Skip to content

Commit 2230cec

Browse files
Make gas costs of counter increments uniform (#291)
1 parent 6b0c57d commit 2230cec

File tree

5 files changed

+14
-42
lines changed

5 files changed

+14
-42
lines changed

load/app/counter_app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (g *CounterUser) GenerateTx(currentGasPrice *big.Int) (*types.Transaction,
128128
}
129129

130130
// prepare tx
131-
const gasLimit = 50000 // IncrementCounter method call takes 43426 of gas
131+
const gasLimit = 28036
132132
tx, err := createTx(g.sender, g.contract, big.NewInt(0), data, currentGasPrice, gasLimit)
133133
if err == nil {
134134
g.sentTxs.Add(1)

load/contracts/Counter.sol

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
pragma solidity ^0.8.4;
33

44
contract Counter {
5-
int private count = 0;
5+
// counter is an internal counter tracking the number of increment calls.
6+
// The counter is initialized to 1 to make all increment-counter calls
7+
// equally expensive. Otherwise, the first call incrementing the counter
8+
// from 0 to 1 would have to pay extra gas for the storage allocation.
9+
int private count = 1;
610

711
function incrementCounter() public {
812
count += 1;
913
}
1014

11-
function decrementCounter() public {
12-
count -= 1;
13-
}
14-
1515
function getCount() public view returns (int) {
16-
return count;
16+
return count-1;
1717
}
1818
}

load/contracts/abi/Counter.abi

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
[
2-
{
3-
"inputs": [],
4-
"name": "decrementCounter",
5-
"outputs": [],
6-
"stateMutability": "nonpayable",
7-
"type": "function"
8-
},
92
{
103
"inputs": [],
114
"name": "getCount",
12-
"outputs":
13-
[
5+
"outputs": [
146
{
157
"internalType": "int256",
168
"name": "",

load/contracts/abi/Counter.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
60806040526000805534801561001457600080fd5b50610120806100246000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80635b34b966146041578063a87d942c146049578063f5c5ad8314605e575b600080fd5b60476064565b005b60005460405190815260200160405180910390f35b6047607b565b60016000808282546074919060a1565b9091555050565b60016000808282546074919060c6565b634e487b7160e01b600052601160045260246000fd5b808201828112600083128015821682158216171560be5760be608b565b505092915050565b818103600083128015838313168383128216171560e35760e3608b565b509291505056fea2646970667358221220133e897f7bd8452e123033f2bd5116036db1bfb1756cd4969259f449fa72905164736f6c63430008130033
1+
60806040526001600055348015601457600080fd5b50610117806100246000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80635b34b966146037578063a87d942c14603f575b600080fd5b603d6057565b005b6045606e565b60405190815260200160405180910390f35b6001600080828254606791906098565b9091555050565b60006001600054607d919060bd565b905090565b634e487b7160e01b600052601160045260246000fd5b808201828112600083128015821682158216171560b55760b56082565b505092915050565b818103600083128015838313168383128216171560da5760da6082565b509291505056fea2646970667358221220e22c01578d13bae8b49fb249b8f9269803187e01f3e69b6166e2d7ffd414a8f964736f6c634300081c0033

load/contracts/abi/Counter.go

+5-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)