Skip to content

Commit d84a9ee

Browse files
atheiRobbepopagryaznov
authored andcommitted
contracts: Replace sp-sandbox and wasmi-validation by newest wasmi (paritytech#12501)
* Replace sp-sandbox and wasmi-validation by just wasmi * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Re-check original code on re-instrumentation * Fix clippy * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Apply suggestions from code review Co-authored-by: Robin Freyler <[email protected]> * Replace wasmi by ::wasmi * Bump wasmi to 0.20 * Add explanation for `unreachable` * Change proof * Fixup master merge * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Fixup naming inconsistencies introduced by reentrancy PR * Fix `scan_imports` docs * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <[email protected]> * Fixup suggestions * Remove unnecessary &mut * Fix test * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Fix benchmark merge fail * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Fix docs as suggested by code review * Improve docs for `CodeRejected` * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <[email protected]> * Fix logic bug when setting `deterministic_only` * Don't panic when module fails to compile * Apply suggestions from code review Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: Sasha Gryaznov <[email protected]>
1 parent 8aaaf03 commit d84a9ee

23 files changed

+1909
-1634
lines changed

Cargo.lock

Lines changed: 60 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frame/contracts/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ serde = { version = "1", optional = true, features = ["derive"] }
2525
smallvec = { version = "1", default-features = false, features = [
2626
"const_generics",
2727
] }
28-
wasmi-validation = { version = "0.5", default-features = false }
28+
wasmi = { version = "0.20", default-features = false }
29+
wasmparser = { package = "wasmparser-nostd", version = "0.91", default-features = false }
2930
impl-trait-for-tuples = "0.2"
3031

3132
# Only used in benchmarking to generate random contract code
@@ -42,7 +43,6 @@ sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primit
4243
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
4344
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
4445
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
45-
sp-sandbox = { version = "0.10.0-dev", default-features = false, path = "../../primitives/sandbox" }
4646
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
4747

4848
[dev-dependencies]
@@ -69,16 +69,16 @@ std = [
6969
"sp-runtime/std",
7070
"sp-io/std",
7171
"sp-std/std",
72-
"sp-sandbox/std",
7372
"frame-benchmarking?/std",
7473
"frame-support/std",
7574
"frame-system/std",
7675
"wasm-instrument/std",
77-
"wasmi-validation/std",
76+
"wasmi/std",
7877
"pallet-contracts-primitives/std",
7978
"pallet-contracts-proc-macro/full",
8079
"log/std",
8180
"rand/std",
81+
"wasmparser/std",
8282
]
8383
runtime-benchmarks = [
8484
"frame-benchmarking/runtime-benchmarks",

frame/contracts/fixtures/return_from_start_fn.wat renamed to frame/contracts/fixtures/event_and_return_on_deploy.wat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
44
(import "env" "memory" (memory 1 1))
55

6-
(start $start)
7-
(func $start
6+
(func (export "deploy")
87
(call $seal_deposit_event
98
(i32.const 0) ;; The topics buffer
109
(i32.const 0) ;; The topics buffer's length
@@ -22,7 +21,6 @@
2221
(func (export "call")
2322
(unreachable)
2423
)
25-
(func (export "deploy"))
2624

2725
(data (i32.const 8) "\01\02\03\04")
2826
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;; Valid module but missing the call function
2+
(module
3+
(func (export "deploy"))
4+
)

frame/contracts/fixtures/invalid_import.wat

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
;; An invalid module
2+
(module
3+
(func (export "deploy"))
4+
(func (export "call")
5+
;; imbalanced stack
6+
(i32.const 7)
7+
)
8+
)

frame/contracts/fixtures/reentrant_count_call.wat renamed to frame/contracts/fixtures/reentrance_count_call.wat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
;; This fixture recursively tests if reentrant_count returns correct reentrant count value when
1+
;; This fixture recursively tests if reentrance_count returns correct reentrant count value when
22
;; using seal_call to make caller contract call to itself
33
(module
44
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
55
(import "seal0" "seal_address" (func $seal_address (param i32 i32)))
66
(import "seal1" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32) (result i32)))
7-
(import "__unstable__" "reentrant_count" (func $reentrant_count (result i32)))
7+
(import "__unstable__" "reentrance_count" (func $reentrance_count (result i32)))
88
(import "env" "memory" (memory 1 1))
99

1010
;; [0, 32) reserved for $seal_address output
@@ -26,7 +26,7 @@
2626
)
2727
)
2828
(func (export "call")
29-
(local $expected_reentrant_count i32)
29+
(local $expected_reentrance_count i32)
3030
(local $seal_call_exit_code i32)
3131

3232
;; reading current contract address
@@ -36,19 +36,19 @@
3636
(call $seal_input (i32.const 32) (i32.const 36))
3737

3838
;; reading manually passed reentrant count
39-
(set_local $expected_reentrant_count (i32.load (i32.const 32)))
39+
(set_local $expected_reentrance_count (i32.load (i32.const 32)))
4040

4141
;; reentrance count is calculated correctly
4242
(call $assert
43-
(i32.eq (call $reentrant_count) (get_local $expected_reentrant_count))
43+
(i32.eq (call $reentrance_count) (get_local $expected_reentrance_count))
4444
)
4545

4646
;; re-enter 5 times in a row and assert that the reentrant counter works as expected
47-
(i32.eq (call $reentrant_count) (i32.const 5))
47+
(i32.eq (call $reentrance_count) (i32.const 5))
4848
(if
4949
(then) ;; recursion exit case
5050
(else
51-
;; incrementing $expected_reentrant_count passed to the contract
51+
;; incrementing $expected_reentrance_count passed to the contract
5252
(i32.store (i32.const 32) (i32.add (i32.load (i32.const 32)) (i32.const 1)))
5353

5454
;; Call to itself

frame/contracts/fixtures/reentrant_count_delegated_call.wat renamed to frame/contracts/fixtures/reentrance_count_delegated_call.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
;; This fixture recursively tests if reentrant_count returns correct reentrant count value when
1+
;; This fixture recursively tests if reentrance_count returns correct reentrant count value when
22
;; using seal_delegate_call to make caller contract delegate call to itself
33
(module
44
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
55
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
66
(import "seal0" "seal_delegate_call" (func $seal_delegate_call (param i32 i32 i32 i32 i32 i32) (result i32)))
7-
(import "__unstable__" "reentrant_count" (func $reentrant_count (result i32)))
7+
(import "__unstable__" "reentrance_count" (func $reentrance_count (result i32)))
88
(import "env" "memory" (memory 1 1))
99

1010
;; [0, 32) buffer where code hash is copied
@@ -37,7 +37,7 @@
3737

3838
;; reentrance count stays 0
3939
(call $assert
40-
(i32.eq (call $reentrant_count) (i32.const 0))
40+
(i32.eq (call $reentrance_count) (i32.const 0))
4141
)
4242

4343
(i32.eq (get_local $callstack_height) (i32.const 5))

0 commit comments

Comments
 (0)