-
Notifications
You must be signed in to change notification settings - Fork 15
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
Initial Plonky2 Plugin #14
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Francisco Hernandez Iglesias <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
@@ -46,7 +46,7 @@ jobs: | |||
os: | |||
- ubuntu-latest | |||
channel: | |||
- stable | |||
# TODO: add custom stable checks for those parts of the workspace that can run on it |
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.
Why these changes? Is there something wrong with the stable CI?
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.
We can't use stable with plonky2 because it uses unstable features.
/// Converts a `u32` value to a field element. | ||
fn from_u32(elem: u32) -> Self; |
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.
Why not an associated type NumberType
and a function
fn from_number_type
? This would cover both the arkworks and plonky2 plugin implementations of this trait without losing randomness from the arkworks side.
@@ -297,6 +292,10 @@ where | |||
} | |||
} | |||
|
|||
impl<const ARITY: usize> SBoxExponent for Spec<bn254::Fr, ARITY> { |
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.
Why only bn254 implementation?
.is_equal(self.target.target, rhs.target.target), | ||
) | ||
} | ||
} |
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.
BitDecomposition
impl?
impl<F, const D: usize, const ARITY: usize, COM> Constant<COM> for Spec<F, D, ARITY> | ||
where | ||
F: RichField + Extendable<D>, | ||
{ | ||
type Type = Self; | ||
|
||
#[inline] | ||
fn new_constant(this: &Self::Type, compiler: &mut COM) -> Self { | ||
let _ = (this, compiler); | ||
Self(PhantomData) | ||
} | ||
} |
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.
Why do we need this?
impl<const D: usize, const ARITY: usize> poseidon::SBoxExponent | ||
for Spec<GoldilocksField, D, ARITY> | ||
{ | ||
const SBOX_EXPONENT: u64 = 7; | ||
} | ||
|
||
impl<const D: usize> poseidon::Constants for Spec<GoldilocksField, D, 7> { | ||
const WIDTH: usize = 8; | ||
const FULL_ROUNDS: usize = 8; | ||
const PARTIAL_ROUNDS: usize = 22; | ||
} | ||
|
||
impl<const D: usize> poseidon::Constants for Spec<GoldilocksField, D, 11> { | ||
const WIDTH: usize = 12; | ||
const FULL_ROUNDS: usize = 8; | ||
const PARTIAL_ROUNDS: usize = 22; | ||
} |
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.
Where did you get these constants from? Maybe mention in the docs.
let pw = PartialWitness::new(); | ||
let mut builder = CircuitBuilder::<C::F, D>::new(config); |
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.
Ideally we'd interact with plonky2 through the plugin structs and not their native ones.
data.verify(proof).expect("Verification failed."); | ||
} | ||
|
||
/// Testing Module |
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.
Time for openzl-benchmark
?
|
||
/// Tests the proving and verification of the ECDSA signature circuit. | ||
#[inline] | ||
pub fn test_ecdsa_circuit<C, const D: usize>(config: CircuitConfig) |
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.
We don't use the eclair interface at all for this circuit. If the eclair creator doesn't use it in a simple signature scheme example, who will?
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.
This stuff was copied directly from plonky2, I haven't converted it over yet.
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.
When we do change this let's allocate the pieces appropriately as public/private inputs, rather than all being constants as they are here.
|
||
/// Tests the proving and verification of the ECDSA signature circuit. | ||
#[inline] | ||
pub fn test_ecdsa_circuit<C, const D: usize>(config: CircuitConfig) |
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.
When we do change this let's allocate the pieces appropriately as public/private inputs, rather than all being constants as they are here.
) | ||
} | ||
|
||
/// Runs the ECDSA benchmark for a narrow circuit configuration. |
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.
/// Runs the ECDSA benchmark for a narrow circuit configuration. | |
/// Runs the ECDSA benchmark for a wide circuit configuration. |
@@ -85,13 +85,13 @@ where | |||
where | |||
F: FieldGeneration, | |||
{ | |||
let ys: Vec<F> = (t as u64..2 * t as u64).map(F::from_u64).collect(); | |||
let ys: Vec<F> = (t as u32..2 * t as u32).map(F::from_u32).collect(); // TODO: Change u64 to integer mod order(F) |
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.
Was this change because of the smaller size of the Goldilocks field?
num-bigint = { version = "0.4.3", default-features = false } | ||
openzl-crypto = { path = "../../openzl-crypto", default-features = false, features = ["alloc"] } | ||
openzl-util = { path = "../../openzl-util", default-features = false, features = ["alloc"] } | ||
plonky2 = { git = "https://github.com/openzklib/plonky2", branch = "feat/circuit-data-serde", default-features = false } |
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.
Why do we use this branch?
} | ||
} | ||
|
||
impl<F, const D: usize> Default for Compiler<F, D> |
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.
I think the problem is that CircuitBuilder
doesn't impl Default
even though you can construct it from a CircuitConfig
which does.
Builds a Plonky2 plugin that supports the
poseidon
gadget fromopenzl_crypto
.ProofSystem
implposeidon
backendBefore we can merge this PR, please make sure that all the following items have been checked off:
CHANGELOG.md
and added the appropriateL-
label to the PR.Files changed
in the GitHub PR explorer.CONTRIBUTING.md
.