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

Initial Plonky2 Plugin #14

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Initial Plonky2 Plugin #14

wants to merge 20 commits into from

Conversation

bhgomes
Copy link
Member

@bhgomes bhgomes commented Nov 3, 2022

Builds a Plonky2 plugin that supports the poseidon gadget from openzl_crypto.

  • Compiler
  • Field
  • Boolean
  • ProofSystem impl
  • poseidon backend

Before we can merge this PR, please make sure that all the following items have been checked off:

  • Linked to an issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Added one line describing your change in CHANGELOG.md and added the appropriate L- label to the PR.
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Checked that changes and commits conform to the standards outlined in CONTRIBUTING.md.

@bhgomes bhgomes self-assigned this Nov 3, 2022
@bhgomes bhgomes added the L-added Changelog: add these changes to the `added` section of the changelog label Jan 20, 2023
Signed-off-by: Brandon H. Gomes <[email protected]>
Signed-off-by: Brandon H. Gomes <[email protected]>
@bhgomes bhgomes marked this pull request as ready for review January 20, 2023 18:44
@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines +69 to +70
/// Converts a `u32` value to a field element.
fn from_u32(elem: u32) -> Self;
Copy link
Contributor

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> {
Copy link
Contributor

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),
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

BitDecomposition impl?

plugins/plonky2/src/compiler.rs Show resolved Hide resolved
Comment on lines +174 to +185
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)
}
}
Copy link
Contributor

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?

Comment on lines +330 to +346
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;
}
Copy link
Contributor

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.

Comment on lines +27 to +28
let pw = PartialWitness::new();
let mut builder = CircuitBuilder::<C::F, D>::new(config);
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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)
Copy link
Contributor

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 }
Copy link
Contributor

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>
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-added Changelog: add these changes to the `added` section of the changelog
Development

Successfully merging this pull request may close these issues.

3 participants