diff --git a/internal/config/poll_verifier.go b/internal/config/poll_verifier.go index 990cc11..c7897b7 100644 --- a/internal/config/poll_verifier.go +++ b/internal/config/poll_verifier.go @@ -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 } @@ -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 +}