Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix in consistency proof verification #266

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pangea-sdk/v3/service/audit/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ func (a *audit) processSearchEvents(ctx context.Context, events SearchEvents, ro
if event.Published != nil && *event.Published {
event.VerifyMembershipProof(root)
event.VerifyConsistencyProof(roots)
if event.ConsistencyVerification == Failed {
if event.ConsistencyVerification == Failed && event.LeafIndex != nil {
// verify again with the consistency proof fetched from Pangea
roots, _ = a.fixConsistencyProof(ctx, root.Size)
roots, _ = a.fixConsistencyProof(ctx, *event.LeafIndex+1)
event.VerifyConsistencyProof(roots)
}
} else {
Expand Down Expand Up @@ -418,7 +418,7 @@ func (a *audit) fixConsistencyProof(ctx context.Context, treeSize int) (map[int]
}

// override root
a.rp.OverrideRoots(map[int]Root{treeSize: resp.Result.Data})
roots = a.rp.OverrideRoots(map[int]Root{treeSize: resp.Result.Data})
return roots, nil
}

Expand Down Expand Up @@ -805,7 +805,7 @@ func (ee *SearchEvent) VerifyConsistencyProof(publishedRoots map[int]Root) {
ee.ConsistencyVerification = NotVerified
return
}
idx := *ee.LeafIndex
idx := *ee.LeafIndex + 1
if idx < 0 {
ee.ConsistencyVerification = Failed
return
Expand Down
5 changes: 3 additions & 2 deletions pangea-sdk/v3/service/audit/roots_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type RootsProvider interface {
UpdateRoots(ctx context.Context, treeSizes []string) map[int]Root
OverrideRoots(roots map[int]Root)
OverrideRoots(roots map[int]Root) map[int]Root
}

type ArweaveRootsProvider struct {
Expand Down Expand Up @@ -72,10 +72,11 @@ func (rp *ArweaveRootsProvider) UpdateRoots(ctx context.Context, treeSizes []str
return rp.Roots
}

func (rp *ArweaveRootsProvider) OverrideRoots(roots map[int]Root) {
func (rp *ArweaveRootsProvider) OverrideRoots(roots map[int]Root) map[int]Root {
for treeSize, root := range roots {
rp.Roots[treeSize] = root
}
return rp.Roots
}

func treeSizeFromTransaction(tx *arweave.Transaction) (int, error) {
Expand Down
2 changes: 1 addition & 1 deletion pangea-sdk/v3/service/audit/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func treeSizes(root *Root, events SearchEvents) []string {
treeSizes[root.Size] = struct{}{}
for _, event := range events {
if event.LeafIndex != nil {
leafIdx := *event.LeafIndex
leafIdx := *event.LeafIndex + 1
treeSizes[leafIdx] = struct{}{}
if leafIdx > 1 {
treeSizes[leafIdx-1] = struct{}{}
Expand Down