-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expand config fix: nothing to send feat: use finality as the syncer fix: rebase feat: add sequencer private key to config fix: add new fields fix: config fix: merge fix fix: remove ImportedExitRoots field feat: build certificates for L1 as well feat: set previous and new exit root in certificate fix: reorg detector for both l1 and l2 fix: rebase feat: add aggsender to run cmd feat: sign certificate POC feat: latest spec types fix: update comments fix: resolve TODOs on claim fix: height fix: rebase feat: new changes fix: lint
- Loading branch information
1 parent
db81a26
commit e7c7d70
Showing
20 changed files
with
699 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package aggregator | ||
package agglayer | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package agglayer | ||
|
||
import ( | ||
"math/big" | ||
|
||
cdkcommon "github.com/0xPolygon/cdk/common" | ||
"github.com/0xPolygon/cdk/tree/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
type LeafType uint8 | ||
|
||
func (l LeafType) Uint8() uint8 { | ||
return uint8(l) | ||
} | ||
|
||
const ( | ||
LeafTypeAsset LeafType = 0 | ||
LeafTypeMessage LeafType = 1 | ||
) | ||
|
||
// Certificate is the data structure that will be sent to the aggLayer | ||
type Certificate struct { | ||
NetworkID uint32 `json:"network_id"` | ||
Height uint64 `json:"height"` | ||
PrevLocalExitRoot common.Hash `json:"prev_local_exit_root"` | ||
NewLocalExitRoot common.Hash `json:"new_local_exit_root"` | ||
BridgeExits []*BridgeExit `json:"bridge_exits"` | ||
ImportedBridgeExits []*ImportedBridgeExit `json:"imported_bridge_exits"` | ||
} | ||
|
||
// Hash returns a hash that uniquely identifies the certificate | ||
func (c *Certificate) Hash() common.Hash { | ||
importedBridgeHashes := make([][]byte, 0, len(c.ImportedBridgeExits)) | ||
for _, claim := range c.ImportedBridgeExits { | ||
importedBridgeHashes = append(importedBridgeHashes, claim.Hash().Bytes()) | ||
} | ||
|
||
incomeCommitment := crypto.Keccak256Hash(importedBridgeHashes...) | ||
outcomeCommitment := c.NewLocalExitRoot | ||
|
||
return crypto.Keccak256Hash(outcomeCommitment.Bytes(), incomeCommitment.Bytes()) | ||
} | ||
|
||
// SignedCertificate is the struct that contains the certificate and the signature of the signer | ||
type SignedCertificate struct { | ||
*Certificate | ||
Signature []byte `json:"signature"` | ||
} | ||
|
||
// TokenInfo encapsulates the information to uniquely identify a token on the origin network. | ||
type TokenInfo struct { | ||
OriginNetwork uint32 `json:"origin_network"` | ||
OriginTokenAddress common.Address `json:"origin_token_address"` | ||
} | ||
|
||
// GlobalIndex represents the global index of an imported bridge exit | ||
type GlobalIndex struct { | ||
MainnetFlag bool `json:"mainnet_flag"` | ||
RollupIndex uint32 `json:"rollup_index"` | ||
LeafIndex uint32 `json:"leaf_index"` | ||
} | ||
|
||
// BridgeExit represents a token bridge exit | ||
type BridgeExit struct { | ||
LeafType LeafType `json:"leaf_type"` | ||
TokenInfo *TokenInfo `json:"token_info"` | ||
DestinationNetwork uint32 `json:"destination_network"` | ||
DestinationAddress common.Address `json:"destination_address"` | ||
Amount *big.Int `json:"amount"` | ||
Metadata []byte `json:"metadata"` | ||
} | ||
|
||
// Hash returns a hash that uniquely identifies the bridge exit | ||
func (c *BridgeExit) Hash() common.Hash { | ||
if c.Amount == nil { | ||
c.Amount = big.NewInt(0) | ||
} | ||
|
||
return crypto.Keccak256Hash( | ||
[]byte{c.LeafType.Uint8()}, | ||
cdkcommon.Uint32ToBytes(c.TokenInfo.OriginNetwork), | ||
c.TokenInfo.OriginTokenAddress.Bytes(), | ||
cdkcommon.Uint32ToBytes(c.DestinationNetwork), | ||
c.DestinationAddress.Bytes(), | ||
c.Amount.Bytes(), | ||
crypto.Keccak256(c.Metadata), | ||
) | ||
} | ||
|
||
// ImportedBridgeExit represents a token bridge exit originating on another network but claimed on the current network. | ||
type ImportedBridgeExit struct { | ||
BridgeExit *BridgeExit `json:"bridge_exit"` | ||
ImportedLocalExitRoot common.Hash `json:"imported_local_exit_root"` | ||
InclusionProof [types.DefaultHeight]common.Hash `json:"inclusion_proof"` | ||
InclusionProofRER [types.DefaultHeight]common.Hash `json:"inclusion_proof_rer"` | ||
GlobalIndex *GlobalIndex `json:"global_index"` | ||
} | ||
|
||
// Hash returns a hash that uniquely identifies the imported bridge exit | ||
func (c *ImportedBridgeExit) Hash() common.Hash { | ||
return c.BridgeExit.Hash() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.