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

Commit 2bdcb3b

Browse files
authored
Merge pull request #305 from ewasm/generator-add-gaslimit
Replace special handling of i64 for CALL with a dedicated gasLimit type
2 parents 1a0304f + 0022c42 commit 2bdcb3b

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const depMap = new Map([
3838
['BLOCKHASH', ['check_overflow', 'callback_256']],
3939
['SHA3', ['memusegas', 'bswap_m256', 'check_overflow', 'keccak']],
4040
['CALL', ['bswap_m256', 'memusegas', 'check_overflow_i64', 'check_overflow', 'memset', 'callback_32']],
41-
['DELEGATECALL', ['callback', 'memusegas', 'check_overflow', 'memset']],
42-
['CALLCODE', ['bswap_m256', 'callback', 'memusegas', 'check_overflow', 'check_overflow_i64', 'memset', 'callback_32']],
41+
['DELEGATECALL', ['callback', 'memusegas', 'check_overflow_i64', 'check_overflow', 'memset']],
42+
['CALLCODE', ['bswap_m256', 'callback', 'memusegas', 'check_overflow_i64', 'check_overflow', 'check_overflow_i64', 'memset', 'callback_32']],
4343
['CREATE', ['bswap_m256', 'bswap_m160', 'callback_160', 'memusegas', 'check_overflow']],
4444
['RETURN', ['memusegas', 'check_overflow']],
4545
['BALANCE', ['bswap_m256', 'callback_128']],

wasm/generateInterface.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const wasmTypes = {
1212
length: 'i32',
1313
ipointer: 'i32',
1414
opointer: 'i32',
15+
gasLimit: 'i64',
1516
// FIXME: these are handled wrongly currently
1617
address: 'i32',
1718
i128: 'i32',
@@ -139,19 +140,19 @@ const interfaceManifest = {
139140
CALL: {
140141
name: 'call',
141142
async: true,
142-
input: ['i64', 'address', 'i128', 'readOffset', 'length'],
143+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
143144
output: ['i32']
144145
},
145146
CALLCODE: {
146147
name: 'callCode',
147148
async: true,
148-
input: ['i64', 'address', 'i128', 'readOffset', 'length'],
149+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
149150
output: ['i32']
150151
},
151152
DELEGATECALL: {
152153
name: 'callDelegate',
153154
async: true,
154-
input: ['i32', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length'],
155+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length'],
155156
output: ['i32']
156157
},
157158
SSTORE: {
@@ -263,7 +264,7 @@ function generateManifest (interfaceManifest, opts) {
263264
// the wasm memory offset is a new item on the EVM stack
264265
spOffset++
265266
call += `(i32.add (get_global $sp) (i32.const ${spOffset * 32}))`
266-
} else if (input === 'i64' && opcode === 'CALL') {
267+
} else if (input === 'gasLimit') {
267268
// i64 param for CALL is the gas
268269
// add 2300 gas subsidy
269270
// for now this only works if the gas is a 64-bit value
@@ -281,7 +282,7 @@ function generateManifest (interfaceManifest, opts) {
281282
call += checkOverflowStackItem64(spOffset)
282283
} else if (input === 'i32') {
283284
call += checkOverflowStackItem256(spOffset)
284-
} else if (input === 'i64' && opcode !== 'CALL') {
285+
} else if (input === 'i64') {
285286
call += checkOverflowStackItem64(spOffset)
286287
} else if (input === 'writeOffset' || input === 'readOffset') {
287288
lastOffset = input

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 (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 (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 (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0)))(set_local $offset1 (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 (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 (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)(local $offset1 i32)(local $length1 i32) (set_local $offset0 (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 (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 (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0)))(set_local $offset1 (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 (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 (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_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 $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 i64 i32 i32 i32 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 (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 (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 (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0)))(set_local $offset1 (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 (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 (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)(local $offset1 i32)(local $length1 i32) (set_local $offset0 (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 (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 (call $memusegas (get_local $offset0) (get_local $length0))\n (set_local $offset0 (i32.add (get_global $memstart) (get_local $offset0)))(set_local $offset1 (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 (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 (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_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 $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 i64 i32 i32 i32 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)