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

Commit

Permalink
Support STATICCALL
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 29, 2018
1 parent 5f181c3 commit a210ba7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions opcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const codes = {
0xf2: ['CALLCODE', 0, 7, 1],
0xf3: ['RETURN', 0, 2, 0],
0xf4: ['DELEGATECALL', 0, 6, 1],
0xfa: ['STATICCALL', 0, 6, 1],

// '0x70', range - other
0xff: ['SELFDESTRUCT', 0, 1, 0]
Expand Down
10 changes: 8 additions & 2 deletions wasm/generateInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ const interfaceManifest = {
input: ['i64', 'address', 'readOffset', 'length'],
output: ['i32']
},
STATICCALL: {
name: 'callStatic',
async: true,
input: ['i64', 'address', 'readOffset', 'length'],
output: ['i32']
},
SSTORE: {
name: 'storageStore',
async: true,
Expand Down Expand Up @@ -265,7 +271,7 @@ 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' && (opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL')) {
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL')) {
// 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
Expand Down Expand Up @@ -365,7 +371,7 @@ function generateManifest (interfaceManifest, opts) {
call += '(get_local $callback)'
}

if (opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL') {
if (opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL') {
call =
`(i64.store
(i32.add (get_global $sp) (i32.const ${spOffset * 32}))
Expand Down
4 changes: 4 additions & 0 deletions wasm/wast-async.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"wast": ";; generated by ./wasm/generateInterface.js\n(func $DELEGATECALL (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 -64)))\n (i64.load (i32.add (get_global $sp) (i32.const -56)))\n (i64.load (i32.add (get_global $sp) (i32.const -48)))\n (i64.load (i32.add (get_global $sp) (i32.const -40)))))(set_local $length0 \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)))))\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 -160))\n (i64.extend_u/i32\n (i32.eqz (call $callDelegate(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))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -96)) (i64.const 0))\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))\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))(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 -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)))",
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i64 i32 i32 i32 i32) (result i32)))"
},
"STATICCALL": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $STATICCALL (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 -64)))\n (i64.load (i32.add (get_global $sp) (i32.const -56)))\n (i64.load (i32.add (get_global $sp) (i32.const -48)))\n (i64.load (i32.add (get_global $sp) (i32.const -40)))))(set_local $length0 \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)))))\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 -160))\n (i64.extend_u/i32\n (i32.eqz (call $callStatic(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))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -96)) (i64.const 0))\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))\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))(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 -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)))",
"imports": "(import \"ethereum\" \"callStatic\" (func $callStatic (param i64 i32 i32 i32 i32) (result i32)))"
},
"SSTORE": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $SSTORE (param $callback i32) (call $storageStore(get_global $sp)(i32.add (get_global $sp) (i32.const -32))(get_local $callback)))",
"imports": "(import \"ethereum\" \"storageStore\" (func $storageStore (param i32 i32 i32) ))"
Expand Down
4 changes: 4 additions & 0 deletions wasm/wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"wast": ";; generated by ./wasm/generateInterface.js\n(func $DELEGATECALL (local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -64)))\n (i64.load (i32.add (get_global $sp) (i32.const -56)))\n (i64.load (i32.add (get_global $sp) (i32.const -48)))\n (i64.load (i32.add (get_global $sp) (i32.const -40)))))(set_local $length0 \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)))))\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 -160))\n (i64.extend_u/i32\n (i32.eqz (call $callDelegate(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))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -96)) (i64.const 0))\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))\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))) ;; 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 -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)))",
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i64 i32 i32 i32) (result i32)))"
},
"STATICCALL": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $STATICCALL (local $offset0 i32)(local $length0 i32) (set_local $offset0 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -64)))\n (i64.load (i32.add (get_global $sp) (i32.const -56)))\n (i64.load (i32.add (get_global $sp) (i32.const -48)))\n (i64.load (i32.add (get_global $sp) (i32.const -40)))))(set_local $length0 \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)))))\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 -160))\n (i64.extend_u/i32\n (i32.eqz (call $callStatic(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))(get_local $offset0)(get_local $length0)\n ;; zero out mem\n (i64.store (i32.add (get_global $sp) (i32.const -96)) (i64.const 0))\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))\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))) ;; 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 -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)))",
"imports": "(import \"ethereum\" \"callStatic\" (func $callStatic (param i64 i32 i32 i32) (result i32)))"
},
"SSTORE": {
"wast": ";; generated by ./wasm/generateInterface.js\n(func $SSTORE (call $storageStore(get_global $sp)(i32.add (get_global $sp) (i32.const -32))))",
"imports": "(import \"ethereum\" \"storageStore\" (func $storageStore (param i32 i32) ))"
Expand Down

0 comments on commit a210ba7

Please sign in to comment.