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

Commit 5f181c3

Browse files
committed
Fix DELEGATECALL
1 parent 12c5fc8 commit 5f181c3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

wasm/generateInterface.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const interfaceManifest = {
134134
DELEGATECALL: {
135135
name: 'callDelegate',
136136
async: true,
137-
input: ['i32', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length'],
137+
input: ['i64', 'address', 'readOffset', 'length'],
138138
output: ['i32']
139139
},
140140
SSTORE: {
@@ -249,7 +249,7 @@ function generateManifest (interfaceManifest, opts) {
249249
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
250250
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
251251
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3}))))`
252-
} else if (input === 'i64' && opcode !== 'CALL') {
252+
} else if (input === 'i64') {
253253
call += `(call $check_overflow_i64
254254
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32})))
255255
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
@@ -265,7 +265,7 @@ function generateManifest (interfaceManifest, opts) {
265265
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
266266
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))`
267267
call += `(get_local $offset${numOfLocals})`
268-
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE')) {
268+
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL')) {
269269
// CALLs in EVM have 7 arguments
270270
// but in ewasm CALLs only have 5 arguments
271271
// so delete the bottom two stack elements, after processing the 5th argument
@@ -302,7 +302,7 @@ function generateManifest (interfaceManifest, opts) {
302302
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})) (i64.const 0))
303303
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 1})) (i64.const 0))`
304304

305-
} else if (input === 'length' && (opcode !== 'CALL' && opcode !== 'CALLCODE')) {
305+
} else if (input === 'length') {
306306
locals += `(local $length${numOfLocals} i32)`
307307
body += `(set_local $length${numOfLocals}
308308
(call $check_overflow

wasm/wast-async.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
"imports": "(import \"ethereum\" \"callCode\" (func $callCode (param i64 i32 i32 i32 i32 i32) (result i32)))"
9797
},
9898
"DELEGATECALL": {
99-
"wast": ";; generated by ./wasm/generateInterface.js\n(func $DELEGATECALL (param $callback i32)(local $offset0 i32)(local $length0 i32)(local $offset1 i32)(local $length1 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)))(set_local $offset1 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -160)))\n (i64.load (i32.add (get_global $sp) (i32.const -152)))\n (i64.load (i32.add (get_global $sp) (i32.const -144)))\n (i64.load (i32.add (get_global $sp) (i32.const -136)))))(set_local $length1 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -192)))\n (i64.load (i32.add (get_global $sp) (i32.const -184)))\n (i64.load (i32.add (get_global $sp) (i32.const -176)))\n (i64.load (i32.add (get_global $sp) (i32.const -168)))))\n\n (call $memusegas (get_local $offset1) (get_local $length1))\n (set_local $offset1 (i32.add (get_global $memstart) (get_local $offset1))) (i64.store\n (i32.add (get_global $sp) (i32.const -192))\n (i64.extend_u/i32\n (i32.eqz (call $callDelegate(call $check_overflow\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 $offset1)(get_local $length1)(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)))",
100-
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))"
99+
"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)))",
100+
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i64 i32 i32 i32 i32) (result i32)))"
101101
},
102102
"SSTORE": {
103103
"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)))",

wasm/wast.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
"imports": "(import \"ethereum\" \"callCode\" (func $callCode (param i64 i32 i32 i32 i32) (result i32)))"
9797
},
9898
"DELEGATECALL": {
99-
"wast": ";; generated by ./wasm/generateInterface.js\n(func $DELEGATECALL (local $offset0 i32)(local $length0 i32)(local $offset1 i32)(local $length1 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)))(set_local $offset1 \n (call $check_overflow\n (i64.load (i32.add (get_global $sp) (i32.const -160)))\n (i64.load (i32.add (get_global $sp) (i32.const -152)))\n (i64.load (i32.add (get_global $sp) (i32.const -144)))\n (i64.load (i32.add (get_global $sp) (i32.const -136)))))(set_local $length1 \n (call $check_overflow \n (i64.load (i32.add (get_global $sp) (i32.const -192)))\n (i64.load (i32.add (get_global $sp) (i32.const -184)))\n (i64.load (i32.add (get_global $sp) (i32.const -176)))\n (i64.load (i32.add (get_global $sp) (i32.const -168)))))\n\n (call $memusegas (get_local $offset1) (get_local $length1))\n (set_local $offset1 (i32.add (get_global $memstart) (get_local $offset1))) (i64.store\n (i32.add (get_global $sp) (i32.const -192))\n (i64.extend_u/i32\n (i32.eqz (call $callDelegate(call $check_overflow\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 $offset1)(get_local $length1)) ;; 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)))",
100-
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i32 i32 i32 i32 i32 i32 i32) (result i32)))"
99+
"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)))",
100+
"imports": "(import \"ethereum\" \"callDelegate\" (func $callDelegate (param i64 i32 i32 i32) (result i32)))"
101101
},
102102
"SSTORE": {
103103
"wast": ";; generated by ./wasm/generateInterface.js\n(func $SSTORE (call $storageStore(get_global $sp)(i32.add (get_global $sp) (i32.const -32))))",

0 commit comments

Comments
 (0)