Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes related to Prague execution requests #2847

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nimbus/common/chain_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ func chainConfigForNetwork*(id: NetworkId): ChainConfig =

result = case id
of MainNet:
const mainNetTTD = parse("58750000000000000000000",UInt256)
const
mainNetTTD = parse("58750000000000000000000",UInt256)
MAINNET_DEPOSIT_CONTRACT_ADDRESS = address"0x00000000219ab540356cbb839cbe05303d7705fa"
ChainConfig(
chainId: MainNet.ChainId,
# Genesis (Frontier): # 2015-07-30 15:26:13 UTC
Expand All @@ -470,6 +472,7 @@ func chainConfigForNetwork*(id: NetworkId): ChainConfig =
terminalTotalDifficulty: Opt.some(mainNetTTD),
shanghaiTime: Opt.some(1_681_338_455.EthTime), # 2023-04-12 10:27:35 UTC
cancunTime: Opt.some(1_710_338_135.EthTime), # 2024-03-13 13:55:35 UTC
depositContractAddress: Opt.some(MAINNET_DEPOSIT_CONTRACT_ADDRESS),
)
of SepoliaNet:
const sepoliaTTD = parse("17000000000000000",UInt256)
Expand Down
3 changes: 3 additions & 0 deletions nimbus/common/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ proc proofOfStake*(com: CommonRef, header: Header): bool =
# This costly check is only executed from test suite
com.isBlockAfterTtd(header)

func depositContractAddress*(com: CommonRef): Address =
com.config.depositContractAddress.get(default(Address))

proc syncReqNewHead*(com: CommonRef; header: Header)
{.gcsafe, raises: [].} =
## Used by RPC updater
Expand Down
1 change: 1 addition & 0 deletions nimbus/common/hardforks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ type

terminalTotalDifficulty*: Opt[UInt256]
terminalTotalDifficultyPassed*: Opt[bool]
depositContractAddress*: Opt[Address]

# These are used for checking that the values of the fields
# are in a valid order.
Expand Down
5 changes: 2 additions & 3 deletions nimbus/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const
initAddress(3)

HISTORY_STORAGE_ADDRESS* = address"0x0aae40965e6800cd9b1f4b05ff21581047e3f91e"
DEPOSIT_CONTRACT_ADDRESS* = address"0x00000000219ab540356cbb839cbe05303d7705fa"
WITHDRAWAL_REQUEST_ADDRESS* = address"0x00A3ca265EBcb825B45F985A16CEFB49958cE017"
CONSOLIDATION_REQUEST_ADDRESS* = address"0x00b42dbF2194e931E80326D950320f7d9Dbeac02"
WITHDRAWAL_QUEUE_ADDRESS* = address"0x09Fc772D0857550724b07B850a4323f39112aAaA"
CONSOLIDATION_QUEUE_ADDRESS* = address"0x01aBEa29659e5e97C95107F20bb753cD3e09bBBb"
# End
18 changes: 8 additions & 10 deletions nimbus/core/eip6110.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import
eth/common/receipts,
stew/assign2,
stew/arrayops,
results,
../constants
results

# -----------------------------------------------------------------------------
# Private helpers
Expand Down Expand Up @@ -71,14 +70,13 @@ func depositLogToRequest(data: openArray[byte]): DepositRequest =
# Public functions
# -----------------------------------------------------------------------------

func parseDepositLogs*(logs: openArray[Log]): Result[seq[byte], string] =
var res = newSeq[byte](logs.len*depositRequestSize)
func parseDepositLogs*(logs: openArray[Log], depositContractAddress: Address): Result[seq[byte], string] =
var res = newSeqOfCap[byte](logs.len*depositRequestSize)
for i, log in logs:
if log.address == DEPOSIT_CONTRACT_ADDRESS:
if log.data.len != 576:
return err("deposit wrong length: want 576, have " & $log.data.len)
let offset = i*depositRequestSize
assign(res.toOpenArray(offset, offset+depositRequestSize-1),
depositLogToRequest(log.data))
if log.address != depositContractAddress:
continue
if log.data.len != 576:
return err("deposit wrong length: want 576, have " & $log.data.len)
res.add depositLogToRequest(log.data)

ok(move(res))
2 changes: 1 addition & 1 deletion nimbus/core/executor/process_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ proc procBlkEpilogue(

if header.requestsHash.isSome:
let
depositReqs = ?parseDepositLogs(vmState.allLogs)
depositReqs = ?parseDepositLogs(vmState.allLogs, vmState.com.depositContractAddress)
requestsHash = calcRequestsHash(depositReqs, withdrawalReqs, consolidationReqs)

if header.requestsHash.get != requestsHash:
Expand Down
4 changes: 2 additions & 2 deletions nimbus/core/executor/process_transaction.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ proc processDequeueWithdrawalRequests*(vmState: BaseVMState): seq[byte] =
sender : SYSTEM_ADDRESS,
gasLimit : 30_000_000.GasInt,
gasPrice : 0.GasInt,
to : WITHDRAWAL_REQUEST_ADDRESS,
to : WITHDRAWAL_QUEUE_ADDRESS,

# It's a systemCall, no need for other knicks knacks
sysCall : true,
Expand All @@ -221,7 +221,7 @@ proc processDequeueConsolidationRequests*(vmState: BaseVMState): seq[byte] =
sender : SYSTEM_ADDRESS,
gasLimit : 30_000_000.GasInt,
gasPrice : 0.GasInt,
to : CONSOLIDATION_REQUEST_ADDRESS,
to : CONSOLIDATION_QUEUE_ADDRESS,

# It's a systemCall, no need for other knicks knacks
sysCall : true,
Expand Down
2 changes: 1 addition & 1 deletion nimbus/core/tx_pool/tx_packer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ proc vmExecCommit(pst: var TxPacker): Result[void, string] =
if vmState.fork >= FkPrague:
pst.withdrawalReqs = processDequeueWithdrawalRequests(vmState)
pst.consolidationReqs = processDequeueConsolidationRequests(vmState)
pst.depositReqs = ?parseDepositLogs(vmState.allLogs)
pst.depositReqs = ?parseDepositLogs(vmState.allLogs, vmState.com.depositContractAddress)

# Finish up, then vmState.stateDB.stateRoot may be accessed
stateDB.persist(clearEmptyAccount = vmState.fork >= FkSpurious)
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/core_db/core_apps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{.push gcsafe, raises: [].}

import
std/[algorithm, sequtils],
std/[sequtils],
chronicles,
eth/[common, rlp],
stew/byteutils,
Expand Down
5 changes: 2 additions & 3 deletions nimbus/evm/interpreter/evmc_gas_costs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ func storageCostSpec(): array[EVMFork, StorageCostSpec] {.compileTime.} =
netCost: true, warmAccess: WarmStorageReadCost, sset: 20000,
reset: 5000 - ColdSloadCost, clear: 4800)

result[FkParis] = result[FkLondon]
result[FkShanghai] = result[FkLondon]
result[FkCancun] = result[FkLondon]
for fork in FkParis..EVMFork.high:
result[fork] = result[FkLondon]

proc legacySStoreCost(e: var SstoreCosts,
c: StorageCostSpec) {.compileTime.} =
Expand Down
1 change: 1 addition & 0 deletions nimbus/evm/interpreter/op_dispatcher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ template handleStopDirective(cpt: VmCpt, tracingEnabled: bool) =
if not cpt.code.atEnd():
# we only trace `REAL STOP` and ignore `FAKE STOP`
cpt.opIndex = cpt.traceOpCodeStarted(Stop)
?cpt.opcodeGasCost(Stop, 0, tracingEnabled, reason = $Stop)
cpt.traceOpCodeEnded(Stop, cpt.opIndex)

template handleFixedGasCostsDirective(
Expand Down
2 changes: 1 addition & 1 deletion nimbus/transaction/host_trace.nim
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ proc showEvmcArgsExpr(fn: NimNode, callName: string): auto =
if (types[i].repr == "ptr byte" or types[i].repr == "ptr HostTopic") and
(i < args.len-1 and types[i+1].repr == "HostSize"):
skip = i+1
arg = newPar(args[i], args[i+1])
arg = newNimNode(nnkTupleConstr).add(args[i], args[i+1])
msgExpr = quote do:
`msgExpr` & `argNameString` & $(`arg`)
return (msgExpr, args)
Expand Down
23 changes: 19 additions & 4 deletions tools/t8n/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ proc readValue*(r: var JsonReader[T8Conv], val: var EnvStruct)
of "blockHashes": r.readValue(val.blockHashes)
of "ommers": r.readValue(val.ommers)
of "withdrawals": r.readValue(val.withdrawals)
of "depositContractAddress": r.readValue(val.depositContractAddress)
else: discard r.readValue(JsonString)

if not currentCoinbaseParsed:
Expand Down Expand Up @@ -235,10 +236,10 @@ proc parseTxJson(txo: TxObject, chainId: ChainId): Result[Transaction, string] =
required(value)
required(input, payload)
tx.to = txo.to
tx.chainId = chainId

case tx.txType
of TxLegacy:
tx.chainId = chainId
required(gasPrice)
of TxEip2930:
required(gasPrice)
Expand All @@ -263,6 +264,9 @@ proc parseTxJson(txo: TxObject, chainId: ChainId): Result[Transaction, string] =
optional(accessList)
required(authorizationList)

if tx.chainId != chainId:
return err("invalid chain id: have " & $tx.chainId & " want " & $chainId)

let eip155 = txo.protected.get(true)
if txo.secretKey.isSome:
let secretKey = PrivateKey.fromRaw(txo.secretKey.get).valueOr:
Expand All @@ -274,13 +278,17 @@ proc parseTxJson(txo: TxObject, chainId: ChainId): Result[Transaction, string] =
required(s, S)
ok(tx)

proc readNestedTx(rlp: var Rlp): Result[Transaction, string] =
proc readNestedTx(rlp: var Rlp, chainId: ChainId): Result[Transaction, string] =
try:
ok if rlp.isList:
let tx = if rlp.isList:
rlp.read(Transaction)
else:
var rr = rlpFromBytes(rlp.read(seq[byte]))
rr.read(Transaction)
if tx.chainId == chainId:
ok(tx)
else:
err("invalid chain id: have " & $tx.chainId & " want " & $chainId)
except RlpError as exc:
err(exc.msg)

Expand All @@ -301,7 +309,7 @@ proc parseTxs*(ctx: var TransContext, chainId: ChainId)

if ctx.txsRlp.len > 0:
for item in rlp:
ctx.txList.add rlp.readNestedTx()
ctx.txList.add rlp.readNestedTx(chainId)

proc filterGoodTransactions*(ctx: TransContext): seq[Transaction] =
for txRes in ctx.txList:
Expand Down Expand Up @@ -433,6 +441,11 @@ proc `@@`[T](x: seq[T]): JsonNode =
for c in x:
result.add @@(c)

proc `@@`[N, T](x: array[N, T]): JsonNode =
result = newJArray()
for c in x:
result.add @@(c)

proc `@@`[T](x: Opt[T]): JsonNode =
if x.isNone:
newJNull()
Expand Down Expand Up @@ -462,3 +475,5 @@ proc `@@`*(x: ExecutionResult): JsonNode =
result["blobGasUsed"] = @@(x.blobGasUsed)
if x.requestsHash.isSome:
result["requestsHash"] = @@(x.requestsHash)
if x.requests.isSome:
result["requests"] = @@(x.requests)
67 changes: 52 additions & 15 deletions tools/t8n/t8n_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type
inEnv : string
stFork : string
stReward: string
chainid : string

T8nOutput = object
alloc : bool
Expand All @@ -39,13 +40,15 @@ type
path: string
error: string

proc t8nInput(alloc, txs, env, fork, reward: string): T8nInput =
proc t8nInput(alloc, txs, env, fork: string;
reward = "0"; chainid = ""): T8nInput =
T8nInput(
inAlloc : alloc,
inTxs : txs,
inEnv : env,
stFork : fork,
stReward: reward
stReward: reward,
chainid : chainid,
)

proc get(opt: T8nInput, base : string): string =
Expand All @@ -55,6 +58,8 @@ proc get(opt: T8nInput, base : string): string =
result.add(" --state.fork " & opt.stFork)
if opt.stReward.len > 0:
result.add(" --state.reward " & opt.stReward)
if opt.chainid.len > 0:
result.add(" --state.chainid " & opt.chainid)

proc get(opt: T8nOutput): string =
if opt.alloc and not opt.trace:
Expand Down Expand Up @@ -164,15 +169,20 @@ proc runTest(appDir: string, spec: TestSpec): bool =

if spec.expOut.len > 0:
if spec.expOut.endsWith(".json"):
let path = base / spec.expOut
let want = json.parseFile(path)
let have = json.parseJson(res)
var jsc = JsonComparator()
if not jsc.cmp(want, have, "root") and notRejectedError(jsc.path):
echo "test $1: output wrong, have \n$2\nwant\n$3\n" %
[spec.name, have.pretty, want.pretty]
echo "path: $1, error: $2" %
[jsc.path, jsc.error]
let path = base / spec.expOut
try:
let want = json.parseFile(path)
let have = json.parseJson(res)
var jsc = JsonComparator()
if not jsc.cmp(want, have, "root") and notRejectedError(jsc.path):
echo "test $1: output wrong, have \n$2\nwant\n$3\n" %
[spec.name, have.pretty, want.pretty]
echo "path: $1, error: $2" %
[jsc.path, jsc.error]
return false
except JsonParsingError as exc:
echo "test $1: ERROR: $2" % [spec.name, exc.msg]
echo "test $1: OUTPUT: $2" % [spec.name, res]
return false
else:
# compare as regular text
Expand Down Expand Up @@ -460,7 +470,7 @@ const
name : "Revert In Create In Init Create2",
base : "testdata/00-512",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Berlin", "0"
"alloc.json", "txs.rlp", "env.json", "Berlin", "0", "0"
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
Expand All @@ -469,7 +479,7 @@ const
name : "Revert In Create In Init",
base : "testdata/00-513",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Berlin", "0"
"alloc.json", "txs.rlp", "env.json", "Berlin", "0", "0"
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
Expand All @@ -478,7 +488,7 @@ const
name : "Init collision 3",
base : "testdata/00-514",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Berlin", "0"
"alloc.json", "txs.rlp", "env.json", "Berlin", "0", "0"
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
Expand All @@ -496,7 +506,7 @@ const
name : "GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideLast_Frontier",
base : "testdata/00-516",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Frontier", "5000000000000000000",
"alloc.json", "txs.rlp", "env.json", "Frontier", "5000000000000000000", "0"
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
Expand Down Expand Up @@ -609,6 +619,33 @@ const
output: T8nOutput(result: true),
expOut: "exp.json",
),
TestSpec(
name : "Different --state.chainid and tx.chainid",
base : "testdata/00-525",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Prague",
),
output: T8nOutput(result: true),
expOut: "exp1.json",
),
TestSpec(
name : "Prague execution requests",
base : "testdata/00-525",
input : t8nInput(
"alloc.json", "txs.rlp", "env.json", "Prague", "", "7078815900"
),
output: T8nOutput(result: true),
expOut: "exp2.json",
),
TestSpec(
name : "Prague depositContractAddress",
base : "testdata/00-525",
input : t8nInput(
"alloc.json", "txs.rlp", "env_dca.json", "Prague", "", "7078815900"
),
output: T8nOutput(result: true),
expOut: "exp3.json",
),
]

proc main() =
Expand Down
Loading
Loading