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

Add 0.11 changes #884

Merged
merged 40 commits into from
Apr 3, 2023
Merged

Add 0.11 changes #884

merged 40 commits into from
Apr 3, 2023

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Mar 9, 2023

This PR contains all the changes introduced by the 0.11 update.
PR list:
#875 Poseidon builtin
#890 Use starknet-crypto for poseidon
#876 ec_op changes
#873 Update keccak builtin
#874 Update layouts

fmoletta and others added 3 commits March 9, 2023 10:08
* Add instance def

* Add file

* Add poseidon instance def to builtin instance def

* Add Poseidon to BuiltinRunners

* Add simple tests program

* Prevent poseidon from being rejected by deserialize

* Use modified version of starknet-crypto poseidon hash (need permute fn to be public in order to access full state

* Add poseidon builtin impl + remove unreleased AddAssign usage

* Fix EOF

* Save a step

* Add comment before unwrap

* Clippy

* Reorder files

* Add comment

* Use constants for cells

* Add more test program

* Add integration tests

* test constant creation doesnt panic

* Add tests

* Fix failling tests

* Use final values for POSEIDON_COMP_CONSTANTS and move calculation to test module

* typo

* Solve post-merge conflicts

* Implement poseidon hints

* Add file

* Add tests for new hint

* Clippy

* Fix hint names

* Solve post-merge conflicts

* Add missing import
* ec_op changes 0.11 release cairo_lang

* Update src/vm/runners/builtin_runner/ec_op.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* remove rc and change bigint to felt

* debug cache

* debug cache

* change add_int implementation

* cargo fmt

---------

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
fmoletta and others added 16 commits March 10, 2023 14:52
* Add cache to keccak builtin

* Temporaryly unhide recursive layout for debugging

* Use same keccak method as the one used in keccak_utils

* Make keccak builtin work

* Fix visisbility

* Small refactor

* Refactor

* Refactor

* Add tests

* Fix address management

* Add test program

* Clippy + Update tests

* Remove unused import

* Remove uneeded Rc

* Make error less specific

* Add integration test

* Add proposed changes

* Re-hide recursive layout
* update layouts to cairo-lang 0.11 release

* update layout all

* update benches and makefile

* Add instance def

* Add file

* Add poseidon instance def to builtin instance def

* Add Poseidon to BuiltinRunners

* Add simple tests program

* Prevent poseidon from being rejected by deserialize

* Use modified version of starknet-crypto poseidon hash (need permute fn to be public in order to access full state

* Add poseidon builtin impl + remove unreleased AddAssign usage

* Fix EOF

* Save a step

* Add comment before unwrap

* Clippy

* Reorder files

* reset run_benchmark script

* Add comment

* Use constants for cells

* Add more test program

* Add integration tests

* test constant creation doesnt panic

* Add tests

* Fix failling tests

* Use final values for POSEIDON_COMP_CONSTANTS and move calculation to test module

* typo

* Solve post-merge conflicts

* Implement poseidon hints

* Add file

* Add tests for new hint

* Clippy

* allow dead code in default poseidon

* remove wrong text

* Update .github/workflows/rust.yml

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Update src/types/instance_definitions/poseidon_instance_def.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Update src/types/instance_definitions/poseidon_instance_def.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Update src/types/instance_definitions/builtins_instance_def.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Update src/types/instance_definitions/builtins_instance_def.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Update src/types/instance_definitions/builtins_instance_def.rs

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

---------

Co-authored-by: Federica <fedemoletta@hotmail.com>
Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
* Add cache to keccak builtin

* Temporaryly unhide recursive layout for debugging

* Use same keccak method as the one used in keccak_utils

* Make keccak builtin work

* Fix visisbility

* Small refactor

* Refactor

* Refactor

* Add tests

* Fix address management

* Add test program

* Clippy + Update tests

* Remove unused import

* Remove uneeded Rc

* Make error less specific

* Add integration test

* Add proposed changes

* Add new hints

* Add test program

* Move constants

* Add keccak hints;

* Fix overflowing operation

* Add more hints

* Add unit tests

* Add integration test

* Update import paths in cairo programs used for testing

* Update hints with new import paths

* Add newline at end of file

* Clippy

* Clean imports

* Re-hide recursive layout

* Update src/hint_processor/builtin_hint_processor/keccak_utils.rs

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>

* Add suggested change + fix conflicts

* Update src/hint_processor/builtin_hint_processor/keccak_utils.rs

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>

* Fix

* Use u64 in split_n_bytes hints

* Use starknet_with_keccak layout when running cairo-lang

* Fix relative path in compare_vm_state script

---------

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>
@fmoletta fmoletta marked this pull request as ready for review March 21, 2023 19:05
@fmoletta fmoletta marked this pull request as draft March 21, 2023 19:06
* Change instance def ratios to Option

* Move builtin runner ratios to option

* Modify methods to accomodate dynamic ratios

* Misc fixes

* Misc fixes

* Fix wrong impl

* Fix tests

* Fix tests

* Add dynamic layout

* Fix wrong impl

* Fix tests

* Expose instances_per_component

* Move get_used_cells_and_allocated_sizes to mod

* Move get_allocated_memory_units to mod

* Finnish prev tasks

* Fix test

* fix get_perm_range_check_limit

* Fix get_range_check_usage

* Fix test values
Comment on lines +69 to +95
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn run_n_greater_than_10_true() {
let hint_code = hint_code::NONDET_N_GREATER_THAN_10;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 21)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 1)];
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn run_n_greater_than_10_false() {
let hint_code = hint_code::NONDET_N_GREATER_THAN_10;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 9)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 0)];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test that n == 10 also tests as true.
Maybe just use some proptest for the value of n tho.

Comment on lines +97 to +123
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn run_n_greater_than_2_true() {
let hint_code = hint_code::NONDET_N_GREATER_THAN_2;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 6)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 1)];
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn run_n_greater_than_2_false() {
let hint_code = hint_code::NONDET_N_GREATER_THAN_2;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 1)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 0)];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for 2.

.map(|x| Felt252::from(*x).into()));
let input_message: Vec<u8> = input_felts
.iter()
.flat_map(|x| Self::right_pad(&x.to_biguint().to_bytes_le(), KECCAK_FELT_BYTE_SIZE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging #927 this can become:

Suggested change
.flat_map(|x| Self::right_pad(&x.to_biguint().to_bytes_le(), KECCAK_FELT_BYTE_SIZE))
.flat_map(|x| &x.to_le_bytes()[..KECCAK_FELT_BYTE_SIZE])

@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #884 (d7c13c4) into main (cdb5125) will increase coverage by 0.28%.
The diff coverage is 98.19%.

@@            Coverage Diff             @@
##             main     #884      +/-   ##
==========================================
+ Coverage   97.45%   97.74%   +0.28%     
==========================================
  Files          70       74       +4     
  Lines       29161    30334    +1173     
==========================================
+ Hits        28418    29649    +1231     
+ Misses        743      685      -58     
Impacted Files Coverage Δ
src/serde/deserialize_program.rs 97.49% <0.00%> (-0.10%) ⬇️
src/utils.rs 99.43% <ø> (ø)
src/vm/runners/builtin_runner/output.rs 97.16% <ø> (-0.07%) ⬇️
src/vm/runners/builtin_runner/bitwise.rs 96.10% <81.81%> (+2.75%) ⬆️
src/vm/runners/builtin_runner/mod.rs 99.28% <95.60%> (-0.03%) ⬇️
src/vm/security.rs 98.06% <96.00%> (-0.37%) ⬇️
src/vm/runners/builtin_runner/hash.rs 98.51% <96.15%> (+3.30%) ⬆️
src/vm/runners/builtin_runner/poseidon.rs 97.47% <97.47%> (ø)
src/vm/runners/builtin_runner/segment_arena.rs 97.52% <97.52%> (ø)
src/vm/runners/cairo_runner.rs 97.90% <98.47%> (+0.11%) ⬆️
... and 22 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

fmoletta and others added 8 commits March 31, 2023 17:03
* Change instance def ratios to Option

* Move builtin runner ratios to option

* Modify methods to accomodate dynamic ratios

* Misc fixes

* Misc fixes

* Fix wrong impl

* Fix tests

* Fix tests

* Add dynamic layout

* Fix wrong impl

* Fix tests

* Expose instances_per_component

* Move get_used_cells_and_allocated_sizes to mod

* Move get_allocated_memory_units to mod

* Finnish prev tasks

* Fix test

* Initial progress

* Add builtin specific methods

* Add SegmentArenaBuiltinRunner to BuiltinRunner enum

* implement final_stack for segmen arena nuiltin runner

* Add other methods

* Integrate into runner

* Remove error from initialize_segments

* Fix comment

* Add test

* Add tests for segment arena builtin

* Fix

* fix get_perm_range_check_limit

* Fix get_range_check_usage

* Fix test values

* expose program base for starknet reasons

* Update src/vm/runners/builtin_runner/mod.rs

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>

* Fix build

* Add nostd Vec import

* Fix wasm import

---------

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>
Co-authored-by: Mario Rugiero <mrugiero@gmail.com>
…from_entrypoint` (#928)

* Change instance def ratios to Option

* Move builtin runner ratios to option

* Modify methods to accomodate dynamic ratios

* Misc fixes

* Misc fixes

* Fix wrong impl

* Fix tests

* Fix tests

* Add dynamic layout

* Fix wrong impl

* Fix tests

* Expose instances_per_component

* Move get_used_cells_and_allocated_sizes to mod

* Move get_allocated_memory_units to mod

* Finnish prev tasks

* Fix test

* Initial progress

* Add builtin specific methods

* Add SegmentArenaBuiltinRunner to BuiltinRunner enum

* implement final_stack for segmen arena nuiltin runner

* Add other methods

* Integrate into runner

* Remove error from initialize_segments

* Fix comment

* Add test

* Add tests for segment arena builtin

* Fix

* fix get_perm_range_check_limit

* Fix get_range_check_usage

* Fix test values

* expose program base for starknet reasons

* Update src/vm/runners/builtin_runner/mod.rs

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>

* Add optional program_size argument to verify_secure_runner & run_from_entrypoint

* Fix build

* Add nostd Vec import

* Fix wasm import

* Expose get_segment_size (#934)

---------

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>
Co-authored-by: Mario Rugiero <mrugiero@gmail.com>
@fmoletta fmoletta marked this pull request as ready for review April 3, 2023 17:03
Copy link
Contributor

@Oppen Oppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK. Just cover the lines reported by codecov and a benchmark program for Poseidon would be greatly appreciated.

src/vm/security.rs Outdated Show resolved Hide resolved
@Oppen Oppen added this pull request to the merge queue Apr 3, 2023
Merged via the queue into main with commit 1fb4a72 Apr 3, 2023
@Oppen Oppen deleted the 0.11 branch April 3, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants