git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 153dfd46e01f77b867195211bfccb5245ca2e2b4

fix SSTORE

wanderer committed on 8/12/2016, 2:42:29 AM
Parent: 12253c96876b01e4b82360ffc0099bd87c512338

Files changed

debugInterface.jschanged
environment.jschanged
interface.jschanged
tests/interface/sstore.wastchanged
debugInterface.jsView
@@ -18,9 +18,8 @@
1818 return {
1919 'print': function (a) {
2020 console.log(a)
2121 },
22-
2322 'printMem': function (offset, length) {
2423 console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`)
2524 }.bind(this),
2625
@@ -34,10 +33,10 @@
3433 opcode.name += opcode.number
3534 }
3635 console.error(`op: ${opcode.name} gas: ${this.environment.gasLimit}`)
3736 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')}`)
4039 }
4140 return sp
4241 }.bind(this)
4342 }
environment.jsView
@@ -23,8 +23,9 @@
2323 // more output calls
2424 returnValue: new ArrayBuffer()
2525 }
2626
27+ const self = this
2728 this.state = new Map()
2829
2930 if (data) {
3031 data = JSON.parse(data)
@@ -33,9 +34,8 @@
3334 }
3435
3536 Object.assign(this, defaults, data)
3637 if (data.accounts) {
37- const self = this
3838 data.accounts.forEach((account) => {
3939 self.state.set(new Uint8Array(account[0]).toString(), account[1])
4040 })
4141 }
interface.jsView
@@ -331,10 +331,11 @@
331331 * @param {interger} pathOffest the memory offset to load the the path from
332332 * @param {interger} valueOffset the memory offset to load the value from
333333 */
334334 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)
337338 const oldValue = this.environment.state.get(path)
338339 const valIsZero = value.every((i) => i === 0)
339340
340341 // write
tests/interface/sstore.wastView
@@ -1,9 +1,9 @@
11 ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
44 (import $sstore "ethereum" "sstore" (param i32 i32))
5- (import $sload "ethereum" "sload" (param i32 i32))
5+ (import $sload "ethereum" "sload" (param i32 i32))
66
77 (export "test" 0)
88 (export "a" memory)
99 (func
@@ -18,8 +18,9 @@
1818 (unreachable))
1919
2020 (i64.store (i32.const 128) (i64.const 173553719826446289))
2121 (call_import $sstore (i32.const 64) (i32.const 128))
22+ (i64.store (i32.const 128) (i64.const 173559826446289))
2223 (call_import $sload (i32.const 64) (i32.const 64))
2324 (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289))
2425 (unreachable))
2526 )

Built with git-ssb-web