Commit 153dfd46e01f77b867195211bfccb5245ca2e2b4
fix SSTORE
wanderer committed on 8/12/2016, 2:42:29 AMParent: 12253c96876b01e4b82360ffc0099bd87c512338
Files changed
debugInterface.js | changed |
environment.js | changed |
interface.js | changed |
tests/interface/sstore.wast | changed |
debugInterface.js | ||
---|---|---|
@@ -18,9 +18,8 @@ | ||
18 | 18 | return { |
19 | 19 | 'print': function (a) { |
20 | 20 | console.log(a) |
21 | 21 | }, |
22 | - | |
23 | 22 | 'printMem': function (offset, length) { |
24 | 23 | console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`) |
25 | 24 | }.bind(this), |
26 | 25 | |
@@ -34,10 +33,10 @@ | ||
34 | 33 | opcode.name += opcode.number |
35 | 34 | } |
36 | 35 | console.error(`op: ${opcode.name} gas: ${this.environment.gasLimit}`) |
37 | 36 | console.log('-------------stack--------------') |
38 | - for (let i = sp; i > 0; i -= 32) { | |
39 | - console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i - 24, 32).toString('hex')}`) | |
37 | + for (let i = sp; i > -32; i -= 32) { | |
38 | + console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i, 32).toString('hex')}`) | |
40 | 39 | } |
41 | 40 | return sp |
42 | 41 | }.bind(this) |
43 | 42 | } |
environment.js | ||
---|---|---|
@@ -23,8 +23,9 @@ | ||
23 | 23 | // more output calls |
24 | 24 | returnValue: new ArrayBuffer() |
25 | 25 | } |
26 | 26 | |
27 | + const self = this | |
27 | 28 | this.state = new Map() |
28 | 29 | |
29 | 30 | if (data) { |
30 | 31 | data = JSON.parse(data) |
@@ -33,9 +34,8 @@ | ||
33 | 34 | } |
34 | 35 | |
35 | 36 | Object.assign(this, defaults, data) |
36 | 37 | if (data.accounts) { |
37 | - const self = this | |
38 | 38 | data.accounts.forEach((account) => { |
39 | 39 | self.state.set(new Uint8Array(account[0]).toString(), account[1]) |
40 | 40 | }) |
41 | 41 | } |
interface.js | ||
---|---|---|
@@ -331,10 +331,11 @@ | ||
331 | 331 | * @param {interger} pathOffest the memory offset to load the the path from |
332 | 332 | * @param {interger} valueOffset the memory offset to load the value from |
333 | 333 | */ |
334 | 334 | sstore (pathOffset, valueOffset) { |
335 | - const path = new Buffer(this.getMemory(pathOffset, 32)).toString('hex') | |
336 | - const value = this.getMemory(valueOffset, 32) | |
335 | + const path = new Buffer(this.getMemory(pathOffset, 32)).toString('hex') | |
336 | + // copy the value | |
337 | + const value = this.getMemory(valueOffset, 32).slice(0) | |
337 | 338 | const oldValue = this.environment.state.get(path) |
338 | 339 | const valIsZero = value.every((i) => i === 0) |
339 | 340 | |
340 | 341 | // write |
tests/interface/sstore.wast | ||
---|---|---|
@@ -1,9 +1,9 @@ | ||
1 | 1 | ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b |
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | (import $sstore "ethereum" "sstore" (param i32 i32)) |
5 | - (import $sload "ethereum" "sload" (param i32 i32)) | |
5 | + (import $sload "ethereum" "sload" (param i32 i32)) | |
6 | 6 | |
7 | 7 | (export "test" 0) |
8 | 8 | (export "a" memory) |
9 | 9 | (func |
@@ -18,8 +18,9 @@ | ||
18 | 18 | (unreachable)) |
19 | 19 | |
20 | 20 | (i64.store (i32.const 128) (i64.const 173553719826446289)) |
21 | 21 | (call_import $sstore (i32.const 64) (i32.const 128)) |
22 | + (i64.store (i32.const 128) (i64.const 173559826446289)) | |
22 | 23 | (call_import $sload (i32.const 64) (i32.const 64)) |
23 | 24 | (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289)) |
24 | 25 | (unreachable)) |
25 | 26 | ) |
Built with git-ssb-web