Skip to content

Commit

Permalink
Merge branch 'main' into 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Mar 27, 2023
2 parents 30e39b4 + 6e5340a commit d180881
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 1,011 deletions.
9 changes: 3 additions & 6 deletions bench/run_benchmarks.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env sh
tests_path="../cairo_programs/benchmarks"
tests_path="cairo_programs/benchmarks"

set -e

for file in $(ls $tests_path | grep .cairo | sed -E 's/\.cairo//'); do
echo "Running $file benchmark"

export PATH="$(pyenv root)/shims:$PATH"

hyperfine \
-n "Cairo VM (CPython)" "PYENV_VERSION=3.7.12 cairo-run --layout all --program $tests_path/$file.json" \
-n "Cairo VM (PyPy)" "PYENV_VERSION=pypy3.7-7.3.9 cairo-run --layout all --program $tests_path/$file.json" \
-n "cairo-rs (Rust)" "../target/release/cairo-vm-cli $tests_path/$file.json --layout all"
-n "cairo-rs (MAIN)" "target/release/cairo-vm-cli-main $tests_path/$file.json --layout all"\
-n "cairo-rs (NO_NAME)" "target/release/cairo-vm-cli $tests_path/$file.json --layout all"
done
4 changes: 2 additions & 2 deletions felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ pub(crate) trait FeltOps {
#[macro_export]
macro_rules! felt_str {
($val: expr) => {
felt::Felt252::parse_bytes($val.as_bytes(), 10_u32).expect("Couldn't parse bytes")
$crate::Felt252::parse_bytes($val.as_bytes(), 10_u32).expect("Couldn't parse bytes")
};
($val: expr, $opt: expr) => {
felt::Felt252::parse_bytes($val.as_bytes(), $opt as u32).expect("Couldn't parse bytes")
$crate::Felt252::parse_bytes($val.as_bytes(), $opt as u32).expect("Couldn't parse bytes")
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,13 @@ impl HintProcessor for BuiltinHintProcessor {
hint_code::BLAKE2S_COMPUTE => {
compute_blake2s(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::VERIFY_ZERO => {
verify_zero(vm, &hint_data.ids_data, &hint_data.ap_tracking, constants)
hint_code::VERIFY_ZERO => verify_zero(vm, &hint_data.ids_data, &hint_data.ap_tracking),
hint_code::NONDET_BIGINT3 => {
nondet_bigint3(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::REDUCE => {
reduce(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::NONDET_BIGINT3 => nondet_bigint3(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::REDUCE => reduce(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::BLAKE2S_FINALIZE => {
finalize_blake2s(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
Expand Down Expand Up @@ -338,61 +328,38 @@ impl HintProcessor for BuiltinHintProcessor {
hint_code::BIGINT_TO_UINT256 => {
bigint_to_uint256(vm, &hint_data.ids_data, &hint_data.ap_tracking, constants)
}
hint_code::IS_ZERO_PACK => is_zero_pack(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::IS_ZERO_NONDET => is_zero_nondet(vm, exec_scopes),
hint_code::IS_ZERO_ASSIGN_SCOPE_VARS => {
is_zero_assign_scope_variables(exec_scopes, constants)
hint_code::IS_ZERO_PACK => {
is_zero_pack(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::IS_ZERO_NONDET => is_zero_nondet(vm, exec_scopes),
hint_code::IS_ZERO_ASSIGN_SCOPE_VARS => is_zero_assign_scope_variables(exec_scopes),
hint_code::DIV_MOD_N_PACKED_DIVMOD => div_mod_n_packed_divmod(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::DIV_MOD_N_SAFE_DIV => div_mod_n_safe_div(exec_scopes, constants),
hint_code::DIV_MOD_N_SAFE_DIV => div_mod_n_safe_div(exec_scopes),
hint_code::GET_POINT_FROM_X => get_point_from_x(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::EC_NEGATE => ec_negate(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::EC_DOUBLE_SCOPE => compute_doubling_slope(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::COMPUTE_SLOPE => compute_slope(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::EC_DOUBLE_ASSIGN_NEW_X => ec_double_assign_new_x(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::EC_DOUBLE_ASSIGN_NEW_Y => ec_double_assign_new_y(exec_scopes, constants),
hint_code::EC_NEGATE => {
ec_negate(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::EC_DOUBLE_SCOPE => {
compute_doubling_slope(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::COMPUTE_SLOPE => {
compute_slope(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::EC_DOUBLE_ASSIGN_NEW_X => {
ec_double_assign_new_x(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking)
}
hint_code::EC_DOUBLE_ASSIGN_NEW_Y => ec_double_assign_new_y(exec_scopes),
hint_code::KECCAK_WRITE_ARGS => {
keccak_write_args(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
Expand Down Expand Up @@ -428,9 +395,8 @@ impl HintProcessor for BuiltinHintProcessor {
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
hint_code::FAST_EC_ADD_ASSIGN_NEW_Y => fast_ec_add_assign_new_y(exec_scopes, constants),
hint_code::FAST_EC_ADD_ASSIGN_NEW_Y => fast_ec_add_assign_new_y(exec_scopes),
hint_code::EC_MUL_INNER => {
ec_mul_inner(vm, &hint_data.ids_data, &hint_data.ap_tracking)
}
Expand Down
30 changes: 22 additions & 8 deletions src/hint_processor/builtin_hint_processor/math_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,29 @@ pub fn is_nn_out_of_range(
};
insert_value_into_ap(vm, value)
}
//Implements hint:from starkware.cairo.common.math_utils import assert_integer
// assert_integer(ids.a)
// assert_integer(ids.b)
// a = ids.a % PRIME
// b = ids.b % PRIME
// assert a <= b, f'a = {a} is not less than or equal to b = {b}.'
// ids.small_inputs = int(
// a < range_check_builtin.bound and (b - a) < range_check_builtin.bound)
/* Implements hint:from starkware.cairo.common.math_utils import assert_integer
%{
import itertools
from starkware.cairo.common.math_utils import assert_integer
assert_integer(ids.a)
assert_integer(ids.b)
a = ids.a % PRIME
b = ids.b % PRIME
assert a <= b, f'a = {a} is not less than or equal to b = {b}.'
# Find an arc less than PRIME / 3, and another less than PRIME / 2.
lengths_and_indices = [(a, 0), (b - a, 1), (PRIME - 1 - b, 2)]
lengths_and_indices.sort()
assert lengths_and_indices[0][0] <= PRIME // 3 and lengths_and_indices[1][0] <= PRIME // 2
excluded = lengths_and_indices[2][1]
memory[ids.range_check_ptr + 1], memory[ids.range_check_ptr + 0] = (
divmod(lengths_and_indices[0][0], ids.PRIME_OVER_3_HIGH))
memory[ids.range_check_ptr + 3], memory[ids.range_check_ptr + 2] = (
divmod(lengths_and_indices[1][0], ids.PRIME_OVER_2_HIGH))
%}
*/
pub fn assert_le_felt(
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ pub fn nondet_bigint3(
exec_scopes: &mut ExecutionScopes,
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let res_reloc = get_relocatable_from_var_name("res", vm, ids_data, ap_tracking)?;
let value = exec_scopes
.get_ref::<num_bigint::BigInt>("value")?
.to_biguint()
.ok_or(HintError::BigIntToBigUintFail)?;
let arg: Vec<MaybeRelocatable> = split(&value, constants)?
let arg: Vec<MaybeRelocatable> = split(&value)?
.into_iter()
.map(|n| MaybeRelocatable::from(Felt252::new(n)))
.collect();
Expand Down
Loading

0 comments on commit d180881

Please sign in to comment.