Skip to content

Commit

Permalink
Merge pull request #33 from rarimo/fix/poll_verifier
Browse files Browse the repository at this point in the history
Use log filtering instead of getting latest root
  • Loading branch information
artemskriabin authored Aug 27, 2024
2 parents d63b800 + 65f5e25 commit 49fc051
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 49fc051

Please sign in to comment.