mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
seal: Change prefix and module name from "ext_" to "seal_" for contract callable functions (#6798)
* seal: Change prefix "ext_" to "seal_" for contract callable functions The word Ext is a overloaded term in the context of substrate. It usually is a trait which abstracts away access to external resources usually in order to mock them away for the purpose of tests. The contract module has its own `Ext` trait in addition the the substrate `Ext` which makes things even more confusing. In order to differentiate the contract callable functions more clearly from this `Ext` concept we rename them to use the "seal_" prefix instead. This should change no behaviour at all. This is a pure renaming commit. * seal: Rename import module from "env" to "seal0" * seal: Fixup integration test * seal: Add more tests for new import module names
This commit is contained in:
committed by
GitHub
parent
f9f8262303
commit
04b185e3d4
@@ -2,9 +2,9 @@
|
||||
;; of this call to the output buffer.
|
||||
;; It also forwards its input to the callee.
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) address of django
|
||||
@@ -23,10 +23,10 @@
|
||||
(func (export "deploy"))
|
||||
|
||||
(func (export "call")
|
||||
(call $ext_input (i32.const 20) (i32.const 24))
|
||||
(call $seal_input (i32.const 20) (i32.const 24))
|
||||
(i32.store
|
||||
(i32.const 16)
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 0) ;; Pointer to "callee" address.
|
||||
(i32.const 8) ;; Length of "callee" address.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -39,6 +39,6 @@
|
||||
)
|
||||
)
|
||||
;; exit with success and take transfer return code to the output buffer
|
||||
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
(call $seal_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_balance" (func $ext_balance (param i32 i32)))
|
||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_println" (func $ext_println (param i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32)))
|
||||
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_println" (func $seal_println (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(func $assert (param i32)
|
||||
@@ -20,7 +20,7 @@
|
||||
(i32.sub (get_local $sp) (i32.const 16))
|
||||
(i32.const 8)
|
||||
)
|
||||
(call $ext_balance
|
||||
(call $seal_balance
|
||||
(i32.sub (get_local $sp) (i32.const 8))
|
||||
(i32.sub (get_local $sp) (i32.const 16))
|
||||
)
|
||||
@@ -41,7 +41,7 @@
|
||||
(i32.store (i32.const 20) (i32.const 32))
|
||||
|
||||
;; Copy input to this contracts memory
|
||||
(call $ext_input (i32.const 24) (i32.const 20))
|
||||
(call $seal_input (i32.const 24) (i32.const 20))
|
||||
|
||||
;; Input data is the code hash of the contract to be deployed.
|
||||
(call $assert
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
;; Fail to deploy the contract since it returns a non-zero exit status.
|
||||
(set_local $exit_code
|
||||
(call $ext_instantiate
|
||||
(call $seal_instantiate
|
||||
(i32.const 24) ;; Pointer to the code hash.
|
||||
(i32.const 32) ;; Length of the code hash.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -86,7 +86,7 @@
|
||||
|
||||
;; Fail to deploy the contract due to insufficient gas.
|
||||
(set_local $exit_code
|
||||
(call $ext_instantiate
|
||||
(call $seal_instantiate
|
||||
(i32.const 24) ;; Pointer to the code hash.
|
||||
(i32.const 32) ;; Length of the code hash.
|
||||
(i64.const 187500000) ;; Just enough to pay for the instantiate
|
||||
@@ -119,7 +119,7 @@
|
||||
|
||||
;; Deploy the contract successfully.
|
||||
(set_local $exit_code
|
||||
(call $ext_instantiate
|
||||
(call $seal_instantiate
|
||||
(i32.const 24) ;; Pointer to the code hash.
|
||||
(i32.const 32) ;; Length of the code hash.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -167,7 +167,7 @@
|
||||
|
||||
;; Call the new contract and expect it to return failing exit code.
|
||||
(set_local $exit_code
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 16) ;; Pointer to "callee" address.
|
||||
(i32.const 8) ;; Length of "callee" address.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -203,7 +203,7 @@
|
||||
|
||||
;; Fail to call the contract due to insufficient gas.
|
||||
(set_local $exit_code
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 16) ;; Pointer to "callee" address.
|
||||
(i32.const 8) ;; Length of "callee" address.
|
||||
(i64.const 117500000) ;; Just enough to make the call
|
||||
@@ -240,7 +240,7 @@
|
||||
|
||||
;; Call the contract successfully.
|
||||
(set_local $exit_code
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 16) ;; Pointer to "callee" address.
|
||||
(i32.const 8) ;; Length of "callee" address.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
(module
|
||||
(import "env" "ext_rent_allowance" (func $ext_rent_allowance (param i32 i32)))
|
||||
(import "seal0" "seal_rent_allowance" (func $seal_rent_allowance (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) reserved for $ext_rent_allowance output
|
||||
;; [0, 8) reserved for $seal_rent_allowance output
|
||||
|
||||
;; [8, 16) length of the buffer
|
||||
(data (i32.const 8) "\08")
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
(func (export "deploy")
|
||||
;; fill the buffer with the rent allowance.
|
||||
(call $ext_rent_allowance (i32.const 0) (i32.const 8))
|
||||
(call $seal_rent_allowance (i32.const 0) (i32.const 8))
|
||||
|
||||
;; assert len == 8
|
||||
(call $assert
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
|
||||
(import "env" "ext_hash_sha2_256" (func $ext_hash_sha2_256 (param i32 i32 i32)))
|
||||
(import "env" "ext_hash_keccak_256" (func $ext_hash_keccak_256 (param i32 i32 i32)))
|
||||
(import "env" "ext_hash_blake2_256" (func $ext_hash_blake2_256 (param i32 i32 i32)))
|
||||
(import "env" "ext_hash_blake2_128" (func $ext_hash_blake2_128 (param i32 i32 i32)))
|
||||
(import "seal0" "seal_hash_sha2_256" (func $seal_hash_sha2_256 (param i32 i32 i32)))
|
||||
(import "seal0" "seal_hash_keccak_256" (func $seal_hash_keccak_256 (param i32 i32 i32)))
|
||||
(import "seal0" "seal_hash_blake2_256" (func $seal_hash_blake2_256 (param i32 i32 i32)))
|
||||
(import "seal0" "seal_hash_blake2_128" (func $seal_hash_blake2_128 (param i32 i32 i32)))
|
||||
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(type $hash_fn_sig (func (param i32 i32 i32)))
|
||||
(table 8 funcref)
|
||||
(elem (i32.const 1)
|
||||
$ext_hash_sha2_256
|
||||
$ext_hash_keccak_256
|
||||
$ext_hash_blake2_256
|
||||
$ext_hash_blake2_128
|
||||
$seal_hash_sha2_256
|
||||
$seal_hash_keccak_256
|
||||
$seal_hash_blake2_256
|
||||
$seal_hash_blake2_128
|
||||
)
|
||||
(data (i32.const 1) "20202010201008") ;; Output sizes of the hashes in order in hex.
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
(local.set $input_len_ptr (i32.const 256))
|
||||
(local.set $input_ptr (i32.const 10))
|
||||
(i32.store (local.get $input_len_ptr) (i32.const 246))
|
||||
(call $ext_input (local.get $input_ptr) (local.get $input_len_ptr))
|
||||
(call $seal_input (local.get $input_ptr) (local.get $input_len_ptr))
|
||||
(local.set $chosen_hash_fn (i32.load8_u (local.get $input_ptr)))
|
||||
(if (i32.gt_u (local.get $chosen_hash_fn) (i32.const 7))
|
||||
;; We check that the chosen hash fn identifier is within bounds: [0,7]
|
||||
@@ -71,7 +71,7 @@
|
||||
(local.get $input_ptr)
|
||||
(local.get $chosen_hash_fn) ;; Which crypto hash function to execute.
|
||||
)
|
||||
(call $ext_return
|
||||
(call $seal_return
|
||||
(i32.const 0)
|
||||
(local.get $input_ptr) ;; Linear memory location of the output buffer.
|
||||
(local.get $output_len) ;; Number of output buffer bytes.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_get_storage" (func $ext_get_storage (param i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
|
||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_get_storage" (func $seal_get_storage (param i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
|
||||
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) Endowment to send when creating contract.
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
(func (export "deploy")
|
||||
;; Input data is the code hash of the contract to be deployed.
|
||||
(call $ext_input (i32.const 48) (i32.const 96))
|
||||
(call $seal_input (i32.const 48) (i32.const 96))
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(i32.load (i32.const 96))
|
||||
@@ -46,7 +46,7 @@
|
||||
;; Deploy the contract with the provided code hash.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_instantiate
|
||||
(call $seal_instantiate
|
||||
(i32.const 48) ;; Pointer to the code hash.
|
||||
(i32.const 32) ;; Length of the code hash.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -72,7 +72,7 @@
|
||||
)
|
||||
|
||||
;; Store the return address.
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 16) ;; Pointer to the key
|
||||
(i32.const 80) ;; Pointer to the value
|
||||
(i32.const 8) ;; Length of the value
|
||||
@@ -83,7 +83,7 @@
|
||||
;; Read address of destination contract from storage.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_get_storage
|
||||
(call $seal_get_storage
|
||||
(i32.const 16) ;; Pointer to the key
|
||||
(i32.const 80) ;; Pointer to the value
|
||||
(i32.const 88) ;; Pointer to the len of the value
|
||||
@@ -101,7 +101,7 @@
|
||||
;; Calling the destination contract with non-empty input data should fail.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 80) ;; Pointer to destination address
|
||||
(i32.const 8) ;; Length of destination address
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -120,7 +120,7 @@
|
||||
;; Call the destination contract regularly, forcing it to self-destruct.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 80) ;; Pointer to destination address
|
||||
(i32.const 8) ;; Length of destination address
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -140,7 +140,7 @@
|
||||
;; does not keep the contract alive.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_transfer
|
||||
(call $seal_transfer
|
||||
(i32.const 80) ;; Pointer to destination address
|
||||
(i32.const 8) ;; Length of destination address
|
||||
(i32.const 0) ;; Pointer to the buffer with value to transfer
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(module
|
||||
(import "env" "ext_balance" (func $ext_balance (param i32 i32)))
|
||||
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32)))
|
||||
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) reserved for $ext_balance output
|
||||
;; [0, 8) reserved for $seal_balance output
|
||||
|
||||
;; [8, 16) length of the buffer
|
||||
(data (i32.const 8) "\08")
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
(func (export "call")
|
||||
;; Send entire remaining balance to the 0 address.
|
||||
(call $ext_balance (i32.const 0) (i32.const 8))
|
||||
(call $seal_balance (i32.const 0) (i32.const 8))
|
||||
|
||||
;; Balance should be encoded as a u64.
|
||||
(call $assert
|
||||
@@ -36,7 +36,7 @@
|
||||
;; Self-destruct by sending full balance to the 0 address.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_transfer
|
||||
(call $seal_transfer
|
||||
(i32.const 16) ;; Pointer to destination address
|
||||
(i32.const 8) ;; Length of destination address
|
||||
(i32.const 0) ;; Pointer to the buffer with value to transfer
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
;; The first 32 byte of input is the code hash to instantiate
|
||||
;; The rest of the input is forwarded to the constructor of the callee
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) address of django
|
||||
@@ -24,10 +24,10 @@
|
||||
(func (export "deploy"))
|
||||
|
||||
(func (export "call")
|
||||
(call $ext_input (i32.const 24) (i32.const 20))
|
||||
(call $seal_input (i32.const 24) (i32.const 20))
|
||||
(i32.store
|
||||
(i32.const 16)
|
||||
(call $ext_instantiate
|
||||
(call $seal_instantiate
|
||||
(i32.const 24) ;; Pointer to the code hash.
|
||||
(i32.const 32) ;; Length of the code hash.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -42,6 +42,6 @@
|
||||
)
|
||||
)
|
||||
;; exit with success and take transfer return code to the output buffer
|
||||
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
(call $seal_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(func (export "deploy")
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
(func $ok_trap_revert
|
||||
(i32.store (i32.const 4) (i32.const 4))
|
||||
(call $ext_input (i32.const 0) (i32.const 4))
|
||||
(call $seal_input (i32.const 0) (i32.const 4))
|
||||
(block $IF_2
|
||||
(block $IF_1
|
||||
(block $IF_0
|
||||
@@ -26,7 +26,7 @@
|
||||
return
|
||||
)
|
||||
;; 1 = revert
|
||||
(call $ext_return (i32.const 1) (i32.const 0) (i32.const 0))
|
||||
(call $seal_return (i32.const 1) (i32.const 0) (i32.const 0))
|
||||
(unreachable)
|
||||
)
|
||||
;; 2 = trap
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
(module
|
||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_restore_to"
|
||||
(func $ext_restore_to
|
||||
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_restore_to"
|
||||
(func $seal_restore_to
|
||||
(param i32 i32 i32 i32 i32 i32 i32 i32)
|
||||
)
|
||||
)
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
(func (export "call")
|
||||
;; copy code hash to contract memory
|
||||
(call $ext_input (i32.const 264) (i32.const 304))
|
||||
(call $seal_input (i32.const 264) (i32.const 304))
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(i32.load (i32.const 304))
|
||||
@@ -27,7 +27,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(call $ext_restore_to
|
||||
(call $seal_restore_to
|
||||
;; Pointer and length of the encoded dest buffer.
|
||||
(i32.const 256)
|
||||
(i32.const 8)
|
||||
@@ -45,14 +45,14 @@
|
||||
)
|
||||
(func (export "deploy")
|
||||
;; Data to restore
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 0)
|
||||
(i32.const 0)
|
||||
(i32.const 4)
|
||||
)
|
||||
|
||||
;; ACL
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 100)
|
||||
(i32.const 0)
|
||||
(i32.const 4)
|
||||
@@ -68,7 +68,7 @@
|
||||
;; Address of bob
|
||||
(data (i32.const 256) "\02\00\00\00\00\00\00\00")
|
||||
|
||||
;; [264, 296) Code hash of SET_RENT (copied here by ext_input)
|
||||
;; [264, 296) Code hash of SET_RENT (copied here by seal_input)
|
||||
|
||||
;; [296, 304) Rent allowance
|
||||
(data (i32.const 296) "\32\00\00\00\00\00\00\00")
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
(module
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "env" "ext_deposit_event" (func $ext_deposit_event (param i32 i32 i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(start $start)
|
||||
(func $start
|
||||
(call $ext_deposit_event
|
||||
(call $seal_deposit_event
|
||||
(i32.const 0) ;; The topics buffer
|
||||
(i32.const 0) ;; The topics buffer's length
|
||||
(i32.const 8) ;; The data buffer
|
||||
(i32.const 4) ;; The data buffer's length
|
||||
)
|
||||
(call $ext_return
|
||||
(call $seal_return
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 4)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 128) buffer where input is copied
|
||||
@@ -16,11 +16,11 @@
|
||||
;; Call reads the first 4 bytes (LE) as the exit status and returns the rest as output data.
|
||||
(func $call (export "call")
|
||||
;; Copy input into this contracts memory.
|
||||
(call $ext_input (i32.const 0) (i32.const 128))
|
||||
(call $seal_input (i32.const 0) (i32.const 128))
|
||||
|
||||
;; Copy all but the first 4 bytes of the input data as the output data.
|
||||
;; Use the first byte as exit status
|
||||
(call $ext_return
|
||||
(call $seal_return
|
||||
(i32.load8_u (i32.const 0)) ;; Exit status
|
||||
(i32.const 4) ;; Pointer to the data to return.
|
||||
(i32.sub ;; Count of bytes to copy.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
(module
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "env" "ext_address" (func $ext_address (param i32 i32)))
|
||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_address" (func $seal_address (param i32 i32)))
|
||||
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_terminate" (func $seal_terminate (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) reserved for $ext_address output
|
||||
;; [0, 8) reserved for $seal_address output
|
||||
|
||||
;; [8, 16) length of the buffer
|
||||
(data (i32.const 8) "\08")
|
||||
@@ -13,7 +13,7 @@
|
||||
;; [16, 24) Address of django
|
||||
(data (i32.const 16) "\04\00\00\00\00\00\00\00")
|
||||
|
||||
;; [24, 32) reserved for output of $ext_input
|
||||
;; [24, 32) reserved for output of $seal_input
|
||||
|
||||
;; [32, 36) length of the buffer
|
||||
(data (i32.const 32) "\04")
|
||||
@@ -36,10 +36,10 @@
|
||||
;; This should trap instead of self-destructing since a contract cannot be removed live in
|
||||
;; the execution stack cannot be removed. If the recursive call traps, then trap here as
|
||||
;; well.
|
||||
(call $ext_input (i32.const 24) (i32.const 32))
|
||||
(call $seal_input (i32.const 24) (i32.const 32))
|
||||
(if (i32.load (i32.const 32))
|
||||
(then
|
||||
(call $ext_address (i32.const 0) (i32.const 8))
|
||||
(call $seal_address (i32.const 0) (i32.const 8))
|
||||
|
||||
;; Expect address to be 8 bytes.
|
||||
(call $assert
|
||||
@@ -52,7 +52,7 @@
|
||||
;; Recursively call self with empty input data.
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_call
|
||||
(call $seal_call
|
||||
(i32.const 0) ;; Pointer to own address
|
||||
(i32.const 8) ;; Length of own address
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
@@ -69,11 +69,11 @@
|
||||
)
|
||||
(else
|
||||
;; Try to terminate and give balance to django.
|
||||
(call $ext_terminate
|
||||
(call $seal_terminate
|
||||
(i32.const 16) ;; Pointer to beneficiary address
|
||||
(i32.const 8) ;; Length of beneficiary address
|
||||
)
|
||||
(unreachable) ;; ext_terminate never returns
|
||||
(unreachable) ;; seal_terminate never returns
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(module
|
||||
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
|
||||
(import "seal0" "seal_terminate" (func $seal_terminate (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(func $assert (param i32)
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
(func (export "deploy")
|
||||
;; Self-destruct by sending full balance to the 0 address.
|
||||
(call $ext_terminate
|
||||
(call $seal_terminate
|
||||
(i32.const 0) ;; Pointer to destination address
|
||||
(i32.const 8) ;; Length of destination address
|
||||
)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
;; This module stores a KV pair into the storage
|
||||
(module
|
||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
|
||||
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 16 16))
|
||||
|
||||
(func (export "call")
|
||||
)
|
||||
(func (export "deploy")
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 0) ;; Pointer to storage key
|
||||
(i32.const 0) ;; Pointer to value
|
||||
(i32.load (i32.const 0)) ;; Size of value
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
(module
|
||||
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
|
||||
(import "env" "ext_clear_storage" (func $ext_clear_storage (param i32)))
|
||||
(import "env" "ext_set_rent_allowance" (func $ext_set_rent_allowance (param i32 i32)))
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
|
||||
(import "seal0" "seal_clear_storage" (func $seal_clear_storage (param i32)))
|
||||
(import "seal0" "seal_set_rent_allowance" (func $seal_set_rent_allowance (param i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; insert a value of 4 bytes into storage
|
||||
(func $call_0
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 1)
|
||||
(i32.const 0)
|
||||
(i32.const 4)
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
;; remove the value inserted by call_1
|
||||
(func $call_1
|
||||
(call $ext_clear_storage
|
||||
(call $seal_clear_storage
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@@ -26,7 +26,7 @@
|
||||
(func $call_2
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
|
||||
(call $seal_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
@@ -48,7 +48,7 @@
|
||||
(func (export "call")
|
||||
(local $input_size i32)
|
||||
(i32.store (i32.const 64) (i32.const 64))
|
||||
(call $ext_input (i32.const 1024) (i32.const 64))
|
||||
(call $seal_input (i32.const 1024) (i32.const 64))
|
||||
(set_local $input_size
|
||||
(i32.load (i32.const 64))
|
||||
)
|
||||
@@ -76,16 +76,16 @@
|
||||
;; Set into storage a 4 bytes value
|
||||
;; Set call set_rent_allowance with input
|
||||
(func (export "deploy")
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 0)
|
||||
(i32.const 0)
|
||||
(i32.const 4)
|
||||
)
|
||||
(call $ext_input
|
||||
(call $seal_input
|
||||
(i32.const 0)
|
||||
(i32.const 64)
|
||||
)
|
||||
(call $ext_set_rent_allowance
|
||||
(call $seal_set_rent_allowance
|
||||
(i32.const 0)
|
||||
(i32.load (i32.const 64))
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(module
|
||||
(import "env" "ext_get_storage" (func $ext_get_storage (param i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
|
||||
(import "env" "ext_input" (func $ext_input (param i32 i32)))
|
||||
(import "seal0" "seal_get_storage" (func $seal_get_storage (param i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "env" "memory" (memory 16 16))
|
||||
|
||||
;; [0, 32) storage key
|
||||
@@ -12,10 +12,10 @@
|
||||
;; [36, 40) size of the input buffer
|
||||
(data (i32.const 36) "\04")
|
||||
|
||||
;; [40, 44) size of buffer for ext_get_storage set to max
|
||||
;; [40, 44) size of buffer for seal_get_storage set to max
|
||||
(data (i32.const 40) "\FF\FF\FF\FF")
|
||||
|
||||
;; [44, inf) ext_get_storage buffer
|
||||
;; [44, inf) seal_get_storage buffer
|
||||
|
||||
(func $assert (param i32)
|
||||
(block $ok
|
||||
@@ -27,7 +27,7 @@
|
||||
)
|
||||
|
||||
(func (export "call")
|
||||
(call $ext_input (i32.const 32) (i32.const 36))
|
||||
(call $seal_input (i32.const 32) (i32.const 36))
|
||||
|
||||
;; assert input size == 4
|
||||
(call $assert
|
||||
@@ -38,7 +38,7 @@
|
||||
)
|
||||
|
||||
;; place a garbage value in storage, the size of which is specified by the call input.
|
||||
(call $ext_set_storage
|
||||
(call $seal_set_storage
|
||||
(i32.const 0) ;; Pointer to storage key
|
||||
(i32.const 0) ;; Pointer to value
|
||||
(i32.load (i32.const 32)) ;; Size of value
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(call $ext_get_storage
|
||||
(call $seal_get_storage
|
||||
(i32.const 0) ;; Pointer to storage key
|
||||
(i32.const 44) ;; buffer where to copy result
|
||||
(i32.const 40) ;; pointer to size of buffer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
;; This transfers 100 balance to the zero account and copies the return code
|
||||
;; of this transfer to the output buffer.
|
||||
(module
|
||||
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 8) zero-adress
|
||||
@@ -18,7 +18,7 @@
|
||||
(func (export "call")
|
||||
(i32.store
|
||||
(i32.const 16)
|
||||
(call $ext_transfer
|
||||
(call $seal_transfer
|
||||
(i32.const 0) ;; ptr to destination address
|
||||
(i32.const 8) ;; length of destination address
|
||||
(i32.const 8) ;; ptr to value to transfer
|
||||
@@ -26,6 +26,6 @@
|
||||
)
|
||||
)
|
||||
;; exit with success and take transfer return code to the output buffer
|
||||
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
(call $seal_return (i32.const 0) (i32.const 16) (i32.const 4))
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user