From 852575baf63c5551752f113d9edd2dc231298252 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Thu, 13 Apr 2023 19:38:48 -0300 Subject: [PATCH 1/8] add program with div_mod_n --- cairo_programs/mul_s_inv.cairo | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 cairo_programs/mul_s_inv.cairo diff --git a/cairo_programs/mul_s_inv.cairo b/cairo_programs/mul_s_inv.cairo new file mode 100644 index 0000000000..7155cd86ee --- /dev/null +++ b/cairo_programs/mul_s_inv.cairo @@ -0,0 +1,60 @@ +%builtins range_check + +// Source: https://github.com/NilFoundation/cairo-placeholder-verification/blob/382924c6f1c4f9673a12a31d19835e00978ab241/src/signatures/ed25519.cairo + +from starkware.cairo.common.cairo_secp.bigint import BASE, BigInt3, bigint_mul, nondet_bigint3 +from starkware.cairo.common.cairo_secp.constants import N0, N1, N2 +from starkware.cairo.common.cairo_secp.ec import EcPoint, ec_add, ec_mul + +from starkware.cairo.common.math import assert_nn_le, assert_not_zero + +// Computes x * s^(-1) modulo the size of the elliptic curve (N). +func mul_s_inv{range_check_ptr}(x : BigInt3, s : BigInt3) -> (res : BigInt3){ + %{ + from starkware.cairo.common.cairo_secp.secp_utils import pack + from starkware.python.math_utils import div_mod, safe_div + + N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + x = pack(ids.x, PRIME) % N + s = pack(ids.s, PRIME) % N + value = res = div_mod(x, s, N) + %} + let (res) = nondet_bigint3(); + + %{ value = k = safe_div(res * s - x, N) %} + let (k) = nondet_bigint3(); + + let (res_s) = bigint_mul(res, s); + let n = BigInt3(N0, N1, N2); + let (k_n) = bigint_mul(k, n); + + // We should now have res_s = k_n + x. Since the numbers are in unreduced form, + // we should handle the carry. + + tempvar carry1 = (res_s.d0 - k_n.d0 - x.d0) / BASE; + assert [range_check_ptr + 0] = carry1 + 2 ** 127; + + tempvar carry2 = (res_s.d1 - k_n.d1 - x.d1 + carry1) / BASE; + assert [range_check_ptr + 1] = carry2 + 2 ** 127; + + tempvar carry3 = (res_s.d2 - k_n.d2 - x.d2 + carry2) / BASE; + assert [range_check_ptr + 2] = carry3 + 2 ** 127; + + tempvar carry4 = (res_s.d3 - k_n.d3 + carry3) / BASE; + assert [range_check_ptr + 3] = carry4 + 2 ** 127; + + assert res_s.d4 - k_n.d4 + carry4 = 0; + + let range_check_ptr = range_check_ptr + 4; + + return (res=res); +} + +func main{range_check_ptr} () -> (){ + alloc_locals; + let bi1 = BigInt3(0x216936D3CD6E53FEC0A4E, 0x231FDD6DC5C692CC760952, 0x5A7B2C9562D608F25D51A); + let bi2 = BigInt3(0x666666666666666666666, 0x6666666666666666666666, 0x666666666666666666658); + let res = mul_s_inv(bi1, bi2); + assert res = res; + return (); +} From 6398d8e93f6d59b5fd237635fdfa0b0f811ca48d Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:13:13 -0300 Subject: [PATCH 2/8] make mul_s_inv program execute --- .../builtin_hint_processor_definition.rs | 10 ++++-- .../builtin_hint_processor/hint_code.rs | 9 +++++ .../builtin_hint_processor/secp/signature.rs | 34 ++++++++++++++++--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index 535db3b7ec..cba4b29c87 100644 --- a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -38,7 +38,7 @@ use crate::{ is_zero_assign_scope_variables, is_zero_nondet, is_zero_pack, reduce, verify_zero, }, - signature::{div_mod_n_packed_divmod, div_mod_n_safe_div, get_point_from_x}, + signature::{div_mod_n_packed_divmod, div_mod_n_safe_div, get_point_from_x, pack_modn_div_modn}, }, segments::{relocate_segment, temporary_array}, set::set_add, @@ -342,7 +342,7 @@ impl HintProcessor for BuiltinHintProcessor { &hint_data.ids_data, &hint_data.ap_tracking, ), - hint_code::DIV_MOD_N_SAFE_DIV => div_mod_n_safe_div(exec_scopes), + hint_code::DIV_MOD_N_SAFE_DIV => div_mod_n_safe_div(exec_scopes, "a", "b"), hint_code::GET_POINT_FROM_X => get_point_from_x( vm, exec_scopes, @@ -452,6 +452,12 @@ impl HintProcessor for BuiltinHintProcessor { chained_ec_op_random_ec_point_hint(vm, &hint_data.ids_data, &hint_data.ap_tracking) } hint_code::RECOVER_Y => recover_y_hint(vm, &hint_data.ids_data, &hint_data.ap_tracking), + hint_code::PACK_MODN_DIV_MODN => pack_modn_div_modn(vm, + exec_scopes, + &hint_data.ids_data, + &hint_data.ap_tracking, + ), + hint_code::XS_SAFE_DIV => div_mod_n_safe_div(exec_scopes, "x", "s"), #[cfg(feature = "skip_next_instruction_hint")] hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm), code => Err(HintError::UnknownHint(code.to_string())), diff --git a/src/hint_processor/builtin_hint_processor/hint_code.rs b/src/hint_processor/builtin_hint_processor/hint_code.rs index aa0472104f..d280331b73 100644 --- a/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -617,5 +617,14 @@ from starkware.python.math_utils import recover_y ids.p.x = ids.x # This raises an exception if `x` is not on the curve. ids.p.y = recover_y(ids.x, ALPHA, BETA, FIELD_PRIME)"; +pub(crate) const PACK_MODN_DIV_MODN: &str = "from starkware.cairo.common.cairo_secp.secp_utils import pack +from starkware.python.math_utils import div_mod, safe_div + +N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 +x = pack(ids.x, PRIME) % N +s = pack(ids.s, PRIME) % N +value = res = div_mod(x, s, N)"; +pub(crate) const XS_SAFE_DIV: &str = "value = k = safe_div(res * s - x, N)"; + #[cfg(feature = "skip_next_instruction_hint")] pub(crate) const SKIP_NEXT_INSTRUCTION: &str = "skip_next_instruction()"; diff --git a/src/hint_processor/builtin_hint_processor/secp/signature.rs b/src/hint_processor/builtin_hint_processor/secp/signature.rs index 1f65e56e85..70e6df781b 100644 --- a/src/hint_processor/builtin_hint_processor/secp/signature.rs +++ b/src/hint_processor/builtin_hint_processor/secp/signature.rs @@ -50,9 +50,9 @@ pub fn div_mod_n_packed_divmod( // Implements hint: // value = k = safe_div(res * b - a, N) -pub fn div_mod_n_safe_div(exec_scopes: &mut ExecutionScopes) -> Result<(), HintError> { - let a = exec_scopes.get_ref::("a")?; - let b = exec_scopes.get_ref::("b")?; +pub fn div_mod_n_safe_div(exec_scopes: &mut ExecutionScopes, a_alias: &str, b_alias: &str) -> Result<(), HintError> { + let a = exec_scopes.get_ref::(a_alias)?; + let b = exec_scopes.get_ref::(b_alias)?; let res = exec_scopes.get_ref::("res")?; let value = safe_div_bigint(&(res * b - a), &N)?; @@ -103,6 +103,30 @@ pub fn get_point_from_x( exec_scopes.insert_value("value", y); Ok(()) } +/* Implements hint: + from starkware.cairo.common.cairo_secp.secp_utils import pack + from starkware.python.math_utils import div_mod, safe_div + + N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + x = pack(ids.x, PRIME) % N + s = pack(ids.s, PRIME) % N + value = res = div_mod(x, s, N) +*/ +pub fn pack_modn_div_modn(vm: &mut VirtualMachine, + exec_scopes: &mut ExecutionScopes, + ids_data: &HashMap, + ap_tracking: &ApTracking,) -> Result<(), HintError> { + let x = pack(BigInt3::from_var_name("x", vm, ids_data, ap_tracking)?).mod_floor(&N); + let s = pack(BigInt3::from_var_name("s", vm, ids_data, ap_tracking)?).mod_floor(&N); + + let value = div_mod(&x, &s, &N); + exec_scopes.insert_value("x", x); + exec_scopes.insert_value("s", s); + exec_scopes.insert_value("value", value.clone()); + exec_scopes.insert_value("res", value); + Ok(()) + } + #[cfg(test)] mod tests { @@ -147,7 +171,7 @@ mod tests { let ids_data = non_continuous_ids_data![("a", -3), ("b", 0)]; let mut exec_scopes = ExecutionScopes::new(); assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); - assert_matches!(div_mod_n_safe_div(&mut exec_scopes), Ok(())); + assert_matches!(div_mod_n_safe_div(&mut exec_scopes, "a", "b"), Ok(())); } #[test] @@ -161,6 +185,8 @@ mod tests { assert_matches!( div_mod_n_safe_div( &mut exec_scopes, + "a", + "b" ), Err( HintError::Math(MathError::SafeDivFailBigInt( From a1712e0108958c7990674bdd8cefb58f5e5678b3 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:13:52 -0300 Subject: [PATCH 3/8] make mul_s_inv program execute --- .../builtin_hint_processor_definition.rs | 13 ++++---- .../builtin_hint_processor/hint_code.rs | 3 +- .../builtin_hint_processor/secp/signature.rs | 33 +++++++++++-------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index cba4b29c87..eeb24cf0b3 100644 --- a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -38,7 +38,10 @@ use crate::{ is_zero_assign_scope_variables, is_zero_nondet, is_zero_pack, reduce, verify_zero, }, - signature::{div_mod_n_packed_divmod, div_mod_n_safe_div, get_point_from_x, pack_modn_div_modn}, + signature::{ + div_mod_n_packed_divmod, div_mod_n_safe_div, get_point_from_x, + pack_modn_div_modn, + }, }, segments::{relocate_segment, temporary_array}, set::set_add, @@ -452,11 +455,9 @@ impl HintProcessor for BuiltinHintProcessor { chained_ec_op_random_ec_point_hint(vm, &hint_data.ids_data, &hint_data.ap_tracking) } hint_code::RECOVER_Y => recover_y_hint(vm, &hint_data.ids_data, &hint_data.ap_tracking), - hint_code::PACK_MODN_DIV_MODN => pack_modn_div_modn(vm, - exec_scopes, - &hint_data.ids_data, - &hint_data.ap_tracking, - ), + hint_code::PACK_MODN_DIV_MODN => { + pack_modn_div_modn(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking) + } hint_code::XS_SAFE_DIV => div_mod_n_safe_div(exec_scopes, "x", "s"), #[cfg(feature = "skip_next_instruction_hint")] hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm), diff --git a/src/hint_processor/builtin_hint_processor/hint_code.rs b/src/hint_processor/builtin_hint_processor/hint_code.rs index d280331b73..17911f91be 100644 --- a/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -617,7 +617,8 @@ from starkware.python.math_utils import recover_y ids.p.x = ids.x # This raises an exception if `x` is not on the curve. ids.p.y = recover_y(ids.x, ALPHA, BETA, FIELD_PRIME)"; -pub(crate) const PACK_MODN_DIV_MODN: &str = "from starkware.cairo.common.cairo_secp.secp_utils import pack +pub(crate) const PACK_MODN_DIV_MODN: &str = + "from starkware.cairo.common.cairo_secp.secp_utils import pack from starkware.python.math_utils import div_mod, safe_div N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 diff --git a/src/hint_processor/builtin_hint_processor/secp/signature.rs b/src/hint_processor/builtin_hint_processor/secp/signature.rs index 70e6df781b..21ce20dc93 100644 --- a/src/hint_processor/builtin_hint_processor/secp/signature.rs +++ b/src/hint_processor/builtin_hint_processor/secp/signature.rs @@ -50,7 +50,11 @@ pub fn div_mod_n_packed_divmod( // Implements hint: // value = k = safe_div(res * b - a, N) -pub fn div_mod_n_safe_div(exec_scopes: &mut ExecutionScopes, a_alias: &str, b_alias: &str) -> Result<(), HintError> { +pub fn div_mod_n_safe_div( + exec_scopes: &mut ExecutionScopes, + a_alias: &str, + b_alias: &str, +) -> Result<(), HintError> { let a = exec_scopes.get_ref::(a_alias)?; let b = exec_scopes.get_ref::(b_alias)?; let res = exec_scopes.get_ref::("res")?; @@ -112,21 +116,22 @@ pub fn get_point_from_x( s = pack(ids.s, PRIME) % N value = res = div_mod(x, s, N) */ -pub fn pack_modn_div_modn(vm: &mut VirtualMachine, +pub fn pack_modn_div_modn( + vm: &mut VirtualMachine, exec_scopes: &mut ExecutionScopes, ids_data: &HashMap, - ap_tracking: &ApTracking,) -> Result<(), HintError> { - let x = pack(BigInt3::from_var_name("x", vm, ids_data, ap_tracking)?).mod_floor(&N); - let s = pack(BigInt3::from_var_name("s", vm, ids_data, ap_tracking)?).mod_floor(&N); - - let value = div_mod(&x, &s, &N); - exec_scopes.insert_value("x", x); - exec_scopes.insert_value("s", s); - exec_scopes.insert_value("value", value.clone()); - exec_scopes.insert_value("res", value); - Ok(()) - } - + ap_tracking: &ApTracking, +) -> Result<(), HintError> { + let x = pack(BigInt3::from_var_name("x", vm, ids_data, ap_tracking)?).mod_floor(&N); + let s = pack(BigInt3::from_var_name("s", vm, ids_data, ap_tracking)?).mod_floor(&N); + + let value = div_mod(&x, &s, &N); + exec_scopes.insert_value("x", x); + exec_scopes.insert_value("s", s); + exec_scopes.insert_value("value", value.clone()); + exec_scopes.insert_value("res", value); + Ok(()) +} #[cfg(test)] mod tests { From 4c91f2cc454e2fc0216621732a6de2ed4780daa0 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Fri, 14 Apr 2023 17:21:00 -0300 Subject: [PATCH 4/8] add pack_modn_div_modn and mul_s_inv test --- .../builtin_hint_processor/secp/signature.rs | 21 +++++++++++++++++++ src/tests/cairo_run_test.rs | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/src/hint_processor/builtin_hint_processor/secp/signature.rs b/src/hint_processor/builtin_hint_processor/secp/signature.rs index 21ce20dc93..d83f2c4ad8 100644 --- a/src/hint_processor/builtin_hint_processor/secp/signature.rs +++ b/src/hint_processor/builtin_hint_processor/secp/signature.rs @@ -269,4 +269,25 @@ mod tests { )] ); } + + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn pack_modn_div_modn_ok() { + let hint_code = hint_code::PACK_MODN_DIV_MODN; + let mut vm = vm!(); + + vm.segments = segments![ + ((1, 0), 15), + ((1, 1), 3), + ((1, 2), 40), + ((1, 3), 0), + ((1, 4), 10), + ((1, 5), 1) + ]; + vm.run_context.fp = 3; + let ids_data = non_continuous_ids_data![("x", -3), ("s", 0)]; + let mut exec_scopes = ExecutionScopes::new(); + assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); + assert_matches!(div_mod_n_safe_div(&mut exec_scopes, "x", "s"), Ok(())); + } } diff --git a/src/tests/cairo_run_test.rs b/src/tests/cairo_run_test.rs index 9c12f8b0e3..aef0fd31a0 100644 --- a/src/tests/cairo_run_test.rs +++ b/src/tests/cairo_run_test.rs @@ -1280,3 +1280,10 @@ fn cairo_run_is_quad_residue_test() { let program_data = include_bytes!("../../cairo_programs/is_quad_residue_test.json"); run_program_simple(program_data.as_slice()); } + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_ed25519_ec() { + let program_data = include_bytes!("../../cairo_programs/mul_s_inv.json"); + run_program_simple(program_data.as_slice()); +} From 8aed31ee2466fb70011bfe529cfa02a5588a9a22 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Fri, 14 Apr 2023 17:35:59 -0300 Subject: [PATCH 5/8] add changes to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e315f345..77a3e61b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### Upcoming Changes * 0.11 Support + * Added support for hints `PACK_MODN_DIV_MODN` and `XS_SAFE_DIV` [#991](https://github.com/lambdaclass/cairo-rs/pull/991) * Layouts update [#874](https://github.com/lambdaclass/cairo-rs/pull/874) * Keccak builtin updated [#873](https://github.com/lambdaclass/cairo-rs/pull/873), [#883](https://github.com/lambdaclass/cairo-rs/pull/883) * Changes to `ec_op` [#876](https://github.com/lambdaclass/cairo-rs/pull/876) From 8df096eece8bcc5e39f6997acadb1c9f9684a734 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Mon, 17 Apr 2023 10:52:31 -0300 Subject: [PATCH 6/8] fix changelog merge --- CHANGELOG.md | 69 ++++++++++++++++++++++++++++++++++++- src/tests/cairo_run_test.rs | 2 +- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74533c846a..8c5e60b47c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ #### Upcoming Changes * 0.11 Support - * Added support for hints `PACK_MODN_DIV_MODN` and `XS_SAFE_DIV` [#991](https://github.com/lambdaclass/cairo-rs/pull/991) + * Add support for hints `PACK_MODN_DIV_MODN` and `XS_MOD` [#991](https://github.com/lambdaclass/cairo-rs/pull/991) * Layouts update [#874](https://github.com/lambdaclass/cairo-rs/pull/874) * Keccak builtin updated [#873](https://github.com/lambdaclass/cairo-rs/pull/873), [#883](https://github.com/lambdaclass/cairo-rs/pull/883) * Changes to `ec_op` [#876](https://github.com/lambdaclass/cairo-rs/pull/876) @@ -199,6 +199,10 @@ ids.root.d2 = root_split[2] ``` +* Re-export the `cairo-felt` crate as `cairo_vm::felt` [#981](https://github.com/lambdaclass/cairo-rs/pull/981) + * Removes the need of explicitly importing `cairo-felt` in downstream projects + and helps ensure there is no version mismatch caused by that + * Implement hint on `uint256_mul_div_mod`[#957](https://github.com/lambdaclass/cairo-rs/pull/957) `BuiltinHintProcessor` now supports the following hint: @@ -219,6 +223,69 @@ Used by the common library function `uint256_mul_div_mod` +* Add missing hint on cairo_secp lib [#986]: + + `BuiltinHintProcessor` now supports the following hint: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + from starkware.python.math_utils import div_mod + + # Compute the slope. + x = pack(ids.pt.x, PRIME) + y = pack(ids.pt.y, PRIME) + value = slope = div_mod(3 * x ** 2, 2 * y, SECP_P) + ``` + +* Add missing hint on cairo_secp lib [#984]: + `BuiltinHintProcessor` now supports the following hint: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + from starkware.python.math_utils import div_mod + + # Compute the slope. + x0 = pack(ids.pt0.x, PRIME) + y0 = pack(ids.pt0.y, PRIME) + x1 = pack(ids.pt1.x, PRIME) + y1 = pack(ids.pt1.y, PRIME) + value = slope = div_mod(y0 - y1, x0 - x1, SECP_P) + ``` + +* Add missing hint on cairo_secp lib [#989]: + + `BuiltinHintProcessor` now supports the following hint: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import SECP_P + q, r = divmod(pack(ids.val, PRIME), SECP_P) + assert r == 0, f"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}." + ids.q = q % PRIME + ``` + +* Add missing hint on cairo_secp lib [#986]: + `BuiltinHintProcessor` now supports the following hint: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + from starkware.python.math_utils import div_mod + + # Compute the slope. + x = pack(ids.pt.x, PRIME) + y = pack(ids.pt.y, PRIME) + value = slope = div_mod(3 * x ** 2, 2 * y, SECP_P) + ``` + +* Add missing hint on cairo_secp lib [#984]: + `BuiltinHintProcessor` now supports the following hint: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + from starkware.python.math_utils import div_mod + + # Compute the slope. + x0 = pack(ids.pt0.x, PRIME) + y0 = pack(ids.pt0.y, PRIME) + x1 = pack(ids.pt1.x, PRIME) + y1 = pack(ids.pt1.y, PRIME) + value = slope = div_mod(y0 - y1, x0 - x1, SECP_P) + ``` + * Move `Memory` into `MemorySegmentManager` [#830](https://github.com/lambdaclass/cairo-rs/pull/830) * Structural changes: * Remove `memory: Memory` field from `VirtualMachine` diff --git a/src/tests/cairo_run_test.rs b/src/tests/cairo_run_test.rs index 588aede09c..21f7a307e1 100644 --- a/src/tests/cairo_run_test.rs +++ b/src/tests/cairo_run_test.rs @@ -1283,7 +1283,7 @@ fn cairo_run_is_quad_residue_test() { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_ed25519_ec() { +fn cairo_run_mul_s_inv() { let program_data = include_bytes!("../../cairo_programs/mul_s_inv.json"); run_program_simple(program_data.as_slice()); } From 7bbfcb0bb26fc2aa078e8c58366dc90bd36bea21 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:15:44 -0300 Subject: [PATCH 7/8] fix changelog --- CHANGELOG.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c5e60b47c..ee3769e3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,20 @@ #### Upcoming Changes * 0.11 Support - * Add support for hints `PACK_MODN_DIV_MODN` and `XS_MOD` [#991](https://github.com/lambdaclass/cairo-rs/pull/991) + * Add support for hints `PACK_MODN_DIV_MODN`: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import pack + from starkware.python.math_utils import div_mod, safe_div + + N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + x = pack(ids.x, PRIME) % N + s = pack(ids.s, PRIME) % N + value = res = div_mod(x, s, N) + ``` + and `XS_SAFE_DIV` [#991](https://github.com/lambdaclass/cairo-rs/pull/991): + ```python + value = k = safe_div(res * s - x, N) + ``` * Layouts update [#874](https://github.com/lambdaclass/cairo-rs/pull/874) * Keccak builtin updated [#873](https://github.com/lambdaclass/cairo-rs/pull/873), [#883](https://github.com/lambdaclass/cairo-rs/pull/883) * Changes to `ec_op` [#876](https://github.com/lambdaclass/cairo-rs/pull/876) From 8ffdc04d2dee4857368ea2f067f01d1d290b17e9 Mon Sep 17 00:00:00 2001 From: mfachal <647731+mfachal@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:17:25 -0300 Subject: [PATCH 8/8] fix changelog style --- CHANGELOG.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3152ed23ec..191b3be9eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,20 +6,21 @@ * BugFix: Add missing `\n` character after traceback lines when the filename is missing ("Unknown Location") * 0.11 Support - * Add missing hints `PACK_MODN_DIV_MODN`: - ```python - from starkware.cairo.common.cairo_secp.secp_utils import pack - from starkware.python.math_utils import div_mod, safe_div - - N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 - x = pack(ids.x, PRIME) % N - s = pack(ids.s, PRIME) % N - value = res = div_mod(x, s, N) - ``` - and `XS_SAFE_DIV` [#991](https://github.com/lambdaclass/cairo-rs/pull/991): - ```python - value = k = safe_div(res * s - x, N) - ``` + * Add missing hints on cairo_secp lib [#991](https://github.com/lambdaclass/cairo-rs/pull/991): + `BuiltinHintProcessor` now supports the following hints: + ```python + from starkware.cairo.common.cairo_secp.secp_utils import pack + from starkware.python.math_utils import div_mod, safe_div + + N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + x = pack(ids.x, PRIME) % N + s = pack(ids.s, PRIME) % N + value = res = div_mod(x, s, N) + ``` + and: + ```python + value = k = safe_div(res * s - x, N) + ``` * Layouts update [#874](https://github.com/lambdaclass/cairo-rs/pull/874) * Keccak builtin updated [#873](https://github.com/lambdaclass/cairo-rs/pull/873), [#883](https://github.com/lambdaclass/cairo-rs/pull/883) * Changes to `ec_op` [#876](https://github.com/lambdaclass/cairo-rs/pull/876)