Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into migration-status2
Browse files Browse the repository at this point in the history
  • Loading branch information
parity-processbot committed Nov 25, 2022
2 parents ff0062d + f465fee commit d8ada89
Show file tree
Hide file tree
Showing 24 changed files with 1,921 additions and 1,638 deletions.
70 changes: 60 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ serde = { version = "1", optional = true, features = ["derive"] }
smallvec = { version = "1", default-features = false, features = [
"const_generics",
] }
wasmi-validation = { version = "0.5", default-features = false }
wasmi = { version = "0.20", default-features = false }
wasmparser = { package = "wasmparser-nostd", version = "0.91", default-features = false }
impl-trait-for-tuples = "0.2"

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

[dev-dependencies]
Expand All @@ -69,16 +69,16 @@ std = [
"sp-runtime/std",
"sp-io/std",
"sp-std/std",
"sp-sandbox/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"wasm-instrument/std",
"wasmi-validation/std",
"wasmi/std",
"pallet-contracts-primitives/std",
"pallet-contracts-proc-macro/full",
"log/std",
"rand/std",
"wasmparser/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
(import "env" "memory" (memory 1 1))

(start $start)
(func $start
(func (export "deploy")
(call $seal_deposit_event
(i32.const 0) ;; The topics buffer
(i32.const 0) ;; The topics buffer's length
Expand All @@ -22,7 +21,6 @@
(func (export "call")
(unreachable)
)
(func (export "deploy"))

(data (i32.const 8) "\01\02\03\04")
)
4 changes: 4 additions & 0 deletions frame/contracts/fixtures/invalid_contract.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;; Valid module but missing the call function
(module
(func (export "deploy"))
)
6 changes: 0 additions & 6 deletions frame/contracts/fixtures/invalid_import.wat

This file was deleted.

8 changes: 8 additions & 0 deletions frame/contracts/fixtures/invalid_module.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; An invalid module
(module
(func (export "deploy"))
(func (export "call")
;; imbalanced stack
(i32.const 7)
)
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
;; This fixture recursively tests if reentrant_count returns correct reentrant count value when
;; This fixture recursively tests if reentrance_count returns correct reentrant count value when
;; using seal_call to make caller contract call to itself
(module
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_address" (func $seal_address (param i32 i32)))
(import "seal1" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32) (result i32)))
(import "__unstable__" "reentrant_count" (func $reentrant_count (result i32)))
(import "__unstable__" "reentrance_count" (func $reentrance_count (result i32)))
(import "env" "memory" (memory 1 1))

;; [0, 32) reserved for $seal_address output
Expand All @@ -26,7 +26,7 @@
)
)
(func (export "call")
(local $expected_reentrant_count i32)
(local $expected_reentrance_count i32)
(local $seal_call_exit_code i32)

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

;; reading manually passed reentrant count
(set_local $expected_reentrant_count (i32.load (i32.const 32)))
(set_local $expected_reentrance_count (i32.load (i32.const 32)))

;; reentrance count is calculated correctly
(call $assert
(i32.eq (call $reentrant_count) (get_local $expected_reentrant_count))
(i32.eq (call $reentrance_count) (get_local $expected_reentrance_count))
)

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

;; Call to itself
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
;; This fixture recursively tests if reentrant_count returns correct reentrant count value when
;; This fixture recursively tests if reentrance_count returns correct reentrant count value when
;; using seal_delegate_call to make caller contract delegate call to itself
(module
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
(import "seal0" "seal_delegate_call" (func $seal_delegate_call (param i32 i32 i32 i32 i32 i32) (result i32)))
(import "__unstable__" "reentrant_count" (func $reentrant_count (result i32)))
(import "__unstable__" "reentrance_count" (func $reentrance_count (result i32)))
(import "env" "memory" (memory 1 1))

;; [0, 32) buffer where code hash is copied
Expand Down Expand Up @@ -37,7 +37,7 @@

;; reentrance count stays 0
(call $assert
(i32.eq (call $reentrant_count) (i32.const 0))
(i32.eq (call $reentrance_count) (i32.const 0))
)

(i32.eq (get_local $callstack_height) (i32.const 5))
Expand Down
Loading

0 comments on commit d8ada89

Please sign in to comment.