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: e2e test Pesimisstic L2 to L2 claim #239

Merged
merged 39 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aa572c0
chore: simplify the `HashMeddler` (#205)
Stefan-Ethernal Nov 29, 2024
e8ba6b9
feat: return an error in case agglayer returns certificate with heigh…
Stefan-Ethernal Nov 29, 2024
5ab4a04
feat: limit cert by estimated size (#217)
joanestebanr Dec 3, 2024
5fe8671
bump DAC (#218)
rachit77 Dec 3, 2024
c84df07
feat: cherry pick PR 229 to release (#233)
goran-ethernal Dec 6, 2024
7f8dd00
feat: use the `GenericError` for all the errors originating from the …
Stefan-Ethernal Dec 9, 2024
61db2b1
fix: calculate correct root for `LER` merkle proof and fix `BridgeExi…
goran-ethernal Dec 10, 2024
c684718
feat: wip
joanestebanr Dec 10, 2024
2b1a61d
feat: wip, still missing test certificate
joanestebanr Dec 11, 2024
96b7f5d
feat: wip, fix polycli
joanestebanr Dec 11, 2024
4f1c47f
feat: wip
joanestebanr Dec 11, 2024
152167b
feat: wip
joanestebanr Dec 11, 2024
d1ade90
feat: wip
joanestebanr Dec 12, 2024
32af660
feat: fix cert error
joanestebanr Dec 12, 2024
a80eba1
feat: wip
joanestebanr Dec 12, 2024
922b0f1
fix: e2e
joanestebanr Dec 12, 2024
41594ae
feat: sometimes fails the claim of L2->L2 with GlobalExitRootInvalid(…
joanestebanr Dec 16, 2024
6d1f19e
feat: RPC for aggsender,previous component RPC is called BRIDGE
joanestebanr Dec 16, 2024
1a51719
feat: improve bats
joanestebanr Dec 17, 2024
0605d97
feat: support unmarshal for certificate
joanestebanr Dec 17, 2024
46523ea
feat: add aggsender RPC
joanestebanr Dec 17, 2024
4dac97c
feat: increase coverage
joanestebanr Dec 18, 2024
41e0001
feat: add tools
joanestebanr Dec 18, 2024
39582d3
feat: integrate aggsender_find_imported_bridgeto e2e
joanestebanr Dec 18, 2024
cc232e4
fix: e2e
joanestebanr Dec 18, 2024
94d5dda
fix: e2e
joanestebanr Dec 18, 2024
ce1e5e5
feat: exclude tools from sonarcloud
joanestebanr Dec 19, 2024
759cabf
feat: increase coverage
joanestebanr Dec 19, 2024
a36f31b
feat: increase coverage
joanestebanr Dec 19, 2024
c2748ec
fix: lint
joanestebanr Dec 19, 2024
77d5fcf
fix: rebase errors
joanestebanr Dec 19, 2024
c465e2d
feat: add more info to RPC status
joanestebanr Dec 19, 2024
51af863
fix: PR comments
joanestebanr Dec 19, 2024
adb73d1
fix: unittest
joanestebanr Dec 19, 2024
98c2e9f
fix: e2e
joanestebanr Dec 19, 2024
1fb05b8
fix: PR comments
joanestebanr Dec 20, 2024
78724d2
fix: PR comments
joanestebanr Dec 20, 2024
8113e91
fix: PR comments
joanestebanr Dec 20, 2024
0638b0b
PR: comments
joanestebanr Dec 20, 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
85 changes: 85 additions & 0 deletions .github/workflows/test-e2e-multi_pp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# based on: https://github.com/0xPolygon/kurtosis-cdk/blob/jhilliard/multi-pp-testing/multi-pp-test.sh.md
name: Test e2e multi pp
on:
push:
branches:
- '**'
workflow_dispatch: {}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: remove extra empty line

Suggested change

jobs:
test-e2e-multi_pp:
strategy:
fail-fast: false
matrix:
go-version: [ 1.22.x ]
goarch: [ "amd64" ]
e2e-group:
- "fork12-pessimistic"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
env:
GOARCH: ${{ matrix.goarch }}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, remove extra blank line

Suggested change


- name: Build Docker
run: make build-docker

- name: Build Tools
run: make build-tools

- name: Checkout kurtosis-cdk
uses: actions/checkout@v4
with:
repository: 0xPolygon/kurtosis-cdk
path: kurtosis-cdk
ref: jhilliard/multi-pp-testing

- name: Install Kurtosis CDK tools
uses: ./kurtosis-cdk/.github/actions/setup-kurtosis-cdk

- name: Install polycli
run: |
git clone https://github.com/0xPolygon/polygon-cli -b jhilliard/alonso
cd polygon-cli
make install
cp ~/go/bin/polycli /usr/local/bin/polycli
/usr/local/bin/polycli version

- name: Setup Bats and bats libs
uses: bats-core/[email protected]

- name: Test
run: make test-e2e-fork12-multi-pessimistic

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

working-directory: test
env:
KURTOSIS_FOLDER: ${{ github.workspace }}/kurtosis-cdk
BATS_LIB_PATH: /usr/lib/
agglayer_prover_sp1_key: ${{ secrets.SP1_PRIVATE_KEY }}

- name: Dump enclave logs
if: failure()
run: kurtosis dump ./dump

- name: Generate archive name
if: failure()
run: |
archive_name="dump_run_with_args_${{matrix.e2e-group}}_${{ github.run_id }}"
echo "ARCHIVE_NAME=${archive_name}" >> "$GITHUB_ENV"
echo "Generated archive name: ${archive_name}"
kurtosis service exec cdk cdk-node-001 'cat /etc/cdk/cdk-node-config.toml' > ./dump/cdk-node-config.toml

- name: Upload logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ./dump
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN go mod download

# BUILD BINARY
COPY . .
RUN make build-go
RUN make build-go build-tools

# BUILD RUST BIN
FROM --platform=${BUILDPLATFORM} rust:slim-bookworm AS chef
Expand Down Expand Up @@ -46,4 +46,6 @@ RUN apt-get update && apt-get install -y ca-certificates sqlite3 procps libssl-d
COPY --from=builder /app/target/release/cdk /usr/local/bin/
COPY --from=build /go/src/github.com/0xPolygon/cdk/target/cdk-node /usr/local/bin/

EXPOSE 5576/tcp
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved

CMD ["/bin/sh", "-c", "cdk"]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ install-linter: check-go check-curl
generate-code-from-proto: check-protoc

.PHONY: build
build: build-rust build-go ## Builds the binaries locally into ./target
build: build-rust build-go build-tools## Builds the binaries locally into ./target
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build: build-rust build-go build-tools## Builds the binaries locally into ./target
build: build-rust build-go build-tools ## Builds the binaries locally into ./target


.PHONY: build-rust
build-rust:
Expand All @@ -66,6 +66,10 @@ build-rust:
build-go:
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)

.PHONY: build-tools
build-tools: ## Builds the tools
$(GOENVVARS) go build -o $(GOBIN)/aggsender_find_imported_bridge ./tools/aggsender_find_imported_bridge

.PHONY: build-docker
build-docker: ## Builds a docker image with the cdk binary
docker build -t cdk -f ./Dockerfile .
Expand Down
178 changes: 175 additions & 3 deletions agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const (
InError
Settled

nilStr = "nil"
nilStr = "nil"
nullStr = "null"
base10 = 10
)

var (
Expand Down Expand Up @@ -77,7 +79,13 @@ func (c *CertificateStatus) UnmarshalJSON(rawStatus []byte) error {
case "Settled":
*c = Settled
default:
return fmt.Errorf("invalid status: %s", status)
// Maybe the status is numeric:
var statusInt int
if _, err := fmt.Sscanf(status, "%d", &statusInt); err == nil {
*c = CertificateStatus(statusInt)
} else {
return fmt.Errorf("invalid status: %s", status)
}
}

return nil
Expand All @@ -93,6 +101,24 @@ func (l LeafType) String() string {
return [...]string{"Transfer", "Message"}[l]
}

func (l *LeafType) UnmarshalJSON(raw []byte) error {
rawStr := strings.Trim(string(raw), "\"")
switch rawStr {
case "Transfer":
*l = LeafTypeAsset
case "Message":
*l = LeafTypeMessage
default:
var value int
if _, err := fmt.Sscanf(rawStr, "%d", &value); err == nil {
*l = LeafType(value)
} else {
return fmt.Errorf("invalid LeafType: %s", rawStr)
}
}
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

const (
LeafTypeAsset LeafType = iota
LeafTypeMessage
Expand Down Expand Up @@ -333,6 +359,44 @@ func (b *BridgeExit) MarshalJSON() ([]byte, error) {
})
}

func (b *BridgeExit) UnmarshalJSON(data []byte) error {
aux := &struct {
LeafType LeafType `json:"leaf_type"`
TokenInfo *TokenInfo `json:"token_info"`
DestinationNetwork uint32 `json:"dest_network"`
DestinationAddress common.Address `json:"dest_address"`
Amount string `json:"amount"`
Metadata interface{} `json:"metadata"`
}{}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}
b.LeafType = aux.LeafType
b.TokenInfo = aux.TokenInfo
b.DestinationNetwork = aux.DestinationNetwork
b.DestinationAddress = aux.DestinationAddress
b.Amount, _ = new(big.Int).SetString(aux.Amount, base10)
if s, ok := aux.Metadata.(string); ok {
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
b.IsMetadataHashed = true
b.Metadata = common.Hex2Bytes(s)
} else if uints, ok := aux.Metadata.([]interface{}); ok {
b.IsMetadataHashed = false
b.Metadata = make([]byte, len(uints))
for k, v := range uints {
value, ok := v.(float64)
if !ok {
return fmt.Errorf("failed to convert metadata to byte: %v", v)
}
b.Metadata[k] = byte(value)
}
} else {
b.Metadata = nil
}
return nil
}

// bytesToUints converts a byte slice to a slice of uints
func bytesToUints(data []byte) []uint {
uints := make([]uint, len(data))
Expand Down Expand Up @@ -361,6 +425,21 @@ func (m *MerkleProof) MarshalJSON() ([]byte, error) {
})
}

func (m *MerkleProof) UnmarshalJSON(data []byte) error {
aux := &struct {
Root common.Hash `json:"root"`
Proof map[string][types.DefaultHeight]common.Hash `json:"proof"`
}{}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}
m.Root = aux.Root
m.Proof = aux.Proof["siblings"]
return nil
}

// Hash returns the hash of the Merkle proof struct
func (m *MerkleProof) Hash() common.Hash {
proofsAsSingleSlice := make([]byte, 0)
Expand Down Expand Up @@ -455,6 +534,29 @@ func (c *ClaimFromMainnnet) MarshalJSON() ([]byte, error) {
})
}

func (c *ClaimFromMainnnet) UnmarshalJSON(data []byte) error {
if string(data) == nullStr {
return nil
}

claimData := &struct {
Child struct {
ProofLeafMER *MerkleProof `json:"proof_leaf_mer"`
ProofGERToL1Root *MerkleProof `json:"proof_ger_l1root"`
L1Leaf *L1InfoTreeLeaf `json:"l1_leaf"`
} `json:"Mainnet"`
}{}
err := json.Unmarshal(data, &claimData)
if err != nil {
return fmt.Errorf("failed to unmarshal the subobject: %w", err)
}
c.ProofLeafMER = claimData.Child.ProofLeafMER
c.ProofGERToL1Root = claimData.Child.ProofGERToL1Root
c.L1Leaf = claimData.Child.L1Leaf

return nil
}

// Hash is the implementation of Claim interface
func (c *ClaimFromMainnnet) Hash() common.Hash {
return crypto.Keccak256Hash(
Expand Down Expand Up @@ -496,6 +598,31 @@ func (c *ClaimFromRollup) MarshalJSON() ([]byte, error) {
})
}

func (c *ClaimFromRollup) UnmarshalJSON(data []byte) error {
if string(data) == nullStr {
return nil
}

claimData := &struct {
Child struct {
ProofLeafLER *MerkleProof `json:"proof_leaf_ler"`
ProofLERToRER *MerkleProof `json:"proof_ler_rer"`
ProofGERToL1Root *MerkleProof `json:"proof_ger_l1root"`
L1Leaf *L1InfoTreeLeaf `json:"l1_leaf"`
} `json:"Rollup"`
}{}
err := json.Unmarshal(data, &claimData)
if err != nil {
return fmt.Errorf("failed to unmarshal the subobject: %w", err)
}
c.ProofLeafLER = claimData.Child.ProofLeafLER
c.ProofLERToRER = claimData.Child.ProofLERToRER
c.ProofGERToL1Root = claimData.Child.ProofGERToL1Root
c.L1Leaf = claimData.Child.L1Leaf

return nil
}

// Hash is the implementation of Claim interface
func (c *ClaimFromRollup) Hash() common.Hash {
return crypto.Keccak256Hash(
Expand All @@ -511,6 +638,35 @@ func (c *ClaimFromRollup) String() string {
c.ProofLeafLER.String(), c.ProofLERToRER.String(), c.ProofGERToL1Root.String(), c.L1Leaf.String())
}

type ClaimSelector struct {
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
obj Claim
}

func (c *ClaimSelector) GetObject() Claim {
return c.obj
}

func (c *ClaimSelector) UnmarshalJSON(data []byte) error {
var obj map[string]interface{}
if string(data) == nullStr {
return nil
}
err := json.Unmarshal(data, &obj)
if err != nil {
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
return err
}
var ok bool
if _, ok = obj["Mainnet"]; ok {
c.obj = &ClaimFromMainnnet{}
} else if _, ok = obj["Rollup"]; ok {
c.obj = &ClaimFromRollup{}
} else {
return errors.New("invalid claim type")
}

return json.Unmarshal(data, &c.obj)
}

// ImportedBridgeExit represents a token bridge exit originating on another network but claimed on the current network.
type ImportedBridgeExit struct {
BridgeExit *BridgeExit `json:"bridge_exit"`
Expand Down Expand Up @@ -538,6 +694,22 @@ func (c *ImportedBridgeExit) String() string {
return res
}

func (c *ImportedBridgeExit) UnmarshalJSON(data []byte) error {
aux := &struct {
BridgeExit *BridgeExit `json:"bridge_exit"`
ClaimData ClaimSelector `json:"claim_data"`
GlobalIndex *GlobalIndex `json:"global_index"`
}{}
err := json.Unmarshal(data, &aux)
if err != nil {
return err
}
c.BridgeExit = aux.BridgeExit
c.ClaimData = aux.ClaimData.GetObject()
c.GlobalIndex = aux.GlobalIndex
return nil
}

// Hash returns a hash that uniquely identifies the imported bridge exit
func (c *ImportedBridgeExit) Hash() common.Hash {
return crypto.Keccak256Hash(
Expand Down Expand Up @@ -592,7 +764,7 @@ func (c *CertificateHeader) String() string {
if c.PreviousLocalExitRoot != nil {
previousLocalExitRoot = c.PreviousLocalExitRoot.String()
}
return fmt.Sprintf("Height: %d, CertificateID: %s, previousLocalExitRoot:%s, NewLocalExitRoot: %s. Status: %s."+
return fmt.Sprintf("Height: %d, CertificateID: %s, PreviousLocalExitRoot: %s, NewLocalExitRoot: %s. Status: %s."+
" Errors: [%s]",
c.Height, c.CertificateID.String(), previousLocalExitRoot, c.NewLocalExitRoot.String(), c.Status.String(), errors)
}
Expand Down
15 changes: 15 additions & 0 deletions agglayer/types_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package agglayer

import (
"fmt"
"testing"

"github.com/0xPolygon/cdk/tree/types"
"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -54,3 +56,16 @@ func createDummyClaim(t *testing.T) *ClaimFromMainnnet {
},
}
}

// Helper function to create a dummy proof
func createDummyProof(t *testing.T) types.Proof {
t.Helper()

proof := types.Proof{}

for i := 0; i < int(types.DefaultHeight); i++ {
proof[i] = common.HexToHash(fmt.Sprintf("0x%x", i))
}

return proof
}
Loading
Loading