Skip to content

Commit

Permalink
feat: secp-related hints
Browse files Browse the repository at this point in the history
Problem: we need an implementation of the hints used by the Starknet OS
in the secp syscalls. These hints rely on private primitives in
`cairo-vm` and need to be implemented here.

Solution: this PR adds an implementation of all the hints that require
`cairo-vm` primitives in the `cairo-vm` repository.
  • Loading branch information
whichqua authored and odesenfans committed Aug 29, 2024
1 parent 59953d2 commit 92cbf06
Show file tree
Hide file tree
Showing 7 changed files with 785 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Upcoming Changes

* chore: bump `cairo-lang-` dependencies to 2.7.1 [#1823](https://github.com/lambdaclass/cairo-vm/pull/1823)
* feat: Implement `SECP related` hints

#### [1.0.1] - 2024-08-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
field_arithmetic::{u256_get_square_root, u384_get_square_root, uint384_div},
mod_circuit::{run_p_mod_circuit, run_p_mod_circuit_with_large_batch_size},
secp::{
self,
ec_utils::{
compute_doubling_slope_external_consts, compute_slope_and_assing_secp_p,
ec_double_assign_new_y, ec_mul_inner, ec_negate_embedded_secp_p,
Expand Down Expand Up @@ -874,6 +875,90 @@ impl HintProcessorLogic for BuiltinHintProcessor {
constants,
exec_scopes,
),
secp::hints::SECP_R1_GET_POINT_FROM_X => secp::hints::r1_get_point_from_x(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::SECP_DOUBLE_ASSIGN_NEW_X => secp::hints::double_assign_new_x(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::GENERATE_NIBBLES => secp::hints::generate_nibbles(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::FAST_SECP_ADD_ASSIGN_NEW_Y => secp::hints::fast_secp_add_assign_new_y(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::WRITE_NIBBLES_TO_MEM => secp::hints::write_nibbles_to_mem(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::COMPUTE_IDS_HIGH_LOW => secp::hints::compute_ids_high_low(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::COMPUTE_Q_MOD_PRIME => secp::hints::compute_q_mod_prime(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::IS_ON_CURVE_2 => secp::hints::is_on_curve_2(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::SECP_REDUCE => secp::hints::reduce_value(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::SECP_REDUCE_X => secp::hints::reduce_x(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::COMPUTE_VALUE_DIV_MOD => secp::hints::compute_value_div_mod(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
secp::hints::WRITE_DIVMOD_SEGMENT => secp::hints::write_div_mod_segment(
vm,
exec_scopes,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
),
code => Err(HintError::UnknownHint(code.to_string().into_boxed_str())),
}
}
Expand Down
8 changes: 4 additions & 4 deletions vm/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ use num_traits::{One, ToPrimitive, Zero};
use super::secp_utils::SECP256R1_P;

#[derive(Debug, PartialEq)]
struct EcPoint<'a> {
x: BigInt3<'a>,
y: BigInt3<'a>,
pub(crate) struct EcPoint<'a> {
pub(crate) x: BigInt3<'a>,
pub(crate) y: BigInt3<'a>,
}
impl EcPoint<'_> {
fn from_var_name<'a>(
pub(crate) fn from_var_name<'a>(
name: &'a str,
vm: &'a VirtualMachine,
ids_data: &'a HashMap<String, HintReference>,
Expand Down
Loading

0 comments on commit 92cbf06

Please sign in to comment.