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

feat: agg-sender #22

Merged
merged 88 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
bc38b5e
test: L2 to L1 withdrawal
vcastellm Oct 14, 2024
a5791ed
test: increase timeout
vcastellm Oct 15, 2024
d0e5501
Merge branch 'develop' into vcastellm/withdrawal-e2e
vcastellm Oct 18, 2024
710b200
faet: aggsender
goran-ethernal Oct 9, 2024
5ad8a9a
fix: update the api types
goran-ethernal Oct 9, 2024
bc6d69e
fix: ling
goran-ethernal Oct 9, 2024
323c970
fix: todos
goran-ethernal Oct 9, 2024
5df5b65
fix: running l2 detector with aggsender
goran-ethernal Oct 9, 2024
1f10dea
fix: l2client rpc url
goran-ethernal Oct 9, 2024
fcfa9b4
fix: add logs
goran-ethernal Oct 9, 2024
589dab5
feat: incorporate getCertificateHeader call
goran-ethernal Oct 9, 2024
d272d2e
feat: sql storage
goran-ethernal Oct 9, 2024
40fc599
feat: sql lite
goran-ethernal Oct 9, 2024
88df544
feat: unit tests
goran-ethernal Oct 9, 2024
14364b9
feat: more UTs
goran-ethernal Oct 9, 2024
1cb7f9e
feat: track certificates settlement
goran-ethernal Oct 9, 2024
6b82e64
fix: get last sent certificate
goran-ethernal Oct 9, 2024
5bce16a
fix: run l1client for aggsender
goran-ethernal Oct 9, 2024
01f2f87
feat: more unit tests
goran-ethernal Oct 9, 2024
ca7363e
feat: more unit tests
goran-ethernal Oct 9, 2024
6a7fcdc
fix: update sonar properties to exclude mocks
goran-ethernal Oct 9, 2024
0b331be
feat: even more unit tests
goran-ethernal Oct 10, 2024
5507297
fix: rebase
goran-ethernal Oct 10, 2024
9c9ba41
fix: small fixes
goran-ethernal Oct 16, 2024
7cce81f
fix: aggSender needs ReorgDetectorL1
joanestebanr Oct 16, 2024
f2a9ef7
fix: local/script support to AggSender
joanestebanr Oct 16, 2024
800ce50
fix: local/script support to AggSender
joanestebanr Oct 16, 2024
dcfa76e
fix: local/script support to AggSender
joanestebanr Oct 16, 2024
8d6447a
fix: block get interval
goran-ethernal Oct 17, 2024
df8ee93
fix: skip cmd and agglayer folders in sonar test coverage
goran-ethernal Oct 17, 2024
8c65487
fix: big ints as TEXT
goran-ethernal Oct 17, 2024
09ae71e
fix: skip agglayer and cmd part 2
goran-ethernal Oct 17, 2024
fb51b03
fix: rebase
goran-ethernal Oct 18, 2024
08a9b0d
fix: sonar analysis issues
goran-ethernal Oct 18, 2024
f9a6caf
feat: adapted to new config-file
joanestebanr Oct 18, 2024
4f8a3e7
fix: calculate GlobalExitRoot on a claim
goran-ethernal Oct 21, 2024
ec83005
fix: remove unnecessary read only txn on db
goran-ethernal Oct 21, 2024
8da0c73
fix: should send certificate
goran-ethernal Oct 21, 2024
718cd96
refactor: remove functions and test withdrawal
vcastellm Oct 21, 2024
c86e3b8
refactor: fixes
vcastellm Oct 21, 2024
f4e16e3
fix: comments
goran-ethernal Oct 22, 2024
313cf7f
fix: mocks to mocks folder
goran-ethernal Oct 22, 2024
9a76640
ci: adjust timeout
vcastellm Oct 22, 2024
3805e8a
ci: timeout and pless
vcastellm Oct 22, 2024
76e2de6
fix: raise condition on L2block beetween aggsender and l2bridgesync
joanestebanr Oct 22, 2024
57f943b
fix: lint
joanestebanr Oct 22, 2024
7029ba5
refactor: apply feedback
vcastellm Oct 22, 2024
d740003
ci: bump prover
vcastellm Oct 22, 2024
716d7e5
fix: error l1infotreesync.GetInfoByGlobalExitRoot
joanestebanr Oct 22, 2024
3bc59b3
fix: getRHTNode bug
joanestebanr Oct 22, 2024
4aeeae5
fix: unit test
goran-ethernal Oct 22, 2024
213139e
ci: try something
vcastellm Oct 22, 2024
899210c
ci: try
vcastellm Oct 22, 2024
2098a6b
ci: peek at bridge file
vcastellm Oct 23, 2024
f90062e
ci: upload logs
vcastellm Oct 23, 2024
9b2aead
fix: add to remove previous data
joanestebanr Oct 23, 2024
04f427a
fix: sqlite extesion for default db
joanestebanr Oct 23, 2024
ab08783
fix: allow to generate proof of partial tree
joanestebanr Oct 23, 2024
e81c6c1
Merge commit 'f90062e95b8654707a2052bf3b9fd26a3e0b77f4' into feat/agg…
goran-ethernal Oct 23, 2024
df721ec
fix: remove execution clients
goran-ethernal Oct 24, 2024
21680d8
fix: identantion and primary key
goran-ethernal Oct 24, 2024
d1e805a
fix: last certificate block
goran-ethernal Oct 24, 2024
335b156
fix: lastCertificateBlock
goran-ethernal Oct 24, 2024
a7c53ff
fix: certificate json format and new hash calculation
goran-ethernal Oct 24, 2024
948a59e
fix: remove unnecessary fields from config
goran-ethernal Oct 25, 2024
12b937b
feat: merge branch 'develop' into feat/agg-sender
joanestebanr Oct 25, 2024
3ea7d7d
fix: lint
joanestebanr Oct 25, 2024
9616ae1
feat: allow bridgeAsset with forceUpdateGlobalExitRoot=false (#140)
joanestebanr Oct 25, 2024
d47cb01
feat: GetBridgesPublished unit test
goran-ethernal Oct 25, 2024
d366571
feat: fix Certificate format
joanestebanr Oct 25, 2024
87ebc7c
fix: format of certificate
joanestebanr Oct 25, 2024
1834b98
fix: claims json format
goran-ethernal Oct 25, 2024
505a02c
fix: remove saveCertificate to json function
goran-ethernal Oct 25, 2024
68f067c
fix: certificate status unmarshal
goran-ethernal Oct 25, 2024
d42e71b
fix: first certificate height and LER
goran-ethernal Oct 28, 2024
424fb87
fix: proofs
goran-ethernal Oct 28, 2024
b6b80fd
fix: get last sent certificate
goran-ethernal Oct 28, 2024
80c9682
feat: add saveCertificate to file
joanestebanr Oct 28, 2024
f26c7ad
PR: fix PR comments
joanestebanr Oct 28, 2024
7318855
fix: comments and get imported bridge exits
goran-ethernal Oct 28, 2024
f5cd1f5
fix: merge develop
goran-ethernal Oct 28, 2024
c8ee26b
fix: ut and lint
goran-ethernal Oct 28, 2024
8cd9de3
feat: storing big.Int to db test
goran-ethernal Oct 29, 2024
dac23e4
feat: experimental test of different trees and proofs
goran-ethernal Oct 29, 2024
da64de8
fix: partial l1infotree
joanestebanr Oct 29, 2024
1f2d2b9
fix: use l1info root insetead of ger to generate merkleproof (#148)
arnaubennassar Oct 29, 2024
5c75104
fix: revert PR#140
joanestebanr Oct 30, 2024
b856c2d
fix: unittest
joanestebanr Oct 31, 2024
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
42 changes: 42 additions & 0 deletions aggregator/agglayer/agglayer_client.go → agglayer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var ErrAgglayerRateLimitExceeded = fmt.Errorf("agglayer rate limit exceeded")
type AgglayerClientInterface interface {
SendTx(signedTx SignedTx) (common.Hash, error)
WaitTxToBeMined(hash common.Hash, ctx context.Context) error
SendCertificate(certificate *SignedCertificate) (common.Hash, error)
GetCertificateHeader(certificateHash common.Hash) (*CertificateHeader, error)
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
}

// AggLayerClient is the client that will be used to interact with the AggLayer
Expand Down Expand Up @@ -86,3 +88,43 @@ func (c *AggLayerClient) WaitTxToBeMined(hash common.Hash, ctx context.Context)
}
}
}

// SendCertificate sends a certificate to the AggLayer
func (c *AggLayerClient) SendCertificate(certificate *SignedCertificate) (common.Hash, error) {
response, err := rpc.JSONRPCCall(c.url, "interop_sendCertificate", certificate)
if err != nil {
return common.Hash{}, err
}

if response.Error != nil {
return common.Hash{}, fmt.Errorf("%d %s", response.Error.Code, response.Error.Message)
}

var result types.ArgHash
err = json.Unmarshal(response.Result, &result)
if err != nil {
return common.Hash{}, err
}

return result.Hash(), nil
}

// GetCertificateHeader returns the certificate header associated to the hash
func (c *AggLayerClient) GetCertificateHeader(certificateHash common.Hash) (*CertificateHeader, error) {
response, err := rpc.JSONRPCCall(c.url, "interop_getCertificateHeader", certificateHash)
if err != nil {
return nil, err
}

if response.Error != nil {
return nil, fmt.Errorf("%d %s", response.Error.Code, response.Error.Message)
}

var result *CertificateHeader
err = json.Unmarshal(response.Result, &result)
if err != nil {
return nil, err
}

return result, nil
}
138 changes: 138 additions & 0 deletions agglayer/mock_agglayer_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
183 changes: 183 additions & 0 deletions agglayer/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package agglayer

import (
"fmt"
"math/big"

"github.com/0xPolygon/cdk/bridgesync"
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 CertificateStatus int

const (
Pending CertificateStatus = iota
InError
Settled
)

// String representation of the enum
func (c CertificateStatus) String() string {
return [...]string{"Pending", "InError", "Settled"}[c]
}

type LeafType uint8

func (l LeafType) Uint8() uint8 {
return uint8(l)
}

const (
LeafTypeAsset LeafType = iota
LeafTypeMessage
)

// 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 {
return crypto.Keccak256Hash(
cdkcommon.Uint32ToBytes(c.NetworkID),
cdkcommon.Uint64ToBytes(c.Height),
c.PrevLocalExitRoot.Bytes(),
c.NewLocalExitRoot.Bytes(),
)
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 {
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
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),
)
}

type MerkleProof struct {
Root common.Hash `json:"root"`
Proof [types.DefaultHeight]common.Hash `json:"proof"`
}

type L1InfoTreeLeafInner struct {
GlobalExitRoot common.Hash `json:"global_exit_root"`
BlockHash common.Hash `json:"block_hash"`
Timestamp uint64 `json:"timestamp"`
}

func (l L1InfoTreeLeafInner) Hash() common.Hash {
return crypto.Keccak256Hash(l.GlobalExitRoot.Bytes(), l.BlockHash.Bytes(), cdkcommon.Uint64ToBytes(l.Timestamp))
}

type L1InfoTreeLeaf struct {
L1InfoTreeIndex uint32 `json:"l1_info_tree_index"`
RollupExitRoot common.Hash `json:"rer"`
MainnetExitRoot common.Hash `json:"mer"`
Inner L1InfoTreeLeafInner `json:"inner"`
}

func (l L1InfoTreeLeaf) Hash() common.Hash {
return l.Inner.Hash()
}

type Claim interface {
Type() string
}

type ClaimFromMainnnet struct {
ProofLeafMER MerkleProof `json:"proof_leaf_mer"`
ProofGERToL1Root MerkleProof `json:"proof_ger_l1root"`
L1Leaf L1InfoTreeLeaf `json:"l1_leaf"`
}

func (c ClaimFromMainnnet) Type() string {
return "Mainnet"
}

type ClaimFromRollup struct {
ProofLeafLER MerkleProof `json:"proof_leaf_ler"`
ProofLERToRER MerkleProof `json:"proof_ler_rer"`
ProofGERToL1Root MerkleProof `json:"proof_ger_l1root"`
L1Leaf L1InfoTreeLeaf `json:"l1_leaf"`
}

func (c ClaimFromRollup) Type() string {
return "Rollup"
}

// ImportedBridgeExit represents a token bridge exit originating on another network but claimed on the current network.
type ImportedBridgeExit struct {
BridgeExit *BridgeExit `json:"bridge_exit"`
ClaimData Claim `json:"claim"`
GlobalIndex *GlobalIndex `json:"global_index"`
}

// Hash returns a hash that uniquely identifies the imported bridge exit
func (c *ImportedBridgeExit) Hash() common.Hash {
globalIndexBig := bridgesync.GenerateGlobalIndex(c.GlobalIndex.MainnetFlag,
c.GlobalIndex.RollupIndex, c.GlobalIndex.LeafIndex)
return crypto.Keccak256Hash(globalIndexBig.Bytes())
}

// CertificateHeader is the structure returned by the interop_getCertificateHeader RPC call
type CertificateHeader struct {
NetworkID uint32 `json:"network_id"`
Height uint64 `json:"height"`
EpochNumber *uint64 `json:"epoch_number"`
CertificateIndex *uint64 `json:"certificate_index"`
CertificateID common.Hash `json:"certificate_id"`
NewLocalExitRoot common.Hash `json:"new_local_exit_root"`
Status CertificateStatus `json:"status"`
}

func (c CertificateHeader) String() string {
return fmt.Sprintf("Height: %d, CertificateID: %s, NewLocalExitRoot: %s",
c.Height, c.CertificateID.String(), c.NewLocalExitRoot.String())
}
Loading
Loading