Skip to content

Commit

Permalink
Merge pull request #18 from reilabs/wz/4844-fix-verify
Browse files Browse the repository at this point in the history
prover: verify: update `verify` command to EIP-4844
  • Loading branch information
wzmuda authored Sep 9, 2024
2 parents 568b3bb + d3d69d5 commit 52a4a1d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
42 changes: 30 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,14 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{Name: "mode", Usage: "insertion/deletion", EnvVars: []string{"MTB_MODE"}, DefaultText: "insertion"},
&cli.StringFlag{Name: "keys-file", Usage: "proving system file", Required: true},
&cli.StringFlag{Name: "input-hash", Usage: "the hash of all public inputs", Required: true},
&cli.StringFlag{Name: "input-hash", Usage: "the hash of all public inputs. Required for deletion only", Required: false},
&cli.StringFlag{Name: "params", Usage: "JSON with test parameters (gen-test-params output)", Required: true},
},
Action: func(context *cli.Context) error {
mode := context.String("mode")

keys := context.String("keys-file")
var inputHash big.Int
_, ok := inputHash.SetString(context.String("input-hash"), 0)
if !ok {
return fmt.Errorf("invalid number: %s", context.String("input-hash"))
}

ps, err := prover.ReadSystemFromFile(keys)
if err != nil {
return err
Expand All @@ -395,16 +392,37 @@ func main() {
if err != nil {
return err
}
var proof prover.Proof
err = json.Unmarshal(bytes, &proof)
if err != nil {
return err
}
logging.Logger().Info().Msg("proof read successfully")

if mode == server.InsertionMode {
err = ps.VerifyInsertion(inputHash, &proof)
var response *prover.InsertionResponse
err = json.Unmarshal(bytes, &response)
if err != nil {
return err
}

logging.Logger().Info().Msg("reading parameters")
var params *prover.InsertionParameters
err = json.Unmarshal([]byte(context.String("params")), &params)
if err != nil {
return err
}
logging.Logger().Info().Msg("params read successfully")

err = ps.VerifyInsertion(response, params)
} else if mode == server.DeletionMode {
var inputHash big.Int
_, ok := inputHash.SetString(context.String("input-hash"), 0)
if !ok {
return fmt.Errorf("invalid number: %s", context.String("input-hash"))
}

var proof prover.Proof
err = json.Unmarshal(bytes, &proof)
if err != nil {
return err
}

err = ps.VerifyDeletion(inputHash, &proof)
} else {
return fmt.Errorf("Invalid mode: %s", mode)
Expand Down
22 changes: 18 additions & 4 deletions prover/insertion_proving_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,28 @@ func (ps *ProvingSystem) ProveInsertion(params *InsertionParameters) (*Insertion
}, nil
}

func (ps *ProvingSystem) VerifyInsertion(inputHash big.Int, proof *Proof) error {
func (ps *ProvingSystem) VerifyInsertion(ir *InsertionResponse, params *InsertionParameters) error {
proofs := make([][]frontend.Variable, ps.BatchSize)
for i := 0; i < int(ps.BatchSize); i++ {
proofs[i] = make([]frontend.Variable, ps.TreeDepth)
}

versionedKzgHash := KzgToVersionedHash(ir.Commitment4844)
publicAssignment := InsertionMbuCircuit{
InputHash: inputHash,
IdComms: make([]frontend.Variable, ps.BatchSize),
InputHash: ir.InputHash,
ExpectedEvaluation: *BytesToBn254BigInt(ir.ExpectedEvaluation[:]),
Commitment4844: *BytesToBn254BigInt(versionedKzgHash[:]),
StartIndex: params.StartIndex,
PreRoot: params.PreRoot,
PostRoot: params.PostRoot,

// Initialize private slices to silence warnings
IdComms: make([]frontend.Variable, ps.BatchSize),
MerkleProofs: proofs,
}
witness, err := frontend.NewWitness(&publicAssignment, ecc.BN254.ScalarField(), frontend.PublicOnly())
if err != nil {
return err
}
return groth16.Verify(proof.Proof, ps.VerifyingKey, witness)
return groth16.Verify(ir.Proof.Proof, ps.VerifyingKey, witness)
}

0 comments on commit 52a4a1d

Please sign in to comment.