EIP-2681: Limit account nonce to 2^64-1 (#1048)

* EIP-2681: Limit account nonce to 2^64-1

* Also for EOA

* Minor
This commit is contained in:
wborgeaud 2023-05-18 15:22:36 +02:00 committed by GitHub
parent 8faea881c1
commit 971bfba64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -75,6 +75,7 @@ global create_common:
DUP2 %selfbalance LT %jumpi(create_insufficient_balance)
// Increment the sender's nonce.
%address
DUP1 %nonce %eq_const(@MAX_NONCE) %jumpi(nonce_overflow) // EIP-2681
%increment_nonce
// stack: address, value, code_offset, code_len, kexit_info
@ -192,6 +193,10 @@ create_insufficient_balance:
%stack (address, value, code_offset, code_len, kexit_info) -> (kexit_info, 0)
EXIT_KERNEL
nonce_overflow:
%stack (sender, address, value, code_offset, code_len, kexit_info) -> (kexit_info, 0)
EXIT_KERNEL
%macro set_codehash
%stack (addr, codehash) -> (addr, codehash, %%after)
%jump(set_codehash)

View File

@ -25,6 +25,7 @@ global process_normalized_txn:
// Check that txn nonce matches account nonce.
DUP1 %nonce
DUP1 %eq_const(@MAX_NONCE) %assert_zero // EIP-2681
// stack: sender_nonce, sender, retdest
%mload_txn_field(@TXN_FIELD_NONCE)
// stack: tx_nonce, sender_nonce, sender, retdest
@ -103,7 +104,6 @@ global process_contract_creation_txn:
%create_contract_account
// stack: status, address, retdest
%jumpi(create_contract_account_fault)
global gtra:
// stack: address, retdest
// Transfer value to new contract

View File

@ -54,6 +54,8 @@ pub fn evm_constants() -> HashMap<String, U256> {
c.insert(name.into(), U256::from(value));
}
c.insert(MAX_NONCE.0.into(), U256::from(MAX_NONCE.1));
for segment in Segment::all() {
c.insert(segment.var_name().into(), (segment as u32).into());
}
@ -260,3 +262,5 @@ const CODE_SIZE_LIMIT: [(&str, u64); 3] = [
("MAX_INITCODE_SIZE", 0xc000),
("INITCODE_WORD_COST", 2),
];
const MAX_NONCE: (&str, u64) = ("MAX_NONCE", 0xffffffffffffffff);