Skip to content

Commit d324f71

Browse files
authored
fix: add changes from eip3860 (#292)
1 parent fd07aeb commit d324f71

5 files changed

Lines changed: 47 additions & 1 deletion

File tree

docs/opcodes/F0.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ The state changes done by the current context are [reverted](#FD) in those cases
4545
- Not enough gas.
4646
- Not enough values on the stack.
4747
- The current execution context is from a [STATICCALL](/#FA) (since Byzantium fork).
48+
- `size` is greater than the chain's maximum initcode size (since Shanghai fork).

docs/opcodes/F0/shanghai.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Gas
2+
3+
minimum_word_size = (size + 31) / 32
4+
init_code_cost = {gasPrices|initCodeWordCost} * minimum_word_size
5+
code_deposit_cost = {gasPrices|createData} * deployed_code_size
6+
7+
static_gas = {gasPrices|create}
8+
dynamic_gas = init_code_cost + memory_expansion_cost + deployment_code_execution_cost + code_deposit_cost
9+
10+
The `deployment_code_execution_cost` is the cost of whatever opcode is run to deploy the new contract.
11+
On top of that, there are additional costs for storing the code of the new contract and performing a jumpdest-analysis, respectively shown as `code_deposit_cost` and `init_code_cost`.
12+
The memory expansion cost explanation can be found [here](/about).
13+
14+
The new contract address is added in the warm addresses. See section [access sets](/about).

docs/opcodes/F5.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ The state changes done by the current context are [reverted](#FD) in those cases
4646
- Not enough gas.
4747
- Not enough values on the stack.
4848
- The current execution context is from a [STATICCALL](/#FA).
49+
- `size` is greater than the chain's maximum initcode size (since Shanghai fork).

docs/opcodes/F5/shanghai.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Gas
2+
3+
minimum_word_size = (size + 31) / 32
4+
init_code_cost = {gasPrices|initCodeWordCost} * minimum_word_size
5+
hash_cost = {gasPrices|sha3Word} * minimum_word_size
6+
code_deposit_cost = {gasPrices|createData} * deployed_code_size
7+
8+
static_gas = {gasPrices|create}
9+
dynamic_gas = init_code_cost + hash_cost + memory_expansion_cost + deployment_code_execution_cost + code_deposit_cost
10+
11+
The `deployment_code_execution_cost` is the cost of whatever opcode is run to deploy the new contract.
12+
On top of that, there are additional costs for storing the code of the new contract and performing a jumpdest-analysis, respectively shown as `code_deposit_cost` and `init_code_cost`.
13+
The difference with [CREATE](#F0) is an additional cost to hash the initialisation code before.
14+
The memory expansion cost explanation can be found [here](/about).
15+
16+
The new contract address is added in the warm addresses. See section [access sets](/about).

util/gas.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,21 @@ function createCost(common: Common, inputs: any): BN {
120120
const depositCost = new BN(inputs.deployedSize).imuln(
121121
Number(common.param('gasPrices', 'createData')),
122122
)
123-
return expansionCost.iadd(depositCost).iadd(new BN(inputs.executionCost))
123+
124+
const result = expansionCost
125+
.iadd(depositCost)
126+
.iadd(new BN(inputs.executionCost))
127+
128+
if (common.gteHardfork('shanghai')) {
129+
const initCodeCost = new BN(
130+
toWordSize(new BN(inputs.size)).imuln(
131+
Number(common.param('gasPrices', 'initCodeWordCost')),
132+
),
133+
)
134+
result.iadd(initCodeCost)
135+
}
136+
137+
return result
124138
}
125139

126140
function callCost(common: Common, inputs: any): BN {

0 commit comments

Comments
 (0)