git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 51b309693ae24e58fef5c9a30f63e30aca8a24aa

theses chages make tests in evm2wasm pass again

wanderer authored on 8/25/2016, 2:04:10 AM
Alex Beregszaszi committed on 8/25/2016, 2:35:34 AM
Parent: ba8942733776fbc730e385e2758b1c9424000c4a

Files changed

environment.jschanged
interface.jschanged
environment.jsView
@@ -41,13 +41,23 @@
4141 this.state.set(address.toString(), account)
4242 }
4343
4444 getBalance (address) {
45- return this.state.get(address.toString())['balance']
45+ const account = this.state.get(address.toString())
46+ if (account) {
47+ return account['balance']
48+ } else {
49+ return new U256()
50+ }
4651 }
4752
4853 getCode (address) {
49- return this.state.get(address.toString())['code']
54+ const account = this.state.get(address.toString())
55+ if (account) {
56+ return account['code']
57+ } else {
58+ return Uint8Array.from(new Buffer([]))
59+ }
5060 }
5161
5262 getBlockHash (height) {
5363 return this.blockchain.getBlock(height).hash()
interface.jsView
@@ -157,9 +157,9 @@
157157 * @param {integer} dataOffset the offset in the input data
158158 * @param {integer} length the length of data to copy
159159 */
160160 callDataCopy (offset, dataOffset, length) {
161- this.takeGas(3 + ((length / 32) * 3))
161+ this.takeGas(3 + Math.ceil(length / 32) * 3)
162162
163163 const callData = this.environment.callData.slice(dataOffset, dataOffset + length)
164164 this.setMemory(offset, length, callData)
165165 }
@@ -192,9 +192,9 @@
192192 * @param {integer} codeOffset the code offset
193193 * @param {integer} length the length of code to copy
194194 */
195195 codeCopy (resultOffset, codeOffset, length) {
196- this.takeGas(3 + ((length / 32) * 3))
196+ this.takeGas(3 + Math.ceil(length / 32) * 3)
197197
198198 const code = new Uint8Array(this.environment.code, codeOffset, length)
199199 this.setMemory(resultOffset, length, code)
200200 }
@@ -219,9 +219,9 @@
219219 * @param {integer} codeOffset the code offset
220220 * @param {integer} length the length of code to copy
221221 */
222222 externalCodeCopy (addressOffset, resultOffset, codeOffset, length) {
223- this.takeGas(20 + ((length / 32) * 3))
223+ this.takeGas(20 + Math.ceil(length / 32) * 3)
224224
225225 const address = Address.fromMemory(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
226226 let code = this.environment.getCode(address)
227227 code = new Uint8Array(code, codeOffset, length)

Built with git-ssb-web