Skip to content
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

Small Gadgets refactor #353

Merged
merged 9 commits into from
Feb 29, 2024
Merged

Conversation

huitseeker
Copy link
Contributor

This does two things:

  • tests assumptions of some gadgets that Field::to_repr() returns something that translates to lower endian,
  • constrains the public exports of the gadgets module to explicitly list out everything we actually use.

This helps the move of gadgets away from arecibo, and will be followed by other PRs to crate::gadgets:

@huitseeker huitseeker requested a review from adr1anh February 28, 2024 20:42
Copy link
Contributor

@mpenciak mpenciak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a few small comments, nothing major so I approved.

Comment on lines -1 to -9
use crate::gadgets::utils::alloc_zero;
use crate::gadgets::alloc_zero;
use crate::provider::poseidon::PoseidonConstantsCircuit;
use crate::provider::Bn256EngineIPA;
use crate::provider::PallasEngine;
use crate::provider::Secp256k1Engine;
use crate::provider::VestaEngine;
use crate::supernova::circuit::{StepCircuit, TrivialSecondaryCircuit, TrivialTestCircuit};
use crate::traits::snark::default_ck_hint;
use crate::{bellpepper::test_shape_cs::TestShapeCS, gadgets::utils::alloc_one};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to clean up these imports with more {..}s?

@@ -711,7 +705,7 @@ mod tests {
test_shape_cs::TestShapeCS,
},
constants::{BN_LIMB_WIDTH, BN_N_LIMBS},
gadgets::utils::scalar_as_base,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More import cleanup possible here too

@@ -370,7 +367,7 @@ mod tests {
test_shape_cs::TestShapeCS,
},
constants::{BN_LIMB_WIDTH, BN_N_LIMBS},
gadgets::utils::scalar_as_base,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Comment on lines +264 to +266
// the write_be function above assumes Field::to_repr() outputs a representation that's an instance
// of `AsRef<[u8]>` in lower endian. We test that here, as this is not what the I2OSP standard recommends
// and may change in some implementations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good check! This is also implicitly assumed in my current CycleFold implementation as well

Comment on lines -83 to -91
let input_bits = input.unwrap_or(E::Scalar::ZERO).clone().to_le_bits();
let mut mult = E::Base::ONE;
let mut val = E::Base::ZERO;
for bit in input_bits {
if bit {
val += mult;
}
mult = mult + mult;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a one-liner?

AllocatedNum::alloc(cs.namespace(|| "allocate scalar as base"), || Ok(scalar_as_base::<E>(input.unwrap_or(E::Scalar::ZERO))))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is morally a one-liner, you're commenting on the removed code. Unless you're talking specifically about inlining the val variable, which I'll take as a nit?

@huitseeker
Copy link
Contributor Author

Thanks @mpenciak, I'll refactor the imports wholesale, through cargo fmt alongside the other shortly upcoming changes to our code base.

@huitseeker huitseeker added this pull request to the merge queue Feb 29, 2024
Merged via the queue into lurk-lang:dev with commit bb2b233 Feb 29, 2024
9 checks passed
@huitseeker huitseeker deleted the gadgets_refactor branch February 29, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants