From 474951c7babbd57f06d074aa15ba7a2f1911af21 Mon Sep 17 00:00:00 2001 From: Oba Date: Sat, 9 Nov 2024 16:38:36 +0100 Subject: [PATCH] [KGA-39] fix: default_dict_copy finalize with default value 0 (#1592) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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? Use `default_dict_finalize` with 0 - - - This change is [Reviewable](https://reviewable.io/reviews/kkrt-labs/kakarot/1592) --- blockchain-tests-skip.yml | 1 + cairo_zero/tests/src/utils/test_dict.cairo | 2 +- cairo_zero/utils/dict.cairo | 16 +++------------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/blockchain-tests-skip.yml b/blockchain-tests-skip.yml index a4b816e41..380795483 100644 --- a/blockchain-tests-skip.yml +++ b/blockchain-tests-skip.yml @@ -465,6 +465,7 @@ testname: - StaticcallToPrecompileFromContractInitialization_d0g0v0_Cancun - StaticcallToPrecompileFromTransaction_d0g0v0_Cancun - static_Call1MB1024Calldepth_d1g0v0_Cancun #RunResources error + - static_Call1024PreCalls2_d0g0v0_Cancun #RunResources error - static_Call50000_d0g0v0_Cancun #RunResources error - static_Call50000_d1g0v0_Cancun #RunResources error - static_Call50000_ecrec_d0g0v0_Cancun #RunResources error diff --git a/cairo_zero/tests/src/utils/test_dict.cairo b/cairo_zero/tests/src/utils/test_dict.cairo index d4cfebbb5..2431df554 100644 --- a/cairo_zero/tests/src/utils/test_dict.cairo +++ b/cairo_zero/tests/src/utils/test_dict.cairo @@ -43,7 +43,7 @@ func test__dict_keys__should_return_keys{range_check_ptr}() { } func test__default_dict_copy__should_return_copied_dict{range_check_ptr}() { - let default_value = 0xdead; + let default_value = 0; let (dict_ptr_start) = default_dict_new(default_value); let dict_ptr = dict_ptr_start; let key = 0x7e1; diff --git a/cairo_zero/utils/dict.cairo b/cairo_zero/utils/dict.cairo index 573faed63..7ff06b7b2 100644 --- a/cairo_zero/utils/dict.cairo +++ b/cairo_zero/utils/dict.cairo @@ -1,5 +1,5 @@ from starkware.cairo.common.dict_access import DictAccess -from starkware.cairo.common.default_dict import default_dict_new +from starkware.cairo.common.default_dict import default_dict_new, default_dict_finalize from starkware.cairo.common.dict import dict_write, dict_squash from starkware.cairo.common.math_cmp import is_not_zero from starkware.cairo.common.alloc import alloc @@ -84,18 +84,11 @@ func default_dict_copy{range_check_ptr}(start: DictAccess*, end: DictAccess*) -> DictAccess*, DictAccess* ) { alloc_locals; - let (squashed_start, squashed_end) = dict_squash(start, end); + let (squashed_start, squashed_end) = default_dict_finalize(start, end, 0); local range_check_ptr = range_check_ptr; let dict_len = squashed_end - squashed_start; - local default_value; - if (dict_len == 0) { - assert default_value = 0; - } else { - assert default_value = squashed_start.prev_value; - } - - let (local new_start) = default_dict_new(default_value); + let (local new_start) = default_dict_new(0); let new_ptr = new_start; if (dict_len == 0) { @@ -110,11 +103,8 @@ func default_dict_copy{range_check_ptr}(start: DictAccess*, end: DictAccess*) -> let squashed_start = cast([ap - 3], DictAccess*); let dict_len = [ap - 2]; let new_ptr = cast([ap - 1], DictAccess*); - let default_value = [fp + 1]; let key = [squashed_start].key; - let prev_value = [squashed_start].prev_value; - assert prev_value = default_value; let new_value = [squashed_start].new_value; dict_write{dict_ptr=new_ptr}(key=key, new_value=new_value);