Skip to content

Commit fad677f

Browse files
committed
forked update
1 parent a80bae1 commit fad677f

File tree

10 files changed

+72
-38
lines changed

10 files changed

+72
-38
lines changed

execution_chain/constants.nim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ const
5959

6060
## Fork specific constants
6161

62-
# See EIP-7907 (https://eips.ethereum.org/EIPS/eip-7907) Maximum code size
62+
# See EIP-170 (https://eips.ethereum.org/EIPS/eip-170) Maximum code size
6363
# that can be stored for a new contract. Init code when creating a new
6464
# contract is not subject to this limit.
65+
EIP170_SIZE_THRESHOLD* = 0x6000
66+
# See See EIP-170 (https://eips.ethereum.org/EIPS/eip-170). Update to limits
6567
CODE_SIZE_THRESHOLD* = 0x6000
6668
EIP7907_MAX_CODE_SIZE* = 0x40000
6769

68-
# See EIP-7907 (https://eips.ethereum.org/EIPS/eip-7907). Maximum initcode
70+
# See EIP-3860 (https://eips.ethereum.org/EIPS/eip-3860). Maximum initcode
6971
# size when creating a new contract.
70-
EIP7907_MAX_INITCODE_SIZE* = 0x80000 # 2 * EIP7907_MAX_CODE_SIZE
72+
EIP3860_MAX_INITCODE_SIZE* = 2 * EIP170_MAX_CODE_SIZE
73+
# See EIP-7907 (https://eips.ethereum.org/EIPS/eip-7907).
74+
EIP7907_MAX_INITCODE_SIZE* = 2 * EIP7907_MAX_CODE_SIZE
7175

7276
# EIP
7377
MaxPrecompilesAddr* = 0xFFFF

execution_chain/core/validate.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ func validateTxBasic*(
228228
if tx.txType == TxEip7702 and fork < FkPrague:
229229
return err("invalid tx: Eip7702 Tx type detected before Prague")
230230

231-
if fork >= FkShanghai and tx.contractCreation and tx.payload.len > EIP7907_MAX_INITCODE_SIZE:
232-
return err("invalid tx: initcode size exceeds maximum")
231+
if tx.contractCreation:
232+
if fork >= FkOsaka and tx.payload.len > EIP7907_MAX_INITCODE_SIZE:
233+
return err("invalid tx: initcode size exceeds maximum")
234+
elif fork >= FkShanghai and tx.payload.len > EIP3860_MAX_INITCODE_SIZE:
235+
return err("invalid tx: initcode size exceeds maximum")
236+
233237

234238
# The total must be the larger of the two
235239
if tx.maxFeePerGasNorm < tx.maxPriorityFeePerGasNorm:

execution_chain/db/access_list.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type
2121

2222
AccessList* = object
2323
slots: Table[Address, SlotSet]
24-
codeHashes: seq[Hash32]
24+
codeAddrs: seq[Address]
2525

2626
# ------------------------------------------------------------------------------
2727
# Private helpers
@@ -37,7 +37,7 @@ func toStorageKeys(slots: SlotSet): seq[Bytes32] =
3737

3838
proc init*(ac: var AccessList) =
3939
ac.slots = Table[Address, SlotSet]()
40-
ac.codeHashes = newSeq[Hash32]()
40+
ac.codeAddrs = newSeq[Address]()
4141

4242
proc init*(_: type AccessList): AccessList {.inline.} =
4343
result.init()
@@ -49,8 +49,8 @@ proc init*(_: type AccessList): AccessList {.inline.} =
4949
func contains*(ac: AccessList, address: Address): bool {.inline.} =
5050
address in ac.slots
5151

52-
func contains*(ac: AccessList, codeHash: Hash32): bool {.inline.} =
53-
codeHash in ac.codeHashes
52+
func containsCode*(ac: AccessList, codeAddr: Address): bool {.inline.} =
53+
codeAddr in ac.codeAddrs
5454

5555
# returnValue: (addressPresent, slotPresent)
5656
func contains*(ac: var AccessList, address: Address, slot: UInt256): bool =
@@ -60,7 +60,7 @@ func contains*(ac: var AccessList, address: Address, slot: UInt256): bool =
6060
proc mergeAndReset*(ac, other: var AccessList) =
6161
# move values in `other` to `ac`
6262
ac.slots.mergeAndReset(other.slots)
63-
ac.codeHashes.mergeAndReset(other.codeHashes)
63+
ac.codeAddrs.mergeAndReset(other.codeAddrs)
6464

6565
proc add*(ac: var AccessList, address: Address) =
6666
if address notin ac.slots:
@@ -72,13 +72,13 @@ proc add*(ac: var AccessList, address: Address, slot: UInt256) =
7272
do:
7373
ac.slots[address] = toHashSet([slot])
7474

75-
proc add*(ac: var AccessList, codeHash: Hash32) =
76-
if codeHash notin ac.codeHashes:
77-
ac.codeHashes.add(codeHash)
75+
proc addCode*(ac: var AccessList, codeAddr: Address) =
76+
if codeAddr notin ac.codeAddrs:
77+
ac.codeAddrs.add(codeAddr)
7878

7979
proc clear*(ac: var AccessList) {.inline.} =
8080
ac.slots.clear()
81-
ac.codeHashes.setLen(0)
81+
ac.codeAddrs.setLen(0)
8282

8383
# TODO: accesses code is still not a part of the transaction access list
8484
# but when it does trickle down into the transaction we will have to add
@@ -105,8 +105,8 @@ func equal*(ac: AccessList, other: var AccessList): bool =
105105
do:
106106
return false
107107

108-
for codeHash in ac.codeHashes:
109-
if codeHash notin other:
108+
for codeAddr in ac.codeAddrs:
109+
if codeAddr notin other:
110110
return false
111111

112112
true

execution_chain/db/ledger.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ proc accessList*(ac: LedgerRef, address: Address) =
829829
proc accessList*(ac: LedgerRef, address: Address, slot: UInt256) =
830830
ac.savePoint.accessList.add(address, slot)
831831

832-
proc accessList*(ac: LedgerRef, codeHash: Hash32) =
833-
ac.savePoint.accessList.add(codeHash)
832+
proc accessList*(ac: LedgerRef, codeAddr: Address) =
833+
ac.savePoint.accessList.addCode(codeAddr)
834834

835835
func inAccessList*(ac: LedgerRef, address: Address): bool =
836836
var sp = ac.savePoint
@@ -848,10 +848,10 @@ func inAccessList*(ac: LedgerRef, address: Address, slot: UInt256): bool =
848848
return
849849
sp = sp.parentSavepoint
850850

851-
func inAccessList*(ac: LedgerRef, codeHash: Hash32): bool =
851+
func inCodeAccessList*(ac: LedgerRef, codeAddr: Address): bool =
852852
var sp = ac.savePoint
853853
while sp != nil:
854-
result = sp.accessList.contains(codeHash)
854+
result = sp.accessList.containsCode(codeAddr)
855855
if result:
856856
return
857857
sp = sp.parentSavepoint

execution_chain/evm/computation.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,23 @@ proc writeContract*(c: Computation) =
207207

208208
# EIP-170 constraint (https://eips.ethereum.org/EIPS/eip-3541).
209209
if fork >= FkSpurious and len > EIP7907_MAX_CODE_SIZE:
210+
withExtra trace, "New contract code exceeds EIP-170 limit",
211+
codeSize=len, maxSize=EIP170_MAX_CODE_SIZE
212+
c.setError(StatusCode.OutOfGas, true)
213+
return
214+
215+
# EIP-7907 constraint (https://eips.ethereum.org/EIPS/eip-7907).
216+
if fork >= FkOsaka and len > EIP7907_MAX_CODE_SIZE:
210217
withExtra trace, "New contract code exceeds EIP-7907 limit",
211218
codeSize=len, maxSize=EIP7907_MAX_CODE_SIZE
212219
c.setError(StatusCode.OutOfGas, true)
213220
return
221+
# EIP-170 constraint (https://eips.ethereum.org/EIPS/eip-170).
222+
elif fork >= FkSpurious and len > EIP7907_MAX_CODE_SIZE:
223+
withExtra trace, "New contract code exceeds EIP-170 limit",
224+
codeSize=len, maxSize=EIP170_MAX_CODE_SIZE
225+
c.setError(StatusCode.OutOfGas, true)
226+
return
214227

215228
# Charge gas and write the code even if the code address is self-destructed.
216229
# Non-empty code in a newly created, self-destructed account is possible if

execution_chain/evm/interpreter/op_handlers/oph_call.nim

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@ proc gasCallEIP2929(c: Computation, address: Address): GasInt =
6666
# the form of a constant `gasCall`
6767
return ColdAccountAccessCost - WarmStorageReadCost
6868

69-
proc gasCallEIP7907(c: Computation, codeAddress: Address): GasInt =
70-
c.vmState.mutateLedger:
71-
let codeHash = db.getCodeHash(codeAddress)
72-
73-
if not db.inAccessList(codeHash):
74-
db.accessList(codeHash)
75-
76-
let
77-
code = db.getCode(codeAddress)
78-
excessContractSize = max(0, code.len - CODE_SIZE_THRESHOLD)
79-
largeContractCost = (ceil32(excessContractSize) * 2) div 32
80-
return GasInt(largeContractCost)
81-
8269
proc updateStackAndParams(q: var LocalParams; c: Computation) =
8370
c.stack.lsTop(0)
8471

execution_chain/evm/interpreter/op_handlers/oph_create.nim

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ proc createOp(cpt: VmCpt): EvmResultVoid =
7676
cpt.stack.lsShrink(2)
7777
cpt.stack.lsTop(0)
7878

79-
# EIP-3860
80-
if cpt.fork >= FkShanghai and memLen > EIP7907_MAX_INITCODE_SIZE:
79+
# EIP-7907 and EIP-3860
80+
if cpt.fork >= FkOsaka and memLen > EIP7907_MAX_INITCODE_SIZE:
81+
trace "Initcode size exceeds maximum", initcodeSize = memLen
82+
return err(opErr(InvalidInitCode))
83+
elif cpt.fork >= FkShanghai and memLen > EIP3860_MAX_INITCODE_SIZE:
8184
trace "Initcode size exceeds maximum", initcodeSize = memLen
8285
return err(opErr(InvalidInitCode))
8386

@@ -146,8 +149,11 @@ proc create2Op(cpt: VmCpt): EvmResultVoid =
146149
cpt.stack.lsShrink(3)
147150
cpt.stack.lsTop(0)
148151

149-
# EIP-3860
150-
if cpt.fork >= FkShanghai and memLen > EIP7907_MAX_INITCODE_SIZE:
152+
# EIP-7907 and EIP-3860
153+
if cpt.fork >= FkOsaka and memLen > EIP7907_MAX_INITCODE_SIZE:
154+
trace "Initcode size exceeds maximum", initcodeSize = memLen
155+
return err(opErr(InvalidInitCode))
156+
elif cpt.fork >= FkShanghai and memLen > EIP3860_MAX_INITCODE_SIZE:
151157
trace "Initcode size exceeds maximum", initcodeSize = memLen
152158
return err(opErr(InvalidInitCode))
153159

execution_chain/evm/interpreter/op_handlers/oph_helpers.nim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ proc delegateResolutionCost*(c: Computation, address: Address): GasInt =
6060
else:
6161
return WarmStorageReadCost
6262

63+
proc gasEip7702CodeCheck*(c: Computation; address: Address): GasInt =
64+
let delegateTo =
65+
parseDelegationAddress(c.vmState.readOnlyLedger.getCode(address)).valueOr:
66+
return 0
67+
c.delegateResolutionCost(delegateTo)
68+
69+
proc gasCallEIP7907*(c: Computation, codeAddress: Address): GasInt =
70+
c.vmState.mutateLedger:
71+
let codeHash = db.getCodeHash(codeAddress)
72+
73+
if not db.inAccessList(codeHash):
74+
db.accessList(codeHash)
75+
76+
let
77+
code = db.getCode(codeAddress)
78+
excessContractSize = max(0, code.len - CODE_SIZE_THRESHOLD)
79+
largeContractCost = (ceil32(excessContractSize) * 2) div 32
80+
return GasInt(largeContractCost)
81+
6382
# ------------------------------------------------------------------------------
6483
# End
6584
# ------------------------------------------------------------------------------

hive_integration/nodocker/engine/withdrawals/wd_max_init_code_spec.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type
3232
overflowMaxInitcodeTxCountAfterFork *: uint64
3333

3434
const
35-
MAX_INITCODE_SIZE = EIP7907_MAX_INITCODE_SIZE
35+
MAX_INITCODE_SIZE = EIP170_MAX_INITCODE_SIZE
3636

3737
proc execute*(ws: MaxInitcodeSizeSpec, env: TestEnv): bool =
3838
testCond waitFor env.clMock.waitForTTD()

vendor/constantine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 782d838e7a073262750eff593af6dfff3ff832dd

0 commit comments

Comments
 (0)