Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions frame/contracts/fixtures/call_return_code.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;; This calls Django (4) and transfers 100 balance during this call and copies the return code
;; 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 "env" "memory" (memory 1 1))

;; [0, 8) address of django
(data (i32.const 0) "\04\00\00\00\00\00\00\00")

;; [8, 16) 100 balance
(data (i32.const 8) "\64\00\00\00\00\00\00\00")

;; [16, 20) here we store the return code of the transfer

;; [20, 24) here we store the input data

;; [24, 28) size of the input data
(data (i32.const 24) "\04")

(func (export "deploy"))

(func (export "call")
(call $ext_input (i32.const 20) (i32.const 24))
(i32.store
(i32.const 16)
(call $ext_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.
(i32.const 8) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 20) ;; Pointer to input data buffer address
(i32.load (i32.const 24)) ;; Length of input data buffer
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Ptr to output buffer len
)
)
;; exit with success and take transfer return code to the output buffer
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
)
)
4 changes: 2 additions & 2 deletions frame/contracts/fixtures/caller_contract.wat
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
(call $ext_instantiate
(i32.const 24) ;; Pointer to the code hash.
(i32.const 32) ;; Length of the code hash.
(i64.const 200) ;; How much gas to devote for the execution.
(i64.const 187500000) ;; Just enough to pay for the instantiate
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 8) ;; Pointer to input data buffer address
Expand Down Expand Up @@ -206,7 +206,7 @@
(call $ext_call
(i32.const 16) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i64.const 100) ;; How much gas to devote for the execution.
(i64.const 117500000) ;; Just enough to make the call
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 8) ;; Pointer to input data buffer address
Expand Down
8 changes: 2 additions & 6 deletions frame/contracts/fixtures/destroy_and_transfer.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(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 "env" "memory" (memory 1 1))

Expand Down Expand Up @@ -139,16 +140,11 @@
;; does not keep the contract alive.
(call $assert
(i32.eq
(call $ext_call
(call $ext_transfer
(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.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
(i32.const 0) ;; Pointer to input data buffer address
(i32.const 1) ;; Length of input data buffer
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
(i32.const 0)
)
Expand Down
11 changes: 3 additions & 8 deletions frame/contracts/fixtures/drain.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(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_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))

;; [0, 8) reserved for $ext_balance output
Expand Down Expand Up @@ -36,18 +36,13 @@
;; Self-destruct by sending full balance to the 0 address.
(call $assert
(i32.eq
(call $ext_call
(call $ext_transfer
(i32.const 16) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
(i32.const 0) ;; Pointer to input data buffer address
(i32.const 0) ;; Length of input data buffer
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
(i32.const 0)
(i32.const 4) ;; ReturnCode::BelowSubsistenceThreshold
)
)
)
Expand Down
47 changes: 47 additions & 0 deletions frame/contracts/fixtures/instantiate_return_code.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
;; This instantiats Charlie (3) and transfers 100 balance during this call and copies the return code
;; of this call to the output buffer.
;; 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 "env" "memory" (memory 1 1))

;; [0, 8) address of django
(data (i32.const 0) "\04\00\00\00\00\00\00\00")

;; [8, 16) 100 balance
(data (i32.const 8) "\64\00\00\00\00\00\00\00")

;; [16, 20) here we store the return code of the transfer

;; [20, 24) size of the input buffer
(data (i32.const 20) "\FF")

;; [24, inf) input buffer

(func (export "deploy"))

(func (export "call")
(call $ext_input (i32.const 24) (i32.const 20))
(i32.store
(i32.const 16)
(call $ext_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.
(i32.const 8) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 56) ;; Pointer to input data buffer address
(i32.sub (i32.load (i32.const 20)) (i32.const 32)) ;; Length of input data buffer
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy address
(i32.const 0) ;; Length is ignored in this case
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
)
;; exit with success and take transfer return code to the output buffer
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
)
)
35 changes: 35 additions & 0 deletions frame/contracts/fixtures/ok_trap_revert.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(module
(import "env" "ext_input" (func $ext_input (param i32 i32)))
(import "env" "ext_return" (func $ext_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

(func (export "deploy")
(call $ok_trap_revert)
)

(func (export "call")
(call $ok_trap_revert)
)

(func $ok_trap_revert
(i32.store (i32.const 4) (i32.const 4))
(call $ext_input (i32.const 0) (i32.const 4))
(block $IF_2
(block $IF_1
(block $IF_0
(br_table $IF_0 $IF_1 $IF_2
(i32.load8_u (i32.const 0))
)
(unreachable)
)
;; 0 = return with success
return
)
;; 1 = revert
(call $ext_return (i32.const 1) (i32.const 0) (i32.const 0))
(unreachable)
)
;; 2 = trap
(unreachable)
)
)
39 changes: 4 additions & 35 deletions frame/contracts/fixtures/self_destructing_constructor.wat
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
(module
(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_terminate" (func $ext_terminate (param i32 i32)))
(import "env" "memory" (memory 1 1))

;; [0, 8) reserved for $ext_balance output

;; [8, 16) length of the buffer
(data (i32.const 8) "\08")

;; [16, inf) zero initialized

(func $assert (param i32)
(block $ok
(br_if $ok
Expand All @@ -20,33 +12,10 @@
)

(func (export "deploy")
;; Send entire remaining balance to the 0 address.
(call $ext_balance (i32.const 0) (i32.const 8))

;; Balance should be encoded as a u64.
(call $assert
(i32.eq
(i32.load (i32.const 8))
(i32.const 8)
)
)

;; Self-destruct by sending full balance to the 0 address.
(call $assert
(i32.eq
(call $ext_call
(i32.const 16) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
(i32.const 0) ;; Pointer to input data buffer address
(i32.const 0) ;; Length of input data buffer
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
(i32.const 0)
)
(call $ext_terminate
(i32.const 0) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
)
)

Expand Down
9 changes: 7 additions & 2 deletions frame/contracts/fixtures/set_rent.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32)))
(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)))
Expand All @@ -24,7 +24,12 @@

;; transfer 50 to CHARLIE
(func $call_2
(call $ext_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
(call $assert
(i32.eq
(call $ext_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
(i32.const 0)
)
)
)

;; do nothing
Expand Down
31 changes: 31 additions & 0 deletions frame/contracts/fixtures/transfer_return_code.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;; 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 "env" "memory" (memory 1 1))

;; [0, 8) zero-adress
(data (i32.const 0) "\00\00\00\00\00\00\00\00")

;; [8, 16) 100 balance
(data (i32.const 8) "\64\00\00\00\00\00\00\00")

;; [16, 20) here we store the return code of the transfer

(func (export "deploy"))

(func (export "call")
(i32.store
(i32.const 16)
(call $ext_transfer
(i32.const 0) ;; ptr to destination address
(i32.const 8) ;; length of destination address
(i32.const 8) ;; ptr to value to transfer
(i32.const 8) ;; length of value to transfer
)
)
;; exit with success and take transfer return code to the output buffer
(call $ext_return (i32.const 0) (i32.const 16) (i32.const 4))
)
)
Loading