Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
fix: call depth (#1018)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->
Closes #1017

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #<Issue number>

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

<!-- 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/1018)
<!-- Reviewable:end -->
  • Loading branch information
enitrat authored Mar 6, 2024
1 parent efb810d commit 3f9326e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
6 changes: 1 addition & 5 deletions blockchain-tests-skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ testname:
- create2collisionStorage_d1g0v0_Shanghai
- create2collisionStorage_d2g0v0_Shanghai
stCallCreateCallCodeTest:
- Call1024BalanceTooLow_d0g0v0_Shanghai
- Call1024PreCalls_d0g0v0_Shanghai
- Call1024PreCalls_d0g1v0_Shanghai
- CallRecursiveBombPreCall_d0g0v0_Shanghai
- Callcode1024BalanceTooLow_d0g0v0_Shanghai
stCreateTest:
- CreateOOGafterMaxCodesize_d2g0v0_Shanghai
- CreateOOGafterMaxCodesize_d3g0v0_Shanghai
- CreateOOGafterMaxCodesize_d5g0v0_Shanghai
- CreateTransactionHighNonce_d0g0v0_Shanghai
- CreateTransactionHighNonce_d0g0v1_Shanghai
stDelegatecallTestHomestead:
- Call1024BalanceTooLow_d0g0v0_Shanghai
- Call1024PreCalls_d0g1v0_Shanghai
- Call1024PreCalls_d0g2v0_Shanghai
- CallRecursiveBombPreCall_d0g0v0_Shanghai
Expand Down Expand Up @@ -161,11 +158,10 @@ testname:
stReturnDataTest:
- modexp_modsize0_returndatasize_d4g0v0_Shanghai
stStaticCall:
- static_Call1MB1024Calldepth_d1g0v0_Shanghai
- StaticcallToPrecompileFromCalledContract_d0g0v0_Shanghai
- StaticcallToPrecompileFromContractInitialization_d0g0v0_Shanghai
- StaticcallToPrecompileFromTransaction_d0g0v0_Shanghai
- static_Call1024PreCalls2_d0g0v0_Shanghai
- static_Call1MB1024Calldepth_d1g0v0_Shanghai
- static_Call50000_d0g0v0_Shanghai
- static_Call50000_d1g0v0_Shanghai
- static_Call50000_ecrec_d0g0v0_Shanghai
Expand Down
16 changes: 8 additions & 8 deletions src/kakarot/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace SystemOperations {
let sender = State.get_account(evm.message.address.evm);
let is_nonce_overflow = Helpers.is_zero(Constants.MAX_NONCE - sender.nonce);
let (is_balance_overflow) = uint256_lt([sender.balance], [value]);
let stack_depth_limit = is_le(1024, evm.message.depth);
let stack_depth_limit = Helpers.is_zero(Constants.STACK_MAX_DEPTH - evm.message.depth);
if (is_nonce_overflow + is_balance_overflow + stack_depth_limit != 0) {
Stack.push_uint128(0);
return evm;
Expand Down Expand Up @@ -369,7 +369,7 @@ namespace SystemOperations {
let sender = State.get_account(evm.message.address.evm);
let (sender_balance_lt_value) = uint256_lt([sender.balance], [value]);
tempvar is_max_depth_reached = Helpers.is_zero(
(Constants.STACK_MAX_DEPTH + 1) - evm.message.depth
Constants.STACK_MAX_DEPTH - evm.message.depth
);
tempvar is_call_invalid = sender_balance_lt_value + is_max_depth_reached;
if (is_call_invalid != FALSE) {
Expand Down Expand Up @@ -473,8 +473,8 @@ namespace SystemOperations {
tempvar memory = new model.Memory(
memory.word_dict_start, memory.word_dict, memory_expansion.new_words_len
);
tempvar is_max_depth_reached = 1 - is_not_zero(
(Constants.STACK_MAX_DEPTH + 1) - evm.message.depth
tempvar is_max_depth_reached = Helpers.is_zero(
Constants.STACK_MAX_DEPTH - evm.message.depth
);

if (is_max_depth_reached != FALSE) {
Expand Down Expand Up @@ -576,8 +576,8 @@ namespace SystemOperations {
);
let sender = State.get_account(evm.message.address.evm);
let (sender_balance_lt_value) = uint256_lt([sender.balance], [value]);
tempvar is_max_depth_reached = 1 - is_not_zero(
(Constants.STACK_MAX_DEPTH + 1) - evm.message.depth
tempvar is_max_depth_reached = Helpers.is_zero(
Constants.STACK_MAX_DEPTH - evm.message.depth
);
tempvar is_call_invalid = sender_balance_lt_value + is_max_depth_reached;
if (is_call_invalid != FALSE) {
Expand Down Expand Up @@ -668,8 +668,8 @@ namespace SystemOperations {
return evm;
}

tempvar is_max_depth_reached = 1 - is_not_zero(
(Constants.STACK_MAX_DEPTH + 1) - evm.message.depth
tempvar is_max_depth_reached = Helpers.is_zero(
Constants.STACK_MAX_DEPTH - evm.message.depth
);
if (is_max_depth_reached != FALSE) {
// Requires popping the returndata offset and size before pushing 0
Expand Down

0 comments on commit 3f9326e

Please sign in to comment.