Skip to content

Commit

Permalink
Use log filtering instead of getting latest root
Browse files Browse the repository at this point in the history
  • Loading branch information
artemskriabin committed Aug 27, 2024
1 parent d22b893 commit 65f5e25
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions internal/config/poll_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,22 @@ func (v *PollVerifier) VerifyProof(proof zkptypes.ZKProof, proposalID, proposalE
return ErrInvalidProposalEventID
}

proposalSMTAddress := proposalInfo.ProposalSMT
proposalSMTCaller, err := proposalsmt.NewProposalSMTCaller(proposalSMTAddress, v.RPC)
root := decimalTo32Bytes(proof.PubSignals[PollNullifierTreeRoot])
if root == [32]byte{} {
return ErrInvalidRoot
}

proposalSMTCaller, err := proposalsmt.NewProposalSMTFilterer(proposalInfo.ProposalSMT, v.RPC)
if err != nil {
return fmt.Errorf("failed to create proposal smt caller: %w", err)
}

root, err := proposalSMTCaller.GetRoot(nil)
it, err := proposalSMTCaller.FilterRootUpdated(nil, [][32]byte{root})
if err != nil {
return fmt.Errorf("failed to get root: %w", err)
}

if new(big.Int).SetBytes(root[:]).String() != proof.PubSignals[PollNullifierTreeRoot] {
if ok := it.Next(); !ok {
return ErrInvalidRoot
}

Expand All @@ -123,3 +127,15 @@ func (v *PollVerifier) VerifyProof(proof zkptypes.ZKProof, proposalID, proposalE

return nil
}

func decimalTo32Bytes(root string) [32]byte {
b, ok := new(big.Int).SetString(root, 10)
if !ok {
return [32]byte{}
}

var bytes [32]byte
b.FillBytes(bytes[:])

return bytes
}

0 comments on commit 65f5e25

Please sign in to comment.