git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit c6fd80c2a2bd31d15152b974317f2258bc078cc5

Merge pull request #28 from ewasm/eei-naming

Follow naming of EEI r1
Alex Beregszaszi authored on 8/17/2016, 10:24:18 PM
GitHub committed on 8/17/2016, 10:24:18 PM
Parent: e2b0bc2fe56ea4ae83d0bf5783132b8cdaa7a460
Parent: aadb72d7d45ed67836a3f278dbcdf1fd41de3c89

Files changed

environment.jschanged
interface.jschanged
tests/interface/address.wastchanged
tests/interface/balance.wastchanged
tests/interface/basic_gas_ops.wastchanged
tests/interface/callDataSize.wastchanged
tests/interface/callValue.wastchanged
tests/interface/caller.wastchanged
tests/interface/origin.wastchanged
tests/interface/sstore.wastchanged
environment.jsView
@@ -52,8 +52,13 @@
5252 // STUB
5353 return // result
5454 }
5555
56+ callCode (gas, address, value, data) {
57+ // STUB
58+ return // result
59+ }
60+
5661 delegateCall (gas, address, data) {
5762 // STUB
5863 return // result
5964 }
interface.jsView
@@ -13,38 +13,38 @@
1313 }
1414
1515 get exportTable () {
1616 let exportMethods = [
17- // include all the public methods according to the Ethereum Environment Interface (EEI)
18- // FIXME: this currently doesn't match EEI r0
17+ // include all the public methods according to the Ethereum Environment Interface (EEI) r1
1918 'useGas',
20- 'gas',
21- 'address',
22- 'balance',
23- 'origin',
24- 'caller',
25- 'callValue',
26- 'callDataSize',
19+ 'getGasLeft',
20+ 'getAddress',
21+ 'getBalance',
22+ 'getTxOrigin',
23+ 'getCaller',
24+ 'getCallValue',
25+ 'getCallDataSize',
2726 'callDataCopy',
28- 'codeSize',
27+ 'getCodeSize',
2928 'codeCopy',
30- 'extCodeSize',
31- 'extCodeCopy',
32- 'gasPrice',
33- 'blockHash',
34- 'coinbase',
35- 'timestamp',
36- 'number',
37- 'difficulty',
38- 'gasLimit',
29+ 'getExternalCodeSize',
30+ 'externalCodeCopy',
31+ 'getTxGasPrice',
32+ 'getBlockHash',
33+ 'getBlockCoinbase',
34+ 'getBlockTimestamp',
35+ 'getBlockNumber',
36+ 'getBlockDifficulty',
37+ 'getBlockGasLimit',
3938 'log',
4039 'create',
4140 'call',
41+ 'callCode',
4242 'callDelegate',
43- 'sstore',
44- 'sload',
43+ 'storageStore',
44+ 'storageLoad',
4545 'return',
46- 'suicide'
46+ 'selfDestruct'
4747 ]
4848 let ret = {}
4949 exportMethods.forEach((method) => {
5050 ret[method] = this[method].bind(this)
@@ -72,18 +72,18 @@
7272 /**
7373 * Returns the current amount of gas
7474 * @return {integer}
7575 */
76- gas () {
76+ getGasLeft () {
7777 return this.environment.gasLimit
7878 }
7979
8080 /**
8181 * Gets address of currently executing account and loads it into memory at
8282 * the given offset.
8383 * @param {integer} offset
8484 */
85- address (offset) {
85+ getAddress (offset) {
8686 this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address.toBuffer())
8787 }
8888
8989 /**
@@ -91,9 +91,9 @@
9191 * offset.
9292 * @param {integer} addressOffset the memory offset to laod the address
9393 * @param {integer} resultOffset
9494 */
95- balance (addressOffset, offset) {
95+ getBalance (addressOffset, offset) {
9696 const address = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
9797 // call the parent contract and ask for the balance of one of its child contracts
9898 const balance = this.environment.parent.environment.getBalance(address)
9999 this.setMemory(offset, constants.BALANCE_SIZE_BYTES, balance.toBuffer(constants.BALANCE_SIZE_BYTES))
@@ -104,36 +104,36 @@
104104 * given offset. This is the sender of original transaction; it is never an
105105 * account with non-empty associated code.
106106 * @param {integer} offset
107107 */
108- origin (offset) {
108+ getTxOrigin (offset) {
109109 this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin.toBuffer())
110110 }
111111
112112 /**
113113 * Gets caller address and loads it into memory at the given offset. This is
114114 * the address of the account that is directly responsible for this execution.
115115 * @param {integer} offset
116116 */
117- caller (offset) {
117+ getCaller (offset) {
118118 this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller.toBuffer())
119119 }
120120
121121 /**
122122 * Gets the deposited value by the instruction/transaction responsible for
123123 * this execution and loads it into memory at the given location.
124124 * @param {integer} offset
125125 */
126- callValue (offset) {
126+ getCallValue (offset) {
127127 this.setMemory(offset, constants.BALANCE_SIZE_BYTES, this.environment.callValue.toBuffer(constants.BALANCE_SIZE_BYTES))
128128 }
129129
130130 /**
131131 * Get size of input data in current environment. This pertains to the input
132132 * data passed with the message call instruction or transaction.
133133 * @return {integer}
134134 */
135- callDataSize () {
135+ getCallDataSize () {
136136 return this.environment.callData.length
137137 }
138138
139139 /**
@@ -151,9 +151,9 @@
151151 /**
152152 * Gets the size of code running in current environment.
153153 * @return {interger}
154154 */
155- codeSize () {
155+ getCodeSize () {
156156 return this.environment.code.length
157157 }
158158
159159 /**
@@ -161,52 +161,52 @@
161161 * @param {integer} offset the memory offset
162162 * @param {integer} codeOffset the code offset
163163 * @param {integer} length the length of code to copy
164164 */
165- codeCopy (offset, codeOffset, length) {
165+ codeCopy (resultOffset, codeOffset, length) {
166166 const code = new Uint8Array(this.environment.code, codeOffset, length)
167- this.setMemory(offset, length, code)
167+ this.setMemory(resultOffset, length, code)
168168 }
169169
170170 /**
171171 * Get size of an account’s code.
172172 * @param {integer} addressOffset the offset in memory to load the address from
173173 * @return {integer}
174174 */
175- extCodeSize (addressOffset) {
175+ getExternalCodeSize (addressOffset) {
176176 const address = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
177177 const code = this.environment.getCode(address)
178178 return code.length
179179 }
180180
181181 /**
182182 * Copys the code of an account to memory.
183183 * @param {integer} addressOffset the memory offset of the address
184- * @param {integer} offset the memory offset
184+ * @param {integer} resultOffset the memory offset
185185 * @param {integer} codeOffset the code offset
186186 * @param {integer} length the length of code to copy
187187 */
188- extCodeCopy (addressOffset, offset, codeOffset, length) {
188+ externalCodeCopy (addressOffset, resultOffset, codeOffset, length) {
189189 const address = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
190190 let code = this.environment.getCode(address)
191191 code = new Uint8Array(code, codeOffset, length)
192- this.setMemory(offset, length, code)
192+ this.setMemory(resultOffset, length, code)
193193 }
194194
195195 /**
196196 * Gets price of gas in current environment.
197197 * @return {integer}
198198 */
199- gasPrice () {
199+ getTxGasPrice () {
200200 return this.environment.gasPrice
201201 }
202202
203203 /**
204204 * Gets the hash of one of the 256 most recent complete blocks.
205205 * @param {integer} number which block to load
206206 * @param {integer} offset the offset to load the hash into
207207 */
208- blockHash (number, offset) {
208+ getBlockHash (number, offset) {
209209 const diff = this.environment.number - number
210210 let hash
211211
212212 if (diff > 256 || diff <= 0) {
@@ -220,41 +220,41 @@
220220 /**
221221 * Gets the block’s beneficiary address and loads into memory.
222222 * @param offset
223223 */
224- coinbase (offset) {
224+ getBlockCoinbase (offset) {
225225 this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.coinbase.toBuffer())
226226 }
227227
228228 /**
229229 * Get the block’s timestamp.
230230 * @return {integer}
231231 */
232- timestamp () {
232+ getBlockTimestamp () {
233233 return this.environment.timestamp
234234 }
235235
236236 /**
237237 * Get the block’s number.
238238 * @return {integer}
239239 */
240- number () {
240+ getBlockNumber () {
241241 return this.environment.number
242242 }
243243
244244 /**
245245 * Get the block’s difficulty.
246246 * @return {integer}
247247 */
248- difficulty () {
248+ getBlockDifficulty () {
249249 return this.environment.difficulty
250250 }
251251
252252 /**
253253 * Get the block’s gas limit.
254254 * @return {integer}
255255 */
256- gasLimit () {
256+ getBlockGasLimit () {
257257 return this.environment.gasLimit
258258 }
259259
260260 /**
@@ -295,9 +295,9 @@
295295 * @param {integer} gas
296296 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
297297 * TODO: add proper gas counting
298298 */
299- call (addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, gas) {
299+ call (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength) {
300300 if (gas === undefined) {
301301 gas = this.gasLeft()
302302 }
303303 // Load the params from mem
@@ -310,8 +310,31 @@
310310 return errorCode
311311 }
312312
313313 /**
314+ * Message-call into this account with an alternative account’s code.
315+ * @param {integer} addressOffset the offset to load the address path from
316+ * @param {integer} valueOffset the offset to load the value from
317+ * @param {integer} dataOffset the offset to load data from
318+ * @param {integer} dataLength the length of data
319+ * @param {integer} resultOffset the offset to store the result data at
320+ * @param {integer} resultLength
321+ * @param {integer} gas
322+ * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
323+ * TODO: add proper gas counting
324+ */
325+ callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength) {
326+ // Load the params from mem
327+ const address = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
328+ const value = new U256(this.getMemory(valueOffset, constants.BALANCE_SIZE_BYTES))
329+ const data = this.getMemory(dataOffset, dataLength)
330+ // Run the call
331+ const [result, errorCode] = this.environment.callCode(gas, address, value, data)
332+ this.setMemory(resultOffset, resultLength, result)
333+ return errorCode
334+ }
335+
336+ /**
314337 * Message-call into this account with an alternative account’s code, but
315338 * persisting the current values for sender and value.
316339 * @param {integer} gas
317340 * @param {integer} addressOffset the offset to load the address path from
@@ -335,9 +358,9 @@
335358 * from Memory
336359 * @param {interger} pathOffest the memory offset to load the the path from
337360 * @param {interger} valueOffset the memory offset to load the value from
338361 */
339- sstore (pathOffset, valueOffset) {
362+ storageStore (pathOffset, valueOffset) {
340363 const path = new Buffer(this.getMemory(pathOffset, 32)).toString('hex')
341364 // copy the value
342365 const value = this.getMemory(valueOffset, 32).slice(0)
343366 const oldValue = this.environment.state.get(path)
@@ -361,9 +384,9 @@
361384 * reterives a value at a given path in long term storage
362385 * @param {interger} pathOffest the memory offset to load the the path from
363386 * @param {interger} resultOffset the memory offset to load the value from
364387 */
365- sload (pathOffset, resultOffset) {
388+ storageLoad (pathOffset, resultOffset) {
366389 const path = new Buffer(this.getMemory(pathOffset, 32)).toString('hex')
367390 const result = this.environment.state.get(path)
368391 this.setMemory(resultOffset, 32, result)
369392 }
@@ -381,9 +404,9 @@
381404 * Halt execution and register account for later deletion giving the remaining
382405 * balance to an address path
383406 * @param {integer} offset the offset to load the address from
384407 */
385- suicide (addressOffset) {
408+ selfDestruct (addressOffset) {
386409 this.environment.suicideAddress = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
387410 }
388411
389412 getMemory (offset, length) {
tests/interface/address.wastView
@@ -1,9 +1,9 @@
11 ;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
44
5- (import $address "ethereum" "address" (param i32))
5+ (import $address "ethereum" "getAddress" (param i32))
66 (export "test" 0)
77 (export "a" memory)
88 (func
99 (block
tests/interface/balance.wastView
@@ -1,8 +1,8 @@
11 ;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 100
22 (module
33 (memory 1 (segment 0 "\5d\48\c1\01\89\04\a1\72\88\68\29\bb\bd\9c\6f\4a\2d\06\c4\7b"))
4- (import $balance "ethereum" "balance" (param i32 i32))
4+ (import $balance "ethereum" "getBalance" (param i32 i32))
55 (export "a" memory)
66 (export "test" 0)
77 (func
88 (block
tests/interface/basic_gas_ops.wastView
@@ -1,8 +1,8 @@
11 ;; starts with 1000 gas
22 (module
33 (import $useGas "ethereum" "useGas" (param i32))
4- (import $gas "ethereum" "gas" (result i32))
4+ (import $gas "ethereum" "getGasLeft" (result i32))
55
66 (export "test" 0)
77 (func
88 ;; test adding gas
tests/interface/callDataSize.wastView
@@ -1,7 +1,7 @@
11 (module
22 (memory 1)
3- (import $callDataSize "ethereum" "callDataSize" (result i64))
3+ (import $callDataSize "ethereum" "getCallDataSize" (result i64))
44
55 (export "test" 0)
66 (func
77 (block
tests/interface/callValue.wastView
@@ -1,8 +1,8 @@
11 ;; call value of 100
22 (module
33 (memory 1)
4- (import $callValue "ethereum" "callValue" (param i32))
4+ (import $callValue "ethereum" "getCallValue" (param i32))
55
66 (export "a" memory)
77 (export "test" 0)
88 (func
tests/interface/caller.wastView
@@ -1,8 +1,8 @@
11 ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
4- (import $caller "ethereum" "caller" (param i32))
4+ (import $caller "ethereum" "getCaller" (param i32))
55
66 (export "test" 0)
77 (export "a" memory)
88 (func
tests/interface/origin.wastView
@@ -1,8 +1,8 @@
11 ;; starts with an origin of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
4- (import $origin "ethereum" "origin" (param i32))
4+ (import $origin "ethereum" "getTxOrigin" (param i32))
55
66 (export "test" 0)
77 (export "a" memory)
88 (func
tests/interface/sstore.wastView
@@ -1,9 +1,9 @@
11 ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
4- (import $sstore "ethereum" "sstore" (param i32 i32))
5- (import $sload "ethereum" "sload" (param i32 i32))
4+ (import $sstore "ethereum" "storageStore" (param i32 i32))
5+ (import $sload "ethereum" "storageLoad" (param i32 i32))
66
77 (export "test" 0)
88 (export "a" memory)
99 (func

Built with git-ssb-web