Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
delete 6th and 7th CALL params from stack
Browse files Browse the repository at this point in the history
  • Loading branch information
cdetrio authored and axic committed May 28, 2018
1 parent e949349 commit e6d2f0a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
39 changes: 38 additions & 1 deletion wasm/generateInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,44 @@ function generateManifest (interfaceManifest, opts) {
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))`
call += `(get_local $offset${numOfLocals})`
} else if (input === 'length') {
} else if (input === 'length' && opcode === 'CALL') {
// CALLs in EVM have 7 arguments
// but in ewasm CALLs only have 5 arguments
// so delete the bottom two stack elements, after processing the 5th argument

locals += `(local $length${numOfLocals} i32)`
body += `(set_local $length${numOfLocals}
(call $check_overflow
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32})))
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))
(call $memusegas (get_local $offset${numOfLocals}) (get_local $length${numOfLocals}))
(set_local $offset${numOfLocals} (i32.add (get_global $memstart) (get_local $offset${numOfLocals})))`

call += `(get_local $length${numOfLocals})`
numOfLocals++

// delete 6th stack element
spOffset--
call += `
;; zero out mem
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 4})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 1})) (i64.const 0))`

// delete 7th stack element
spOffset--
call += `
;; zero out mem
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 4})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})) (i64.const 0))
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 1})) (i64.const 0))`

} else if (input === 'length' && opcode !== 'CALL') {
locals += `(local $length${numOfLocals} i32)`
body += `(set_local $length${numOfLocals}
(call $check_overflow
Expand Down
2 changes: 1 addition & 1 deletion wasm/wast-async.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"imports": "(import \"ethereum\" \"create\" (func $create (param i32 i32 i32 i32 i32) ))"
},
"CALL": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $CALL (param $callback i32)(local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -96)))\n (i64.load (i32.add (get_global $sp) (i32.const -88)))\n (i64.load (i32.add (get_global $sp) (i32.const -80)))\n (i64.load (i32.add (get_global $sp) (i32.const -72)))))(set_local $length0 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -128)))\n (i64.load (i32.add (get_global $sp) (i32.const -120)))\n (i64.load (i32.add (get_global $sp) (i32.const -112)))\n (i64.load (i32.add (get_global $sp) (i32.const -104)))))\n\n (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0))) (i64.store\n (i32.add (get_global $sp) (i32.const -128))\n (i64.extend_u/i32\n (i32.eqz (call $call(call $check_overflow_i64\n (i64.load (i32.add (get_global $sp) (i32.const 0)))\n (i64.load (i32.add (get_global $sp) (i32.const 8)))\n (i64.load (i32.add (get_global $sp) (i32.const 16)))\n (i64.load (i32.add (get_global $sp) (i32.const 24))))(i32.add (get_global $sp) (i32.const -32))(i32.add (get_global $sp) (i32.const -64))(get_local $offset0)(get_local $length0)(get_local $callback)) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)\n )))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -104)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -112)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -120)) (i64.const 0)))",
"wast": ";; generated by ./wasm/generateInterface.js\n(func $CALL (param $callback i32)(local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -96)))\n (i64.load (i32.add (get_global $sp) (i32.const -88)))\n (i64.load (i32.add (get_global $sp) (i32.const -80)))\n (i64.load (i32.add (get_global $sp) (i32.const -72)))))(set_local $length0 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -128)))\n (i64.load (i32.add (get_global $sp) (i32.const -120)))\n (i64.load (i32.add (get_global $sp) (i32.const -112)))\n (i64.load (i32.add (get_global $sp) (i32.const -104)))))\n\n (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0))) (i64.store\n (i32.add (get_global $sp) (i32.const -192))\n (i64.extend_u/i32\n (i32.eqz (call $call(call $check_overflow_i64\n (i64.load (i32.add (get_global $sp) (i32.const 0)))\n (i64.load (i32.add (get_global $sp) (i32.const 8)))\n (i64.load (i32.add (get_global $sp) (i32.const 16)))\n (i64.load (i32.add (get_global $sp) (i32.const 24))))(i32.add (get_global $sp) (i32.const -32))(i32.add (get_global $sp) (i32.const -64))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -128)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -136)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -144)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -152)) (i64.const 0))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -160)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -168)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -176)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -184)) (i64.const 0))(get_local $callback)) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)\n )))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -168)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -176)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -184)) (i64.const 0)))",
"imports": "(import \"ethereum\" \"call\" (func $call (param i64 i32 i32 i32 i32 i32) (result i32)))"
},
"CALLCODE": {
Expand Down
2 changes: 1 addition & 1 deletion wasm/wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"imports": "(import \"ethereum\" \"create\" (func $create (param i32 i32 i32 i32) ))"
},
"CALL": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $CALL (local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -96)))\n (i64.load (i32.add (get_global $sp) (i32.const -88)))\n (i64.load (i32.add (get_global $sp) (i32.const -80)))\n (i64.load (i32.add (get_global $sp) (i32.const -72)))))(set_local $length0 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -128)))\n (i64.load (i32.add (get_global $sp) (i32.const -120)))\n (i64.load (i32.add (get_global $sp) (i32.const -112)))\n (i64.load (i32.add (get_global $sp) (i32.const -104)))))\n\n (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0))) (i64.store\n (i32.add (get_global $sp) (i32.const -128))\n (i64.extend_u/i32\n (i32.eqz (call $call(call $check_overflow_i64\n (i64.load (i32.add (get_global $sp) (i32.const 0)))\n (i64.load (i32.add (get_global $sp) (i32.const 8)))\n (i64.load (i32.add (get_global $sp) (i32.const 16)))\n (i64.load (i32.add (get_global $sp) (i32.const 24))))(i32.add (get_global $sp) (i32.const -32))(i32.add (get_global $sp) (i32.const -64))(get_local $offset0)(get_local $length0)) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)\n )))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -104)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -112)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -120)) (i64.const 0)))",
"wast": ";; generated by ./wasm/generateInterface.js\n(func $CALL (local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -96)))\n (i64.load (i32.add (get_global $sp) (i32.const -88)))\n (i64.load (i32.add (get_global $sp) (i32.const -80)))\n (i64.load (i32.add (get_global $sp) (i32.const -72)))))(set_local $length0 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -128)))\n (i64.load (i32.add (get_global $sp) (i32.const -120)))\n (i64.load (i32.add (get_global $sp) (i32.const -112)))\n (i64.load (i32.add (get_global $sp) (i32.const -104)))))\n\n (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0))) (i64.store\n (i32.add (get_global $sp) (i32.const -192))\n (i64.extend_u/i32\n (i32.eqz (call $call(call $check_overflow_i64\n (i64.load (i32.add (get_global $sp) (i32.const 0)))\n (i64.load (i32.add (get_global $sp) (i32.const 8)))\n (i64.load (i32.add (get_global $sp) (i32.const 16)))\n (i64.load (i32.add (get_global $sp) (i32.const 24))))(i32.add (get_global $sp) (i32.const -32))(i32.add (get_global $sp) (i32.const -64))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -128)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -136)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -144)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -152)) (i64.const 0))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -160)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -168)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -176)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -184)) (i64.const 0))) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)\n )))\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -168)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -176)) (i64.const 0))\n (i64.store (i32.add (get_global $sp) (i32.const -184)) (i64.const 0)))",
"imports": "(import \"ethereum\" \"call\" (func $call (param i64 i32 i32 i32 i32) (result i32)))"
},
"CALLCODE": {
Expand Down

0 comments on commit e6d2f0a

Please sign in to comment.