Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the Dictionary used in dict hints to store MaybeRelocatable instead of BigInt #687

Merged
merged 73 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c47e701
Start get_traceback_entries + add convenience methos
fmoletta Dec 22, 2022
51219ca
Add fn is_call_instruction
fmoletta Dec 22, 2022
3b276db
add code
fmoletta Dec 22, 2022
05f0bdd
Merge branch 'main' of github.com:lambdaclass/cairo-rs into traceback
fmoletta Dec 22, 2022
c89eb3f
Refactor code
fmoletta Dec 22, 2022
f02db3e
Clippy
fmoletta Dec 22, 2022
05813bd
Add get_traceback method
fmoletta Dec 22, 2022
58992c3
Fix get_error_attr_value
fmoletta Dec 22, 2022
b381624
Add traceback to VmException
fmoletta Dec 22, 2022
936eadc
Make traceback non-optional
fmoletta Dec 22, 2022
e72dff5
Add tests for is_call_instruction
fmoletta Dec 22, 2022
93eae26
Add traceback to error display
fmoletta Dec 22, 2022
67ccc39
Add test + fix logic for get_traceback_entries
fmoletta Dec 22, 2022
ba410b0
Code refactor
fmoletta Dec 22, 2022
acf3299
Add one more test for get_traceback_entries
fmoletta Dec 22, 2022
bc66d0f
Fix string format + add test for get_traceback
fmoletta Dec 22, 2022
b3952cb
Improve fn
fmoletta Dec 27, 2022
c2fa8a0
Add reference to is_call_instruction signature
fmoletta Dec 27, 2022
88e4b52
Add reference to immediate in decode_instruction + remove clone
fmoletta Dec 27, 2022
7a03cec
Merge branch 'main' of github.com:lambdaclass/cairo-rs into traceback
fmoletta Dec 27, 2022
371dc43
Fix hint_processor mutability in tests
fmoletta Dec 27, 2022
46a7202
Add Location::get_location_marks
fmoletta Dec 27, 2022
fd0b9c6
Fix method to_string_with_contents
fmoletta Dec 27, 2022
5e753bb
Fix string format
fmoletta Dec 27, 2022
09ee596
Fix string format
fmoletta Dec 28, 2022
9eac613
Update traceback tests
fmoletta Dec 28, 2022
3612b01
Add tests for Location::to_string_with_contents()
fmoletta Dec 28, 2022
f56122d
Fix intermediate string format
fmoletta Dec 28, 2022
00ccd31
Fix test
fmoletta Dec 28, 2022
2ed2287
Add tests for Location::get_location_marks()
fmoletta Dec 28, 2022
839cbf1
Update VmException display
fmoletta Dec 28, 2022
8937c87
Fix string format
fmoletta Dec 28, 2022
747bb77
Fix string format
fmoletta Dec 28, 2022
1dbe083
Merge branch 'main' of github.com:lambdaclass/cairo-rs into input_fil…
fmoletta Dec 28, 2022
5f78c47
Remove debug print
fmoletta Dec 28, 2022
542e06e
Fix Display
fmoletta Dec 28, 2022
d33f6e1
Implement Display for MaybeRelocatable
fmoletta Dec 28, 2022
2fdef4a
Add real-case test for VmException Display
fmoletta Dec 28, 2022
9845fc5
Remove debug format from erros containing MaybeRelocatable and Reloca…
fmoletta Dec 28, 2022
8b1e11c
Add tests for display implementation
fmoletta Dec 28, 2022
f46e49a
Update Changelog
fmoletta Dec 28, 2022
e9ecfe4
Clippy
fmoletta Dec 28, 2022
40d06cb
Remove unnecessary &
fmoletta Dec 29, 2022
c7b5cfe
Add hint location to InstructionLocation
fmoletta Dec 29, 2022
160fe32
Use InstructionLocation instead of Location in insruction_locations f…
fmoletta Dec 29, 2022
bd6111a
Add hint location logic to get_location
fmoletta Dec 29, 2022
a9045fa
Add rought version of VirtualMachineError::Hint
fmoletta Dec 29, 2022
085d6eb
Add test for error display on HintError
fmoletta Dec 29, 2022
2909f1b
Add test for get_location with hint_index
fmoletta Dec 29, 2022
5542e3f
Start refactor
fmoletta Dec 29, 2022
4a9e6dd
Update changelog
fmoletta Dec 29, 2022
7f6e049
Merge branch 'hint-location' into hint-error
fmoletta Dec 29, 2022
68f7384
Finnish changing hint fns to HintError
fmoletta Dec 29, 2022
94aa1f1
Update custom hint example
fmoletta Dec 29, 2022
c683b6d
Fix changelog format
fmoletta Dec 29, 2022
31fdb1e
Add changelog entry for this PR
fmoletta Dec 29, 2022
3695a11
Merge branch 'hint-location' into hint-error
fmoletta Dec 29, 2022
6b142e7
Merge branch 'main' of github.com:lambdaclass/cairo-rs into hint-error
fmoletta Jan 2, 2023
d17c74d
Merge branch 'main' of github.com:lambdaclass/cairo-rs into hint-error
fmoletta Jan 3, 2023
3a9266a
Add non-typed helpers for ids variables
fmoletta Jan 4, 2023
6555822
Swap BigInt for MaybeRelocatable in Dictionary
fmoletta Jan 4, 2023
e76a541
Merge branch 'main' of github.com:lambdaclass/cairo-rs into maybe-rel…
fmoletta Jan 4, 2023
9d62363
Update dict_hint_utils + dict macros in test_utils
fmoletta Jan 4, 2023
c8b514c
Fix tests
fmoletta Jan 4, 2023
29785c2
Clippy
fmoletta Jan 4, 2023
ee751fa
Add test for dict_write with relocatable
fmoletta Jan 4, 2023
510ae02
Add tests on hint_utils.rs
fmoletta Jan 4, 2023
6988b57
Add tetss on hint_processor_utils.rs
fmoletta Jan 4, 2023
3946f98
Add integration test for bug case
fmoletta Jan 4, 2023
68a4265
Update changelog
fmoletta Jan 4, 2023
a8c52bb
Merge branch 'main' of github.com:lambdaclass/cairo-rs into maybe-rel…
fmoletta Jan 6, 2023
0b34376
Fix eof
fmoletta Jan 6, 2023
04b2003
Remove debug print
fmoletta Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
* Add new error type `HintError` [#676](https://github.com/lambdaclass/cairo-rs/pull/676)
* Public Api changes:
* `HintProcessor::execute_hint()` now returns a `HintError` instead of a `VirtualMachineError`
* helper functions on `hint_processor_utils.rs` now return a `HintError`
* Helper functions on `hint_processor_utils.rs` now return a `HintError`

* Change the Dictionary used in dict hints to store MaybeRelocatable instead of BigInt [#687](https://github.com/lambdaclass/cairo-rs/pull/687)
* Public Api changes:
* `DictManager`, its dictionaries, and all dict module hints implemented in rust now use `MaybeRelocatable` for keys and values instead of `BigInt`
* Add helper functions that allow extracting ids variables as `MaybeRelocatable`: `get_maybe_relocatable_from_var_name` & `get_maybe_relocatable_from_reference`
* Change inner value type of dict-related `HintError` variants to `MaybeRelocatable`
40 changes: 40 additions & 0 deletions cairo_programs/dict_store_cast_ptr.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from starkware.cairo.common.dict_access import DictAccess
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.default_dict import default_dict_new
from starkware.cairo.common.dict import dict_write, dict_read

struct Structure {
a: felt,
b: felt,
c: felt,
}

func main() {
// Create dictionary
let (dictionary: DictAccess*) = default_dict_new(default_value=0);
// Create & initialize struct_pointer
let (struct_ptr: Structure*) = alloc();
assert struct_ptr[0] = Structure(1, 2, 3);
// Cast ptr to felt and store it in the dictionary
tempvar struct_ptr_cast_felt = cast(struct_ptr, felt);
dict_write{dict_ptr=dictionary}(key=0, new_value=struct_ptr_cast_felt);
// Read the casted ptr from the dictionary and compare it to the one we stored
let read_struct_ptr_cast_felt: felt = dict_read{dict_ptr=dictionary}(key=0);
assert struct_ptr_cast_felt = read_struct_ptr_cast_felt;
// Cast he ptr back to Structure* and check its value
let read_struct_ptr_cast_struct_ptr = cast(read_struct_ptr_cast_felt, Structure*);
assert struct_ptr = read_struct_ptr_cast_struct_ptr;
// Confirm that the ptr still leads to the data we initialized
assert read_struct_ptr_cast_struct_ptr[0].a = 1;
assert read_struct_ptr_cast_struct_ptr[0].b = 2;
assert read_struct_ptr_cast_struct_ptr[0].c = 3;
// Now we do the same, but we read the struct_ptr from the dictionary as a Struct*
// without an explicit cast
let read_struct_ptr: Structure* = dict_read{dict_ptr=dictionary}(key=0);
assert struct_ptr = read_struct_ptr;
// Confirm that the ptr still leads to the data we initialized
assert read_struct_ptr[0].a = 1;
assert read_struct_ptr[0].b = 2;
assert read_struct_ptr[0].c = 3;
return ();
}
Loading