From 3f9326e19ddf16d18ec51b0d749c794e1590a5a8 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:18:46 +0100 Subject: [PATCH] fix: call depth (#1018) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1017 Time spent on this PR: ## Pull request type 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? Resolves # ## What is the new behavior? - - - - - - This change is [Reviewable](https://reviewable.io/reviews/kkrt-labs/kakarot/1018) --- blockchain-tests-skip.yml | 6 +----- src/kakarot/instructions/system_operations.cairo | 16 ++++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/blockchain-tests-skip.yml b/blockchain-tests-skip.yml index a5b543a8d..567fcaa8d 100644 --- a/blockchain-tests-skip.yml +++ b/blockchain-tests-skip.yml @@ -31,11 +31,9 @@ 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 @@ -43,7 +41,6 @@ testname: - CreateTransactionHighNonce_d0g0v0_Shanghai - CreateTransactionHighNonce_d0g0v1_Shanghai stDelegatecallTestHomestead: - - Call1024BalanceTooLow_d0g0v0_Shanghai - Call1024PreCalls_d0g1v0_Shanghai - Call1024PreCalls_d0g2v0_Shanghai - CallRecursiveBombPreCall_d0g0v0_Shanghai @@ -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 diff --git a/src/kakarot/instructions/system_operations.cairo b/src/kakarot/instructions/system_operations.cairo index 00bda76a0..381932c18 100644 --- a/src/kakarot/instructions/system_operations.cairo +++ b/src/kakarot/instructions/system_operations.cairo @@ -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; @@ -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) { @@ -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) { @@ -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) { @@ -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