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

Bump cairo_lang to 0.13.1 in testing env #1687

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: Bump cairo_lang to 0.13.1 in testing env [#1687](https://github.com/lambdaclass/cairo-vm/pull/1687)

* feat(BREAKING): Use return type info from sierra when serializing return values in cairo1-run crate [#1665](https://github.com/lambdaclass/cairo-vm/pull/1665)
* Removed public function `serialize_output`.
* Add field `serialize_output` to `Cairo1RunConfig`.
Expand Down
12 changes: 6 additions & 6 deletions cairo_programs/secp.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%builtins range_check
from starkware.cairo.common.cairo_secp.bigint import nondet_bigint3, BigInt3, bigint_to_uint256

from starkware.cairo.common.cairo_secp.bigint3 import BigInt3, SumBigInt3
from starkware.cairo.common.cairo_secp.bigint import nondet_bigint3, bigint_to_uint256
from starkware.cairo.common.cairo_secp.field import verify_zero, UnreducedBigInt3, reduce, is_zero

func main{range_check_ptr: felt}() {
Expand Down Expand Up @@ -43,17 +43,17 @@ func main{range_check_ptr: felt}() {
);

// is_zero
let (u) = is_zero(BigInt3(0, 0, 0));
let (u) = is_zero(SumBigInt3(0, 0, 0));
assert u = 1;
let (v) = is_zero(
BigInt3(232113757366008801543585, 232113757366008801543585, 232113757366008801543585)
SumBigInt3(232113757366008801543585, 232113757366008801543585, 232113757366008801543585)
);
assert v = 0;

let (w) = is_zero(BigInt3(-10, -10, -10));
let (w) = is_zero(SumBigInt3(-10, -10, -10));
assert w = 0;

let (z) = is_zero(BigInt3(1833312543, 67523423, 8790312));
let (z) = is_zero(SumBigInt3(1833312543, 67523423, 8790312));
assert z = 0;

return ();
Expand Down
4 changes: 2 additions & 2 deletions cairo_programs/secp_integration_tests.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%builtins range_check

from starkware.cairo.common.cairo_secp.bigint import (
BigInt3,
bigint_mul,
nondet_bigint3,
bigint_to_uint256,
uint256_to_bigint,
)
from starkware.cairo.common.cairo_secp.bigint3 import BigInt3, SumBigInt3
from starkware.cairo.common.cairo_secp.signature import (
get_generator_point,
validate_signature_entry,
Expand Down Expand Up @@ -86,7 +86,7 @@ func test_operations{range_check_ptr}(point: EcPoint) {
let (zero_uint, _) = uint256_add(slope_uint, neg_slope);
let (zero) = uint256_to_bigint(zero_uint);

let (is_z) = is_zero(zero);
let (is_z) = is_zero(SumBigInt3(d0=zero.d0, d1=zero.d1, d2=zero.d2));
assert is_z = 1;

let (pow2, scaled) = ec_mul_inner(point, 0, 0);
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ecdsa==0.18.0
bitarray==2.7.3
fastecdsa==2.2.3
fastecdsa==2.3.0
sympy==1.11.1
typeguard==2.13.3
cairo-lang==0.12.2
cairo-lang==0.13.1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::{
math_utils::*,
memcpy_hint_utils::{add_segment, enter_scope, exit_scope, memcpy_enter_scope},
memset_utils::{memset_enter_scope, memset_step_loop},
poseidon_utils::{n_greater_than_10, n_greater_than_2},
poseidon_utils::{elements_over_x, n_greater_than_10, n_greater_than_2},
pow_utils::pow,
secp::{
bigint_utils::{bigint_to_uint256, hi_max_bitlen, nondet_bigint3},
Expand Down Expand Up @@ -731,6 +731,12 @@ impl HintProcessorLogic for BuiltinHintProcessor {
hint_code::NONDET_N_GREATER_THAN_2 => {
n_greater_than_2(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::NONDET_ELEMENTS_OVER_TEN => {
elements_over_x(vm, &hint_data.ids_data, &hint_data.ap_tracking, 10)
}
hint_code::NONDET_ELEMENTS_OVER_TWO => {
elements_over_x(vm, &hint_data.ids_data, &hint_data.ap_tracking, 2)
}
hint_code::RANDOM_EC_POINT => {
random_ec_point_hint(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
Expand Down
5 changes: 5 additions & 0 deletions vm/src/hint_processor/builtin_hint_processor/hint_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,8 @@ data = __dict_manager.get_dict(ids.dict_ptr)
print(
{k: v if isinstance(v, int) else [memory[v + i] for i in range(ids.pointer_size)] for k, v in data.items()}
)"#;

pub const NONDET_ELEMENTS_OVER_TEN: &str =
"memory[ap] = to_felt_or_relocatable(ids.elements_end - ids.elements >= 10)";
pub const NONDET_ELEMENTS_OVER_TWO: &str =
"memory[ap] = to_felt_or_relocatable(ids.elements_end - ids.elements >= 2)";
15 changes: 14 additions & 1 deletion vm/src/hint_processor/builtin_hint_processor/poseidon_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};

use super::hint_utils::{get_integer_from_var_name, insert_value_into_ap};
use super::hint_utils::{get_integer_from_var_name, get_ptr_from_var_name, insert_value_into_ap};
use num_traits::ToPrimitive;

// Implements hint: "memory[ap] = to_felt_or_relocatable(ids.n >= 10)"
Expand Down Expand Up @@ -37,6 +37,19 @@ pub fn n_greater_than_2(
insert_value_into_ap(vm, value)
}

// Implements hint: "memory[ap] = to_felt_or_relocatable(ids.elements_end - ids.elements >= x)"
pub fn elements_over_x(
vm: &mut VirtualMachine,
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
x: usize,
) -> Result<(), HintError> {
let elements_end = get_ptr_from_var_name("elements_end", vm, ids_data, ap_tracking)?;
let elements = get_ptr_from_var_name("elements", vm, ids_data, ap_tracking)?;
let value = Felt252::from(((elements_end - elements)? >= x) as usize);
insert_value_into_ap(vm, value)
}

#[cfg(test)]
mod tests {
use crate::any_box;
Expand Down
6 changes: 3 additions & 3 deletions vm/src/types/instance_definitions/builtins_instance_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ impl BuiltinsInstanceDef {
pub(crate) fn recursive_large_output() -> BuiltinsInstanceDef {
BuiltinsInstanceDef {
output: true,
pedersen: Some(PedersenInstanceDef::new(Some(32), 1)),
pedersen: Some(PedersenInstanceDef::new(Some(128), 1)),
range_check: Some(RangeCheckInstanceDef::default()),
ecdsa: None,
bitwise: Some(BitwiseInstanceDef::new(Some(8))),
ec_op: None,
keccak: None,
poseidon: None,
poseidon: Some(PoseidonInstanceDef::new(Some(8))),
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ mod tests {
assert!(builtins.bitwise.is_some());
assert!(builtins.ec_op.is_none());
assert!(builtins.keccak.is_none());
assert!(builtins.poseidon.is_none());
assert!(builtins.poseidon.is_some());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions vm/src/types/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl CairoLayout {
_public_memory_fraction: 8,
_memory_units_per_step: 8,
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::default()),
_n_trace_colums: 13,
_n_trace_colums: 12,
_cpu_instance_def: CpuInstanceDef::default(),
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ mod tests {
layout.diluted_pool_instance_def,
Some(DilutedPoolInstanceDef::default())
);
assert_eq!(layout._n_trace_colums, 13);
assert_eq!(layout._n_trace_colums, 12);
assert_eq!(layout._cpu_instance_def, CpuInstanceDef::default());
}

Expand Down
Loading