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

Fix modulo builtin constraints #1841

Merged
merged 81 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7d14e74
Fix Zero segment location.
Alon-Ti Jun 24, 2024
e71b052
Fixed has_zero_segment naming
yuvalsw Aug 13, 2024
0ec972a
Fix prover input.
Alon-Ti Jun 30, 2024
8c5c924
Fixed version reading when no version is supplied
yuvalsw Jul 7, 2024
057bc6f
Added change to changelog.
yuvalsw Aug 13, 2024
64c844b
fix test_from_serializable()
OmriEshhar1 Aug 21, 2024
51d25a7
fix panic_impl error
OmriEshhar1 Aug 25, 2024
88d1da1
fix cairo version
OmriEshhar1 Aug 26, 2024
c5d3bd5
Add dummy changelog
JulianGCalderon Aug 26, 2024
ea377a8
Pin wasm-bindgen
JulianGCalderon Aug 26, 2024
e8e7bb3
Register change in CHANGELOG
JulianGCalderon Aug 26, 2024
87a736a
Update Cargo.lock
JulianGCalderon Aug 26, 2024
2fe7f90
Remove changes from CHANGELOG
JulianGCalderon Aug 26, 2024
6c7237e
Add argument parsing for layout params file
JulianGCalderon Aug 23, 2024
e4b162b
Add dynamic support (no implement)
JulianGCalderon Aug 23, 2024
43360b9
Add cairo_layout_params_file.example.json
JulianGCalderon Aug 23, 2024
e3e31b8
Implement dynamic layout creation
JulianGCalderon Aug 23, 2024
ad97bd0
Update CHANGELOG
JulianGCalderon Aug 23, 2024
11edca3
Add cli dynamic support for cairo 1
JulianGCalderon Aug 23, 2024
adbba88
Make wasm compatible
JulianGCalderon Aug 23, 2024
8ac5b5b
Merge remote-tracking branch 'lambdaclass-cairo-vm/main' into yuval/f…
OmriEshhar1 Aug 28, 2024
a41f231
Use public_memory_fraction = 4 vy default
JulianGCalderon Aug 28, 2024
f7334f5
Deserialize bool from int
JulianGCalderon Aug 28, 2024
63eba32
Add comparison with python-vm (failing)
JulianGCalderon Aug 28, 2024
3d18e47
Merge remote-tracking branch 'lambdaclass-cairo-vm/main' into yuval/f…
OmriEshhar1 Aug 29, 2024
1f2098a
Rebuild .rs files in makefile
JulianGCalderon Aug 29, 2024
707e0d2
Use 8 as dynamic public_memory_fraction
JulianGCalderon Aug 29, 2024
723eaf2
Use None ratio for dynamic unused builtins
JulianGCalderon Aug 29, 2024
f20b97b
Add rangecheck96 to private inputs
JulianGCalderon Aug 29, 2024
e6d3f9b
Make dyn py files depend on params_file
JulianGCalderon Aug 29, 2024
3f5eef5
Use cpu_component_step=1 by default
JulianGCalderon Aug 29, 2024
026e459
Fix typo in private inputs
JulianGCalderon Aug 29, 2024
15b7742
Add range check value to air private input test
JulianGCalderon Aug 30, 2024
698b35c
Fix zero segment location
JulianGCalderon Aug 30, 2024
c58dc4e
Use zero builtin instead of None
JulianGCalderon Aug 30, 2024
ce985ba
Add debug scripts
JulianGCalderon Aug 30, 2024
6ea8ddf
Merge branch 'main' into dynamic-layout
JulianGCalderon Sep 2, 2024
08874bd
Remove dup makefile recipes
JulianGCalderon Sep 2, 2024
ba4d3c0
remove outdated test
JulianGCalderon Sep 2, 2024
0e0c65b
Enable ensure-no_std on test
JulianGCalderon Sep 2, 2024
0b9fed5
Fix tests
JulianGCalderon Sep 2, 2024
737850f
Add correct test
JulianGCalderon Sep 2, 2024
34e5eaf
Rename tset
JulianGCalderon Sep 3, 2024
2a4213f
Add comment
JulianGCalderon Sep 3, 2024
28eb15c
Add debugging document
JulianGCalderon Sep 3, 2024
20ce2aa
Update cairo layout params file
JulianGCalderon Sep 3, 2024
0036504
Merge branch 'fix-for-sw-fix-version' into dynamic-layout
JulianGCalderon Sep 3, 2024
30f7766
Merge branch 'main' into dynamic-layout
JulianGCalderon Sep 3, 2024
af9fadd
Remove duplicated range check
JulianGCalderon Sep 3, 2024
fbf074d
Remove dup
JulianGCalderon Sep 3, 2024
f8a7f78
Merge branch 'main' into dynamic-layout
JulianGCalderon Sep 4, 2024
f94ae2b
Merge branch 'main' into dynamic-layout
JulianGCalderon Sep 17, 2024
050c71a
Remove debugging and scrippts (moveed to another branch)
JulianGCalderon Sep 17, 2024
3f9e684
Add comment
JulianGCalderon Sep 17, 2024
fca3cbf
Add tests
JulianGCalderon Sep 18, 2024
eb63b5c
Add dynamic test to cairo-vm-cli
JulianGCalderon Sep 18, 2024
a6f1511
Add parse test
JulianGCalderon Sep 18, 2024
f2c0abb
Remove compare all dynamic
JulianGCalderon Sep 18, 2024
5b6868e
Add script for comparing with dynamic layouts
JulianGCalderon Sep 18, 2024
cdab848
Add tests to workflow
JulianGCalderon Sep 18, 2024
2015055
Delete logic changes
JulianGCalderon Sep 18, 2024
c46ed76
Delete more logic changes
JulianGCalderon Sep 18, 2024
7a44d4e
Update rust.yml
JulianGCalderon Sep 19, 2024
859b7fb
Rename compare_outputs_dynamic_layout.sh to compare_outputs_dynamic_l…
JulianGCalderon Sep 19, 2024
47e441b
Update test script
JulianGCalderon Sep 19, 2024
6ecdf3d
Enforce prover constraints in add, sub, and mul
JulianGCalderon Sep 19, 2024
2630845
Remove debug prints
JulianGCalderon Sep 19, 2024
fa384fb
Add tests
JulianGCalderon Sep 19, 2024
6991904
Update CHANGELOG.md
JulianGCalderon Sep 19, 2024
deab241
Fix serialization
JulianGCalderon Sep 19, 2024
9db796a
Comment failing test
JulianGCalderon Sep 19, 2024
dd6d6ff
Uncomment test
JulianGCalderon Sep 19, 2024
9202255
Fix tests
JulianGCalderon Sep 19, 2024
7346f80
Remove operation struct and use builtin type instead
JulianGCalderon Sep 20, 2024
399c14c
Add unit tests to modulo builtin operations
JulianGCalderon Sep 20, 2024
43c2d41
Fix security error message
JulianGCalderon Sep 20, 2024
6435a77
Test custom serde impl
JulianGCalderon Sep 23, 2024
80916e6
Upload mod_builtin coverage
JulianGCalderon Sep 23, 2024
9bbfc36
Merge branch 'main' into dynamic-layout
JulianGCalderon Sep 23, 2024
a913599
Merge branch 'dynamic-layout' into mod-builtin-fix
JulianGCalderon Sep 23, 2024
bcd5b31
Merge branch 'main' into mod-builtin-fix
JulianGCalderon Sep 30, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/rust.yml
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,36 @@ jobs:
key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }}
fail-on-cache-miss: true

- name: Fetch results for tests with stdlib (w/mod_builtin; part. 1)
uses: actions/cache/restore@v3
with:
path: lcov-test#1-mod_builtin.info
key: codecov-cache-test#1-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/mod_builtin; part. 2)
uses: actions/cache/restore@v3
with:
path: lcov-test#2-mod_builtin.info
key: codecov-cache-test#2-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/mod_builtin; part. 3)
uses: actions/cache/restore@v3
with:
path: lcov-test#3-mod_builtin.info
key: codecov-cache-test#3-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/mod_builtin; part. 4)
uses: actions/cache/restore@v3
with:
path: lcov-test#4-mod_builtin.info
key: codecov-cache-test#4-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests without stdlib (w/mod_builtin)
uses: actions/cache/restore@v3
with:
path: lcov-no_std-mod_builtin.info
key: codecov-cache-test-no_std-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#### Upcoming Changes

* fix: [#1841](https://github.com/lambdaclass/cairo-vm/pull/1841):
* Fix modulo builtin to comply with prover constraints

* feat(BREAKING): [#1824](https://github.com/lambdaclass/cairo-vm/pull/1824):
* Add support for dynamic layout
* CLI change(BREAKING): The flag `cairo_layout_params_file` must be specified when using dynamic layout.
Expand Down
84 changes: 84 additions & 0 deletions vm/src/air_private_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub struct ModInputInstance {
pub values_ptr: usize,
pub offsets_ptr: usize,
pub n: usize,
#[serde(deserialize_with = "mod_input_instance_batch_serde::deserialize")]
#[serde(serialize_with = "mod_input_instance_batch_serde::serialize")]
pub batch: BTreeMap<usize, ModInputMemoryVars>,
}

Expand Down Expand Up @@ -205,6 +207,88 @@ impl AirPrivateInputSerializable {
}
}

mod mod_input_instance_batch_serde {
use super::*;

use serde::{Deserializer, Serializer};

pub(crate) fn serialize<S: Serializer>(
value: &BTreeMap<usize, ModInputMemoryVars>,
s: S,
) -> Result<S::Ok, S::Error> {
let value = value.iter().map(|v| v.1).collect::<Vec<_>>();

value.serialize(s)
}

pub(crate) fn deserialize<'de, D: Deserializer<'de>>(
d: D,
) -> Result<BTreeMap<usize, ModInputMemoryVars>, D::Error> {
let value = Vec::<ModInputMemoryVars>::deserialize(d)?;

Ok(value.into_iter().enumerate().collect())
}

#[cfg(feature = "std")]
#[test]
fn test_serde() {
let input_value = vec![
(
0,
ModInputMemoryVars {
a_offset: 5,
b_offset: 5,
c_offset: 5,
a0: Felt252::from(5u32),
a1: Felt252::from(5u32),
a2: Felt252::from(5u32),
a3: Felt252::from(5u32),
b0: Felt252::from(5u32),
b1: Felt252::from(5u32),
b2: Felt252::from(5u32),
b3: Felt252::from(5u32),
c0: Felt252::from(5u32),
c1: Felt252::from(5u32),
c2: Felt252::from(5u32),
c3: Felt252::from(5u32),
},
),
(
1,
ModInputMemoryVars {
a_offset: 7,
b_offset: 7,
c_offset: 7,
a0: Felt252::from(7u32),
a1: Felt252::from(7u32),
a2: Felt252::from(7u32),
a3: Felt252::from(7u32),
b0: Felt252::from(7u32),
b1: Felt252::from(7u32),
b2: Felt252::from(7u32),
b3: Felt252::from(7u32),
c0: Felt252::from(7u32),
c1: Felt252::from(7u32),
c2: Felt252::from(7u32),
c3: Felt252::from(7u32),
},
),
]
.into_iter()
.collect::<BTreeMap<usize, _>>();

let bytes = Vec::new();
let mut serializer = serde_json::Serializer::new(bytes);
serialize(&input_value, &mut serializer).unwrap();
let bytes = serializer.into_inner();

let mut deserializer = serde_json::Deserializer::from_slice(&bytes);
let output_value = deserialize(&mut deserializer).unwrap();

assert_eq!(input_value, output_value);
}
}

#[cfg(test)]
mod tests {
use crate::types::layout_name::LayoutName;
Expand Down
3 changes: 3 additions & 0 deletions vm/src/tests/compare_outputs_dynamic_layouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ CASES=(
"cairo_programs/proof_programs/sha256.json;double_all_cairo"
"cairo_programs/proof_programs/keccak.json;all_cairo"
"cairo_programs/proof_programs/keccak.json;double_all_cairo"
"cairo_programs/mod_builtin_feature/proof/mod_builtin.json;all_cairo"
"cairo_programs/mod_builtin_feature/proof/mod_builtin_failure.json;all_cairo"
"cairo_programs/mod_builtin_feature/proof/apply_poly.json;all_cairo"
)

passed_tests=0
Expand Down
Loading
Loading