diff --git a/core/src/lib.rs b/core/src/lib.rs index 5ddb750641..2e9fecd64d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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"; diff --git a/prover/Makefile b/prover/Makefile index b4e0999616..8ab442e38b 100644 --- a/prover/Makefile +++ b/prover/Makefile @@ -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: diff --git a/recursion/gnark-ffi/go/sp1/babybear/babybear.go b/recursion/gnark-ffi/go/sp1/babybear/babybear.go index 74219c428c..066edd2653 100644 --- a/recursion/gnark-ffi/go/sp1/babybear/babybear.go +++ b/recursion/gnark-ffi/go/sp1/babybear/babybear.go @@ -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 { @@ -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) } @@ -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) } @@ -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) } @@ -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") } @@ -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()) diff --git a/sdk/src/proof.rs b/sdk/src/proof.rs index 75b81fcdf6..86d8939f74 100644 --- a/sdk/src/proof.rs +++ b/sdk/src/proof.rs @@ -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 { + 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;