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

fix: use l1info root insetead of ger to generate merkleproof #148

Merged
merged 4 commits into from
Oct 29, 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
54 changes: 41 additions & 13 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,57 @@ func (a *AggSender) getBridgeExits(bridges []bridgesync.Bridge) []*agglayer.Brid
}

// getImportedBridgeExits converts claims to agglayer.ImportedBridgeExit objects and calculates necessary proofs
func (a *AggSender) getImportedBridgeExits(ctx context.Context,
claims []bridgesync.Claim) ([]*agglayer.ImportedBridgeExit, error) {
importedBridgeExits := make([]*agglayer.ImportedBridgeExit, 0, len(claims))

for i, claim := range claims {
a.log.Debugf("claim[%d]: destAddr: %s GER:%s", i, claim.DestinationAddress.String(), claim.GlobalExitRoot.String())
l1Info, err := a.l1infoTreeSyncer.GetInfoByGlobalExitRoot(claim.GlobalExitRoot)
func (a *AggSender) getImportedBridgeExits(
ctx context.Context, claims []bridgesync.Claim,
) ([]*agglayer.ImportedBridgeExit, error) {
if len(claims) == 0 {
// no claims to convert
return nil, nil
}

var (
greatestL1InfoTreeIndexUsed uint32
importedBridgeExits = make([]*agglayer.ImportedBridgeExit, 0, len(claims))
claimL1Info = make([]*l1infotreesync.L1InfoTreeLeaf, 0, len(claims))
)

for _, claim := range claims {
info, err := a.l1infoTreeSyncer.GetInfoByGlobalExitRoot(claim.GlobalExitRoot)
if err != nil {
return nil, fmt.Errorf("error getting info by global exit root: %w", err)
}

claimL1Info = append(claimL1Info, info)

if info.L1InfoTreeIndex > greatestL1InfoTreeIndexUsed {
greatestL1InfoTreeIndexUsed = info.L1InfoTreeIndex
}
}

rootToProve, err := a.l1infoTreeSyncer.GetL1InfoTreeRootByIndex(ctx, greatestL1InfoTreeIndexUsed)
if err != nil {
return nil, fmt.Errorf("error getting L1 Info tree root by index: %d. Error: %w", greatestL1InfoTreeIndexUsed, err)
}

for i, claim := range claims {
l1Info := claimL1Info[i]

a.log.Debugf("claim[%d]: destAddr: %s GER:%s", i, claim.DestinationAddress.String(), claim.GlobalExitRoot.String())
ibe, err := a.convertClaimToImportedBridgeExit(claim)
if err != nil {
return nil, fmt.Errorf("error converting claim to imported bridge exit: %w", err)
}

importedBridgeExits = append(importedBridgeExits, ibe)

gerToL1Proof, err := a.l1infoTreeSyncer.GetL1InfoTreeMerkleProofFromIndexToRoot(ctx,
l1Info.L1InfoTreeIndex, l1Info.GlobalExitRoot)
gerToL1Proof, err := a.l1infoTreeSyncer.GetL1InfoTreeMerkleProofFromIndexToRoot(
ctx, l1Info.L1InfoTreeIndex, rootToProve.Hash,
)
if err != nil {
return nil, fmt.Errorf("error getting L1 Info tree merkle proof for leaf index: %d. GER: %s. Error: %w",
l1Info.L1InfoTreeIndex, l1Info.GlobalExitRoot, err)
return nil, fmt.Errorf(
"error getting L1 Info tree merkle proof for leaf index: %d and root: %s. Error: %w",
l1Info.L1InfoTreeIndex, rootToProve.Hash, err,
)
}

claim := claims[i]
Expand All @@ -347,7 +375,7 @@ func (a *AggSender) getImportedBridgeExits(ctx context.Context,
Proof: claim.ProofLocalExitRoot,
},
ProofGERToL1Root: &agglayer.MerkleProof{
Root: l1Info.GlobalExitRoot,
Root: rootToProve.Hash,
Proof: gerToL1Proof,
},
}
Expand All @@ -372,7 +400,7 @@ func (a *AggSender) getImportedBridgeExits(ctx context.Context,
Proof: claim.ProofRollupExitRoot,
},
ProofGERToL1Root: &agglayer.MerkleProof{
Root: l1Info.GlobalExitRoot,
Root: rootToProve.Hash,
Proof: gerToL1Proof,
},
}
Expand Down
Loading
Loading