Skip to content

Commit

Permalink
feat: ensure sender nonce doesnt overflow u64 (#1444)
Browse files Browse the repository at this point in the history
ensure the sender nonce is not MAX_U64 otherwise reject tx.

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1444)
<!-- Reviewable:end -->
  • Loading branch information
enitrat committed Sep 25, 2024
1 parent ad40c50 commit 58d82ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions blockchain-tests-skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ testname:
stCreateTest:
- CreateOOGafterMaxCodesize_d3g0v0_Cancun #RunResources error
- CreateOOGafterMaxCodesize_d5g0v0_Cancun #RunResources error
- CreateTransactionHighNonce_d0g0v0_Cancun
- CreateTransactionHighNonce_d0g0v1_Cancun
stCallCreateCallCodeTest:
- Call1024PreCalls_d0g0v0_Cancun #RunResources error
- Call1024PreCalls_d0g1v0_Cancun #RunResources error
stExtCodeHash:
# fails because we don't support the behavior described in: https://github.com/ethereum/execution-specs/blob/07f5747a43d62ef7f203d41d77005cb15ca5e434/src/ethereum/cancun/vm/interpreter.py#L165-L177
# At no point in Kakarot can there be an empty account with storage.
- dynamicAccountOverwriteEmpty_Paris_d0g0v0_Cancun
stDelegatecallTestHomestead:
- Call1024PreCalls_d0g0v0_Cancun #RunResources error
Expand Down Expand Up @@ -454,6 +454,8 @@ testname:
- randomStatetest476_d0g0v0_Cancun #RunResources error
- randomStatetest650_d0g0v0_Cancun #RunResources error
stSStoreTest:
# Test family fails because we don't support the behavior described in: https://github.com/ethereum/execution-specs/blob/07f5747a43d62ef7f203d41d77005cb15ca5e434/src/ethereum/cancun/vm/interpreter.py#L165-L177
# At no point in Kakarot can there be an empty account with storage.
- InitCollisionParis_d0g0v0_Cancun
- InitCollisionParis_d1g0v0_Cancun
- InitCollisionParis_d2g0v0_Cancun
Expand Down
28 changes: 28 additions & 0 deletions src/kakarot/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,32 @@ namespace Errors {
dw 'c';
dw 'y';
}

func nonceIsMax() -> (error_len: felt, error: felt*) {
let (error) = get_label_location(nonce_is_max_error_message);
return (21, error);
nonce_is_max_error_message:
dw 'K';
dw 'a';
dw 'k';
dw 'a';
dw 'r';
dw 'o';
dw 't';
dw ':';
dw ' ';
dw 'n';
dw 'o';
dw 'n';
dw 'c';
dw 'e';
dw ' ';
dw 'i';
dw 's';
dw ' ';
dw 'm';
dw 'a';
dw 'x';
}
}
7 changes: 7 additions & 0 deletions src/kakarot/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,13 @@ namespace Interpreter {
let sender = State.get_account(env.origin);
let (local new_balance) = uint256_sub([sender.balance], max_fee_u256);
let sender = Account.set_balance(sender, &new_balance);
// Check that the sender nonce cannot overflow MAX_64
if (sender.nonce == 2 ** 64 - 1) {
let (revert_reason_len, revert_reason) = Errors.nonceIsMax();
let evm = EVM.stop(evm, revert_reason_len, revert_reason, Errors.EXCEPTIONAL_HALT);
State.finalize();
return (evm, stack, memory, state, 0, 0);
}
let sender = Account.set_nonce(sender, sender.nonce + 1);
State.update_account(sender);

Expand Down

0 comments on commit 58d82ec

Please sign in to comment.