Skip to content

Commit

Permalink
fix: resolve TODOs on claim
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Sep 5, 2024
1 parent 3b951fa commit 2156258
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/0xPolygon/cdk/config/types"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/tree"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ledgerwatch/erigon-lib/kv"
Expand Down Expand Up @@ -218,11 +219,11 @@ func convertBridgeToBridgeExit(bridge *bridgesync.Bridge) *agglayer.BridgeExit {
func convertClaimToImportedBridgeExit(claim *bridgesync.Claim, bridge *bridgesync.Bridge,
bridgeExit *agglayer.BridgeExit) *agglayer.ImportedBridgeExit {
return &agglayer.ImportedBridgeExit{
BridgeExit: bridgeExit,
// ImportedLocalExitRoot: claim.LocalExitRoot, TODO
InclusionProof: claim.ProofLocalExitRoot,
InclusionProofRER: claim.ProofRollupExitRoot,
GlobalIndex: claim.GlobalIndex,
BridgeExit: bridgeExit,
ImportedLocalExitRoot: tree.CalculateRoot(bridgeExit.Hash(), claim.ProofLocalExitRoot, uint32(claim.GlobalIndex.Uint64())),
InclusionProof: claim.ProofLocalExitRoot,
InclusionProofRER: claim.ProofRollupExitRoot,
GlobalIndex: claim.GlobalIndex,
}
}

Expand Down
17 changes: 17 additions & 0 deletions tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

dbCommon "github.com/0xPolygon/cdk/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ledgerwatch/erigon-lib/kv"
"golang.org/x/crypto/sha3"
)
Expand Down Expand Up @@ -298,3 +299,19 @@ func (t *Tree) GetLeaf(ctx context.Context, index uint32, root common.Hash) (com

return currentNodeHash, nil
}

// CalculateRoot calculates the Merkle Root based on the leaf and proof of inclusion
func CalculateRoot(leafHash common.Hash, proof [DefaultHeight]common.Hash, index uint32) common.Hash {
node := leafHash

// Compute the Merkle root
for height := uint8(0); height < DefaultHeight; height++ {
if (index>>height)&1 == 1 {
node = crypto.Keccak256Hash(proof[height].Bytes(), node.Bytes())
} else {
node = crypto.Keccak256Hash(node.Bytes(), proof[height].Bytes())
}
}

return node
}

0 comments on commit 2156258

Please sign in to comment.