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

Commit

Permalink
[KGA-39] fix: default_dict_copy finalize with default value 0 (#1592)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- 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. -->

Use `default_dict_finalize` with 0

<!-- 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/1592)
<!-- Reviewable:end -->
  • Loading branch information
obatirou authored Nov 9, 2024
1 parent f87b89e commit 474951c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions blockchain-tests-skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cairo_zero/tests/src/utils/test_dict.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 3 additions & 13 deletions cairo_zero/utils/dict.cairo
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 474951c

Please sign in to comment.