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

feat: v1.0.0-rc.1 #1126

Merged
merged 18 commits into from
Jul 19, 2024
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ use stark::StarkGenericConfig;
/// This string should be updated whenever any step in verifying an SP1 proof changes, including
/// core, recursion, and plonk-bn254. This string is used to download SP1 artifacts and the gnark
/// docker image.
pub const SP1_CIRCUIT_VERSION: &str = "v1.0.8-testnet";
pub const SP1_CIRCUIT_VERSION: &str = "v1.0.0-rc.1";
2 changes: 1 addition & 1 deletion prover/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-plonk-bn254:
rm -rf build && \
mkdir -p build && \
RUSTFLAGS='-C target-cpu=native' \
cargo run -p sp1-prover --release --bin build_plonk_bn254 -- \
cargo run -p sp1-prover --release --bin build_plonk_bn254 --features native-gnark -- \
--build-dir=./build

release-plonk-bn254:
Expand Down
19 changes: 10 additions & 9 deletions recursion/gnark-ffi/go/sp1/babybear/babybear.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
var modulus = new(big.Int).SetUint64(2013265921)

func init() {
solver.RegisterHint(invFHint)
solver.RegisterHint(invEHint)
solver.RegisterHint(reduceHint)
// These functions must be public so Gnark's hint system can access them.
solver.RegisterHint(InvFHint)
solver.RegisterHint(InvEHint)
solver.RegisterHint(ReduceHint)
}

type Variable struct {
Expand Down Expand Up @@ -103,7 +104,7 @@ func (c *Chip) negF(a Variable) Variable {

func (c *Chip) invF(in Variable) Variable {
in = c.ReduceSlow(in)
result, err := c.api.Compiler().NewHint(invFHint, 1, in.Value)
result, err := c.api.Compiler().NewHint(InvFHint, 1, in.Value)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -215,7 +216,7 @@ func (c *Chip) InvE(in ExtensionVariable) ExtensionVariable {
in.Value[1] = c.ReduceSlow(in.Value[1])
in.Value[2] = c.ReduceSlow(in.Value[2])
in.Value[3] = c.ReduceSlow(in.Value[3])
result, err := c.api.Compiler().NewHint(invEHint, 4, in.Value[0].Value, in.Value[1].Value, in.Value[2].Value, in.Value[3].Value)
result, err := c.api.Compiler().NewHint(InvEHint, 4, in.Value[0].Value, in.Value[1].Value, in.Value[2].Value, in.Value[3].Value)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -274,7 +275,7 @@ func (p *Chip) ReduceSlow(x Variable) Variable {
}

func (p *Chip) reduceWithMaxBits(x frontend.Variable, maxNbBits uint64) frontend.Variable {
result, err := p.api.Compiler().NewHint(reduceHint, 2, x)
result, err := p.api.Compiler().NewHint(ReduceHint, 2, x)
if err != nil {
panic(err)
}
Expand All @@ -291,7 +292,7 @@ func (p *Chip) reduceWithMaxBits(x frontend.Variable, maxNbBits uint64) frontend
}

// The hint used to compute Reduce.
func reduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
func ReduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
if len(inputs) != 1 {
panic("reduceHint expects 1 input operand")
}
Expand All @@ -303,14 +304,14 @@ func reduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
return nil
}

func invFHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
func InvFHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
a := C.uint(inputs[0].Uint64())
ainv := C.babybearinv(a)
results[0].SetUint64(uint64(ainv))
return nil
}

func invEHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
func InvEHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
a := C.uint(inputs[0].Uint64())
b := C.uint(inputs[1].Uint64())
c := C.uint(inputs[2].Uint64())
Expand Down
16 changes: 16 additions & 0 deletions sdk/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ impl SP1ProofWithPublicValues {
_ => unimplemented!(),
}
}

/// For Plonk proofs, returns the proof in a byte encoding the onchain verifier accepts.
/// The bytes consist of the first four bytes of Plonk vkey hash followed by the encoded proof.
pub fn bytes(&self) -> Vec<u8> {
match &self.proof {
SP1Proof::Plonk(plonk_proof) => {
let mut bytes = Vec::with_capacity(4 + plonk_proof.encoded_proof.len());
bytes.extend_from_slice(&plonk_proof.plonk_vkey_hash[..4]);
bytes.extend_from_slice(
&hex::decode(&plonk_proof.encoded_proof).expect("Invalid Plonk proof"),
);
bytes
}
_ => unimplemented!("only Plonk proofs are verifiable onchain"),
}
}
}

pub type SP1CoreProofVerificationError = MachineVerificationError<CoreSC>;
Expand Down
Loading