Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix endianness of getBalance #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions EVMimports.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = class Interface {
* @param {integer} addressOffset the memory offset to laod the address
* @param {integer} resultOffset
*/
getBalance (addressOffset, offset, cbIndex) {
getBalance (addressOffset, resultOffset, cbIndex) {
log.debug('EVMImports.js getBalance')
this.takeGas(20)

Expand All @@ -137,7 +137,7 @@ module.exports = class Interface {
const opPromise = Promise.resolve(balanceU256)

this.kernel.pushOpsQueue(opPromise, cbIndex, balance => {
this.setMemory(offset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES))
this.setMemory(resultOffset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES).reverse())
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/interface/balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"callData": "0x00",
"state": {
"0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": {
"balance": "0x056bc75e2d63100000",
"balance": "0xde0b6b3a7640000",
"code": "0x00",
"nonce": "0x00"
}
Expand Down
Binary file modified tests/interface/balance.wasm
Binary file not shown.
9 changes: 4 additions & 5 deletions tests/interface/balance.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0x056bc75e2d63100000 (100 ETH)
;; address 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0xde0b6b3a7640000 (1 ETH)
(module
(import "ethereum" "getBalance" (func $balance (param i32 i32 i32)))
(memory 1 )
Expand All @@ -8,16 +8,15 @@
(export "1" (func $callback))

(func $main
(call $balance (i32.const 0) (i32.const 0) (i32.const 1))
(call $balance (i32.const 0) (i32.const 64) (i32.const 1))
)

(func $callback
(block
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000))
(if (i64.eq (i64.load (i32.const 64)) (i64.const 0xde0b6b3a7640000))
(return)
)
(unreachable)
)
)
)