Commit a1cbfac008b122511f7f6be08a5e1dc164c4a9ad
simplified gas ops
wanderer committed on 7/17/2016, 3:55:10 PMParent: 7250d1d613c9fe437b5c03af7ff4973d93dd5227
Files changed
environment.js | changed |
interface.js | changed |
tests/interface/basic_gas_ops.json | changed |
tests/interface/basic_gas_ops.wast | changed |
tests/interface/default_enviroment.json | changed |
environment.js | ||
---|---|---|
@@ -4,9 +4,8 @@ | ||
4 | 4 | module.exports = class Environment { |
5 | 5 | constructor (data) { |
6 | 6 | const defaults = { |
7 | 7 | // gas tank |
8 | - gasCounter: 0, // TODO: gasCounter is only 53 bits | |
9 | 8 | gasPrice: 0, |
10 | 9 | gasLimit: 0, // The gas limit for the block |
11 | 10 | // call infromation |
12 | 11 | address: new Uint8Array(20), |
interface.js | ||
---|---|---|
@@ -33,29 +33,21 @@ | ||
33 | 33 | * @param {integer} amount the amount to subtract to the gas counter |
34 | 34 | */ |
35 | 35 | useGas (amount) { |
36 | 36 | if (amount > 0) { |
37 | - ENV.gasCounter += amount | |
37 | + ENV.gasLimit -= amount | |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Returns the current gasCounter | |
42 | + * Returns the current amount of gas | |
43 | 43 | * @return {integer} |
44 | 44 | */ |
45 | - gasUsed () { | |
46 | - return ENV.gasCounter | |
45 | + gas () { | |
46 | + return ENV.gasLimit | |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * Returns the current gasCounter | |
51 | - * @return {integer} | |
52 | - */ | |
53 | - gasLeft () { | |
54 | - return ENV.gasLimit - ENV.gasCounter | |
55 | - } | |
56 | - | |
57 | - /** | |
58 | 50 | * Gets address of currently executing account and loads it into memory at |
59 | 51 | * the given offset. |
60 | 52 | * @param {integer} offset |
61 | 53 | */ |
tests/interface/basic_gas_ops.wast | ||
---|---|---|
@@ -1,40 +1,32 @@ | ||
1 | 1 | ;; starts with 1000 gas |
2 | 2 | (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)) | |
6 | 5 | |
7 | 6 | (export "test" 0) |
8 | 7 | (func |
9 | 8 | ;; test adding gas |
10 | 9 | (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)) | |
13 | 12 | (return) |
14 | 13 | ) |
15 | 14 | (unreachable) |
16 | 15 | ) |
17 | 16 | (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)) | |
20 | 19 | (return) |
21 | 20 | ) |
22 | 21 | (unreachable) |
23 | 22 | ) |
24 | 23 | ;; should disregard negative values |
25 | 24 | (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)) | |
28 | 27 | (return) |
29 | 28 | ) |
30 | 29 | (unreachable) |
31 | 30 | ) |
32 | - ;; gas left | |
33 | - (block | |
34 | - (if (i64.eq (call_import $gasLeft) (i64.const 998)) | |
35 | - (return) | |
36 | - ) | |
37 | - (unreachable) | |
38 | - ) | |
39 | 31 | ) |
40 | 32 | ) |
Built with git-ssb-web