-
Notifications
You must be signed in to change notification settings - Fork 344
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
refactor: generic size limbs for curve precompiles #417
Conversation
diff curves Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
core/src/operations/field/params.rs
Outdated
} | ||
|
||
/// Implement NumWords for NumLimbs where # Limbs is divisible by 4. | ||
impl<N: NumLimbs> NumWords for N |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you could leave a comment explaining wtf is going on here, that would be great :)
@@ -53,14 +52,14 @@ pub struct EdAddAssignCols<T> { | |||
pub q_ptr: T, | |||
pub p_access: [MemoryWriteCols<T>; 16], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: shouldn't these be Ed25519BaseField::...
for consistency?
|
||
let p_x = limbs_from_prev_access(&row.p_access[0..NUM_WORDS_FIELD_ELEMENT]); | ||
let p_y = limbs_from_prev_access(&row.p_access[NUM_WORDS_FIELD_ELEMENT..]); | ||
let num_words_field_element = E::BaseField::NB_LIMBS / 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: here shouldn't we just use the NUM_WORDS trait on E?
|
||
// a in the Weierstrass form: y^2 = x^3 + a * x + b. | ||
let a = limbs_from_biguint::<AB, E::BaseField>(&E::a_int()); | ||
// TODO: U32 can't be hardcoded here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this todo mean?
core/src/utils/ec/edwards/mod.rs
Outdated
@@ -6,6 +6,9 @@ use serde::{Deserialize, Serialize}; | |||
use crate::utils::ec::field::{FieldParameters, MAX_NB_LIMBS}; | |||
use crate::utils::ec::{AffinePoint, EllipticCurve, EllipticCurveParameters}; | |||
|
|||
// The number of `u8` limbs in the base field of Ed25519. | |||
const NUM_LIMBS: usize = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we clean up MAX_NB_LIMBS
and NUM_LIMBS
in here?
@@ -38,6 +40,11 @@ impl FieldParameters for Bn254BaseField { | |||
} | |||
} | |||
|
|||
impl NumLimbs for Bn254BaseField { | |||
type Limbs = U16; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait i think this should be u32, u62 lol, i was just trolling when i added this file
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com> Co-authored-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
<T, N: ArraySize>
NumLimbs
trait which hasLimbs
andWitness
ArraySize
typesgeneric_array
from rustcrypto so we can have associated array lengths in traithybrid-array
to const generic core arrays RustCrypto/traits#1481E::BaseField
as NumLimbs (execute still hardcoded)