git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit a1cbfac008b122511f7f6be08a5e1dc164c4a9ad

simplified gas ops

wanderer committed on 7/17/2016, 3:55:10 PM
Parent: 7250d1d613c9fe437b5c03af7ff4973d93dd5227

Files changed

environment.jschanged
interface.jschanged
tests/interface/basic_gas_ops.jsonchanged
tests/interface/basic_gas_ops.wastchanged
tests/interface/default_enviroment.jsonchanged
environment.jsView
@@ -4,9 +4,8 @@
44 module.exports = class Environment {
55 constructor (data) {
66 const defaults = {
77 // gas tank
8- gasCounter: 0, // TODO: gasCounter is only 53 bits
98 gasPrice: 0,
109 gasLimit: 0, // The gas limit for the block
1110 // call infromation
1211 address: new Uint8Array(20),
interface.jsView
@@ -33,29 +33,21 @@
3333 * @param {integer} amount the amount to subtract to the gas counter
3434 */
3535 useGas (amount) {
3636 if (amount > 0) {
37- ENV.gasCounter += amount
37+ ENV.gasLimit -= amount
3838 }
3939 }
4040
4141 /**
42- * Returns the current gasCounter
42+ * Returns the current amount of gas
4343 * @return {integer}
4444 */
45- gasUsed () {
46- return ENV.gasCounter
45+ gas () {
46+ return ENV.gasLimit
4747 }
4848
4949 /**
50- * Returns the current gasCounter
51- * @return {integer}
52- */
53- gasLeft () {
54- return ENV.gasLimit - ENV.gasCounter
55- }
56-
57- /**
5850 * Gets address of currently executing account and loads it into memory at
5951 * the given offset.
6052 * @param {integer} offset
6153 */
tests/interface/basic_gas_ops.jsonView
@@ -1,3 +1,3 @@
11 {
2- "gas": 1000
2+ "gasLimit": 1000
33 }
tests/interface/basic_gas_ops.wastView
@@ -1,40 +1,32 @@
11 ;; starts with 1000 gas
22 (module
3- (import $addGas "ethereum" "addGas" (param i32))
4- (import $gasUsed "ethereum" "gasUsed" (result i64))
5- (import $gasLeft "ethereum" "gasLeft" (result i64))
3+ (import $useGas "ethereum" "useGas" (param i32))
4+ (import $gas "ethereum" "gas" (result i32))
65
76 (export "test" 0)
87 (func
98 ;; test adding gas
109 (block
11- (call_import $addGas (i32.const 1))
12- (if (i64.eq (call_import $gasUsed) (i64.const 1))
10+ (call_import $useGas (i32.const 1))
11+ (if (i32.eq (call_import $gas) (i32.const 999))
1312 (return)
1413 )
1514 (unreachable)
1615 )
1716 (block
18- (call_import $addGas (i32.const 1))
19- (if (i64.eq (call_import $gasUsed) (i64.const 2))
17+ (call_import $useGas (i32.const 1))
18+ (if (i32.eq (call_import $gas) (i32.const 998))
2019 (return)
2120 )
2221 (unreachable)
2322 )
2423 ;; should disregard negative values
2524 (block
26- (call_import $addGas (i32.const -1))
27- (if (i64.eq (call_import $gasUsed) (i64.const 2))
25+ (call_import $useGas (i32.const -1))
26+ (if (i32.eq (call_import $gas) (i32.const 998))
2827 (return)
2928 )
3029 (unreachable)
3130 )
32- ;; gas left
33- (block
34- (if (i64.eq (call_import $gasLeft) (i64.const 998))
35- (return)
36- )
37- (unreachable)
38- )
3931 )
4032 )
tests/interface/default_enviroment.jsonView
@@ -1,7 +1,5 @@
11 enviroment: {
2- gasCounter: 0,
3- gas: 0,
42 gasPrice: 0,
53 gasLimit: 0,
64 address: [],
75 origin: [],

Built with git-ssb-web