diff --git a/CHANGELOG.md b/CHANGELOG.md index f51c9cb46c..3fbaa1b980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * refactor: Remove unused code & use constants whenever possible for builtin instance definitions[#1707](https://github.com/lambdaclass/cairo-vm/pull/1707) +* feat: missing EC hints for Starknet OS 0.13.1 [#1706](https://github.com/lambdaclass/cairo-vm/pull/1706) + * fix(BREAKING): Use program builtins in `initialize_main_entrypoint` & `read_return_values`[#1703](https://github.com/lambdaclass/cairo-vm/pull/1703) * `initialize_main_entrypoint` now iterates over the program builtins when building the stack & inserts 0 for any missing builtin * `read_return_values` now only computes the final stack of the builtins in the program diff --git a/fuzzer/src/fuzz_json.rs b/fuzzer/src/fuzz_json.rs index 09193c512b..4306a29c67 100644 --- a/fuzzer/src/fuzz_json.rs +++ b/fuzzer/src/fuzz_json.rs @@ -29,7 +29,7 @@ const HEX_SYMBOLS: [&str; 16] = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", ]; -const HINTS_CODE: [&str; 184] = [ +const HINTS_CODE: [&str; 186] = [ ADD_SEGMENT, VM_ENTER_SCOPE, VM_EXIT_SCOPE, @@ -139,10 +139,12 @@ const HINTS_CODE: [&str; 184] = [ EC_DOUBLE_SLOPE_V1, EC_DOUBLE_SLOPE_V2, EC_DOUBLE_SLOPE_V3, + EC_DOUBLE_SLOPE_V4, EC_DOUBLE_SLOPE_EXTERNAL_CONSTS, COMPUTE_SLOPE_V1, COMPUTE_SLOPE_V2, - COMPUTE_SLOPE_SECP256R1, + COMPUTE_SLOPE_SECP256R1_V1, + COMPUTE_SLOPE_SECP256R1_V2, IMPORT_SECP256R1_P, COMPUTE_SLOPE_WHITELIST, EC_DOUBLE_ASSIGN_NEW_X_V1, diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index e785949884..3120b91d03 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -119,6 +119,9 @@ use crate::hint_processor::builtin_hint_processor::skip_next_instruction::skip_n #[cfg(feature = "print")] use crate::hint_processor::builtin_hint_processor::print::{print_array, print_dict, print_felt}; +use crate::hint_processor::builtin_hint_processor::secp::secp_utils::{ + SECP256R1_ALPHA, SECP256R1_P, +}; use super::blake2s_utils::example_blake2s_compress; @@ -532,6 +535,15 @@ impl HintProcessorLogic for BuiltinHintProcessor { &SECP_P, &ALPHA, ), + hint_code::EC_DOUBLE_SLOPE_V4 => compute_doubling_slope( + vm, + exec_scopes, + &hint_data.ids_data, + &hint_data.ap_tracking, + "point", + &SECP256R1_P, + &SECP256R1_ALPHA, + ), hint_code::EC_DOUBLE_SLOPE_EXTERNAL_CONSTS => compute_doubling_slope_external_consts( vm, exec_scopes, @@ -559,13 +571,23 @@ impl HintProcessorLogic for BuiltinHintProcessor { "point1", &SECP_P_V2, ), - hint_code::COMPUTE_SLOPE_SECP256R1 => compute_slope( + hint_code::COMPUTE_SLOPE_SECP256R1_V1 => compute_slope( + vm, + exec_scopes, + &hint_data.ids_data, + &hint_data.ap_tracking, + "point0", + "point1", + "SECP_P", + ), + hint_code::COMPUTE_SLOPE_SECP256R1_V2 => compute_slope( vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking, "point0", "point1", + "SECP256R1_P", ), hint_code::IMPORT_SECP256R1_P => import_secp256r1_p(exec_scopes), hint_code::COMPUTE_SLOPE_WHITELIST => compute_slope_and_assing_secp_p( diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs index 563fe0d7e0..03bab59189 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -694,6 +694,15 @@ x = pack(ids.pt.x, PRIME) y = pack(ids.pt.y, PRIME) value = slope = div_mod(3 * x ** 2, 2 * y, SECP_P)"#; +pub const EC_DOUBLE_SLOPE_V4: &str = r#"from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_ALPHA, SECP256R1_P +from starkware.cairo.common.cairo_secp.secp_utils import pack +from starkware.python.math_utils import ec_double_slope + +# Compute the slope. +x = pack(ids.point.x, SECP256R1_P) +y = pack(ids.point.y, SECP256R1_P) +value = slope = ec_double_slope(point=(x, y), alpha=SECP256R1_ALPHA, p=SECP256R1_P)"#; + pub const EC_DOUBLE_SLOPE_EXTERNAL_CONSTS: &str = r#"from starkware.cairo.common.cairo_secp.secp_utils import pack from starkware.python.math_utils import ec_double_slope @@ -722,7 +731,7 @@ x1 = pack(ids.point1.x, PRIME) y1 = pack(ids.point1.y, PRIME) value = slope = line_slope(point1=(x0, y0), point2=(x1, y1), p=SECP_P)"#; -pub const COMPUTE_SLOPE_SECP256R1: &str = r#"from starkware.cairo.common.cairo_secp.secp_utils import pack +pub const COMPUTE_SLOPE_SECP256R1_V1: &str = r#"from starkware.cairo.common.cairo_secp.secp_utils import pack from starkware.python.math_utils import line_slope # Compute the slope. @@ -732,6 +741,17 @@ x1 = pack(ids.point1.x, PRIME) y1 = pack(ids.point1.y, PRIME) value = slope = line_slope(point1=(x0, y0), point2=(x1, y1), p=SECP_P)"#; +pub const COMPUTE_SLOPE_SECP256R1_V2: &str = r#"from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P +from starkware.cairo.common.cairo_secp.secp_utils import pack +from starkware.python.math_utils import line_slope + +# Compute the slope. +x0 = pack(ids.point0.x, PRIME) +y0 = pack(ids.point0.y, PRIME) +x1 = pack(ids.point1.x, PRIME) +y1 = pack(ids.point1.y, PRIME) +value = slope = line_slope(point1=(x0, y0), point2=(x1, y1), p=SECP256R1_P)"#; + pub const IMPORT_SECP256R1_P: &str = "from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P as SECP_P"; diff --git a/vm/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs b/vm/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs index d4dbc3b910..fdafd49e07 100644 --- a/vm/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs @@ -198,6 +198,7 @@ pub fn compute_slope_and_assing_secp_p( ap_tracking, point0_alias, point1_alias, + "SECP_P", ) } @@ -208,13 +209,14 @@ pub fn compute_slope( ap_tracking: &ApTracking, point0_alias: &str, point1_alias: &str, + secp_p_name: &str, ) -> Result<(), HintError> { //ids.point0 let point0 = EcPoint::from_var_name(point0_alias, vm, ids_data, ap_tracking)?; //ids.point1 let point1 = EcPoint::from_var_name(point1_alias, vm, ids_data, ap_tracking)?; - let secp_p: BigInt = exec_scopes.get("SECP_P")?; + let secp_p: BigInt = exec_scopes.get(secp_p_name)?; let value = line_slope( &(point0.x.pack86(), point0.y.pack86()),