# Nimbus # Copyright (c) 2023-2025 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) # * MIT license ([LICENSE-MIT](LICENSE-MIT) or # http://opensource.org/licenses/MIT) # at your option. This file may not be copied, modified, or distributed except # according to those terms. import std/[tables], eth/common/[keys, transaction_utils], stew/endians2, nimcrypto/sha2, chronicles, ./engine_client, ./cancun/blobs, ../../../execution_chain/transaction, ../../../execution_chain/common, ../../../execution_chain/utils/utils from std/sequtils import mapIt type BaseTx* = object of RootObj recipient* : Opt[Address] gasLimit* : GasInt amount* : UInt256 payload* : seq[byte] txType* : Opt[TxType] gasTip* : GasInt gasFee* : GasInt blobGasFee*: UInt256 blobCount* : int blobID* : BlobID authorizationList*: seq[Authorization] BigInitcodeTx* = object of BaseTx initcodeLength*: int padByte* : uint8 initcode* : seq[byte] # Blob transaction creator BlobTx* = object of BaseTx TestAccount* = object key* : PrivateKey address*: Address index* : int TxSender* = ref object accounts: seq[TestAccount] nonceMap: Table[Address, uint64] txSent : int chainId : ChainId MakeTxParams* = object chainId*: ChainId key* : PrivateKey nonce* : AccountNonce CustSig* = object V*: uint64 R*: UInt256 S*: UInt256 CustomTransactionData* = object nonce* : Opt[uint64] gasPriceOrGasFeeCap*: Opt[GasInt] gasTipCap* : Opt[GasInt] gas* : Opt[GasInt] blobGas* : Opt[UInt256] to* : Opt[common.Address] value* : Opt[UInt256] data* : Opt[seq[byte]] chainId* : Opt[ChainId] signature* : Opt[CustSig] auth* : Opt[Authorization] const TestAccountCount = 1000 gasPrice* = 30.gwei gasTipPrice* = 1.gwei blobGasPrice* = 1.gwei func toAddress(key: PrivateKey): Address = toKeyPair(key).pubkey.toCanonicalAddress() proc createAccount(idx: int): TestAccount = let seed = toBytesBE(idx.uint64) seedHash = sha256.digest(seed) result.index = idx result.key = PrivateKey.fromRaw(seedHash.data).valueOr: echo error quit(QuitFailure) result.address = toAddress(result.key) proc createAccounts(sender: TxSender, numAccounts: int) = for i in 0.. 0) modTx.authorizationList[0] = custTx.auth.get if custTx.signature.isSome: let signature = custTx.signature.get modTx.V = signature.V modTx.R = signature.R modTx.S = signature.S else: modTx.signature = modTx.sign(acc.key, eip155 = true) modTx proc makeAuth*(sender: TxSender, acc: TestAccount, nonce: AccountNonce): Authorization = var auth = Authorization( chainId: sender.chainId, address: acc.address, nonce: nonce, ) let hash = auth.rlpHashForSigning() let sig = sign(acc.key, SkMessage(hash.data)) let raw = sig.toRaw() auth.r = UInt256.fromBytesBE(raw.toOpenArray(0, 31)) auth.s = UInt256.fromBytesBE(raw.toOpenArray(32, 63)) auth.v = raw[64].uint64