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

imp: eth light client and relayer sepolia support #394

Merged
merged 69 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
aeaabf7
start add back rust-fixtures
gjermundgaraba Mar 4, 2025
1fba026
feat: electra support in eth lc
gjermundgaraba Mar 7, 2025
c592721
Merge branch 'gjermund/rust-fixtures' into gjermund/electra
gjermundgaraba Mar 7, 2025
266bf5f
imp: electra support
gjermundgaraba Mar 7, 2025
e36d100
Merge remote-tracking branch 'origin/main' into gjermund/electra
gjermundgaraba Mar 7, 2025
5ab4608
update lc
gjermundgaraba Mar 7, 2025
9840fcb
add back rust tests
gjermundgaraba Mar 8, 2025
bfb5d1a
fixes
gjermundgaraba Mar 8, 2025
157bb85
fix nil pointer for multichain tests
gjermundgaraba Mar 8, 2025
f6d3d99
mainnet config wtf
gjermundgaraba Mar 8, 2025
a212a5c
relayer and lc fixes
gjermundgaraba Mar 9, 2025
25be894
more fixes
gjermundgaraba Mar 9, 2025
79a430f
add genesis script
gjermundgaraba Mar 9, 2025
cabe9c1
insert anakin it's working meme here
gjermundgaraba Mar 10, 2025
9ccebc0
cleanup
gjermundgaraba Mar 10, 2025
5a3d2a2
remove ethgenesis script (moved to other branch)
gjermundgaraba Mar 10, 2025
69fce2b
added some more logs
gjermundgaraba Mar 10, 2025
2a3031d
add back ethgenesis script
gjermundgaraba Mar 10, 2025
92ea58c
Merge remote-tracking branch 'origin/main' into gjermund/sepolia
gjermundgaraba Mar 10, 2025
e332e75
did I just make it?
gjermundgaraba Mar 11, 2025
5cc573a
Merge remote-tracking branch 'origin/main' into gjermund/sepolia
gjermundgaraba Mar 11, 2025
4eebcb0
working commit
gjermundgaraba Mar 11, 2025
d6916cb
fix justfile
gjermundgaraba Mar 11, 2025
c0fcc87
update checksum in ethgenesis
gjermundgaraba Mar 11, 2025
6fff846
fix eth genesis script
gjermundgaraba Mar 11, 2025
3863218
fix build error
gjermundgaraba Mar 11, 2025
bba13d1
fix the ethgenesis script again
gjermundgaraba Mar 11, 2025
8e2221e
fix justfile
gjermundgaraba Mar 11, 2025
406429c
wasm fixtures
gjermundgaraba Mar 11, 2025
13baa30
update checksum
gjermundgaraba Mar 11, 2025
081dd30
try something real quick
gjermundgaraba Mar 11, 2025
b2efafd
test1
gjermundgaraba Mar 11, 2025
a91eaee
test1.2
gjermundgaraba Mar 11, 2025
081c684
test2
gjermundgaraba Mar 11, 2025
697c1e2
test3
gjermundgaraba Mar 11, 2025
75e8983
test4
gjermundgaraba Mar 11, 2025
41f8364
test5
gjermundgaraba Mar 11, 2025
b52d8d8
crazy test
gjermundgaraba Mar 11, 2025
6d2ebf4
fix build
gjermundgaraba Mar 11, 2025
59c738e
try something
gjermundgaraba Mar 11, 2025
7ac23ca
new client to test
gjermundgaraba Mar 11, 2025
f1a6129
event type
gjermundgaraba Mar 11, 2025
3ebbe0c
remove debug file
gjermundgaraba Mar 11, 2025
41c4f36
lint
gjermundgaraba Mar 12, 2025
ca74884
Merge remote-tracking branch 'origin/main' into gjermund/sepolia
gjermundgaraba Mar 12, 2025
558b3ef
add heights from tm events
gjermundgaraba Mar 12, 2025
fa290de
code review fixes
gjermundgaraba Mar 12, 2025
7bf8b9d
use trait in TxBuilder
gjermundgaraba Mar 12, 2025
639d73c
code review fixes
gjermundgaraba Mar 12, 2025
abfaae5
clean up wait for finality
gjermundgaraba Mar 13, 2025
682f3c6
fix minimum block number
gjermundgaraba Mar 13, 2025
aac305c
code review fixes
gjermundgaraba Mar 13, 2025
b4a8353
rebuild light client
gjermundgaraba Mar 13, 2025
89d7af3
docs: fix error string
srdtrk Mar 13, 2025
1143687
fix: clippy complaint
srdtrk Mar 13, 2025
dceab5d
style
srdtrk Mar 13, 2025
2976eaa
style
srdtrk Mar 13, 2025
7fccf8d
code review fixes + fixtures
gjermundgaraba Mar 13, 2025
61efb1c
style: imp
srdtrk Mar 13, 2025
12c7ba3
fix fetch events
gjermundgaraba Mar 13, 2025
d938e07
code review fixes
gjermundgaraba Mar 13, 2025
18340b5
more code review fixes
gjermundgaraba Mar 13, 2025
a735559
imp: more additions
srdtrk Mar 13, 2025
44d7ad2
lint
gjermundgaraba Mar 13, 2025
fd4aabc
Merge remote-tracking branch 'origin/gjermund/sepolia' into gjermund/…
srdtrk Mar 13, 2025
9e4b8f9
imp
srdtrk Mar 13, 2025
b5813f1
Merge remote-tracking branch 'origin/gjermund/sepolia' into gjermund/…
srdtrk Mar 13, 2025
ff030c2
add wasm fixture for multi period update client
gjermundgaraba Mar 13, 2025
4552820
imp: remove unneeded clone
srdtrk Mar 13, 2025
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
494 changes: 362 additions & 132 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ ibc-core-commitment-types = { version = "0.57", default-features = false }
ibc-core-handler-types = { version = "0.57", default-features = false }
ibc-client-tendermint-types = { version = "0.57", default-features = false }

alloy = { version = "0.11", default-features = false }
alloy-contract = { version = "0.11", default-features = false }
alloy = { version = "0.12", default-features = false }
alloy-contract = { version = "0.12", default-features = false }
alloy-sol-types = { version = "0.8", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
alloy-serde = { version = "0.11", default-features = false }
alloy-network = { version = "0.11", default-features = false }
alloy-signer-local = { version = "0.11", default-features = false }
alloy-serde = { version = "0.12", default-features = false }
alloy-network = { version = "0.12", default-features = false }
alloy-signer-local = { version = "0.12", default-features = false }
alloy-rlp = { version = "0.3", default-features = false }
alloy-provider = { version = "0.11", default-features = false }
alloy-transport = { version = "0.11", default-features = false }
alloy-rpc-types-eth = { version = "0.11", default-features = false }
alloy-provider = { version = "0.12", default-features = false }
alloy-transport = { version = "0.12", default-features = false }
alloy-rpc-types-eth = { version = "0.12", default-features = false }

sp1-sdk = { version = "4.1", default-features = false }
sp1-prover = { version = "4.1", default-features = false }
Expand Down
22 changes: 12 additions & 10 deletions e2e/interchaintestv8/chainconfig/kurtosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ var (
kurtosisConfig = kurtosisNetworkParams{
Participants: []kurtosisParticipant{
{
CLType: "lodestar",
CLImage: "ethpandaops/lodestar:devnet-5-1c2b5ed",
ELType: "geth",
ELImage: "ethpandaops/geth:prague-devnet-5-a193537",
ELLogLevel: "info",
CLType: "lodestar",
CLImage: "ethpandaops/lodestar:unstable",
ELType: "geth",
ELImage: "ethpandaops/geth:prague-devnet-6",
ELLogLevel: "info",
ValidatorCount: 64,
},
},
NetworkParams: kurtosisNetworkConfigParams{
Expand Down Expand Up @@ -65,11 +66,12 @@ type kurtosisNetworkParams struct {
}

type kurtosisParticipant struct {
CLType string `json:"cl_type"`
CLImage string `json:"cl_image"`
ELType string `json:"el_type"`
ELImage string `json:"el_image"`
ELLogLevel string `json:"el_log_level"`
CLType string `json:"cl_type"`
CLImage string `json:"cl_image"`
ELType string `json:"el_type"`
ELImage string `json:"el_image"`
ELLogLevel string `json:"el_log_level"`
ValidatorCount uint64 `json:"validator_count"`
}

type kurtosisNetworkConfigParams struct {
Expand Down
38 changes: 24 additions & 14 deletions e2e/interchaintestv8/e2esuite/light_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

ethcommon "github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -55,20 +54,32 @@ func (s *TestSuite) createEthereumLightClient(
spec, err := eth.BeaconAPIClient.GetSpec()
s.Require().NoError(err)

executionHeight, err := eth.BeaconAPIClient.GetExecutionHeight("finalized")
beaconBlock, err := eth.BeaconAPIClient.GetBeaconBlocks("finalized")
s.Require().NoError(err)

executionHeight := beaconBlock.Data.Message.Body.ExecutionPayload.BlockNumber
executionNumberHex := fmt.Sprintf("0x%x", executionHeight)

header, err := eth.BeaconAPIClient.GetHeader(beaconBlock.Data.Message.Slot)
s.Require().NoError(err)

bootstrap, err := eth.BeaconAPIClient.GetBootstrap(header.Root)
s.Require().NoError(err)
s.Require().Equal(executionHeight, bootstrap.Data.Header.Execution.BlockNumber)

latestSlot := bootstrap.Data.Header.Beacon.Slot

ethClientState := ethereumtypes.ClientState{
ChainID: eth.ChainID.Uint64(),
GenesisValidatorsRoot: ethcommon.Bytes2Hex(genesis.GenesisValidatorsRoot[:]),
MinSyncCommitteeParticipants: 32,
GenesisTime: uint64(genesis.GenesisTime.Unix()),
GenesisSlot: spec.GenesisSlot,
ForkParameters: spec.ToForkParameters(),
SecondsPerSlot: uint64(spec.SecondsPerSlot.Seconds()),
SlotsPerEpoch: spec.SlotsPerEpoch,
EpochsPerSyncCommitteePeriod: spec.EpochsPerSyncCommitteePeriod,
LatestSlot: executionHeight,
LatestSlot: latestSlot,
IsFrozen: false,
IbcCommitmentSlot: testvalues.IbcCommitmentSlotHex,
IbcContractAddress: ibcContractAddress,
Expand All @@ -93,21 +104,14 @@ func (s *TestSuite) createEthereumLightClient(
proofOfIBCContract, err := eth.EthAPI.GetProof(ibcContractAddress, []string{ics26router.IbcStoreStorageSlot}, executionNumberHex)
s.Require().NoError(err)

header, err := eth.BeaconAPIClient.GetHeader(strconv.Itoa(int(executionHeight)))
s.Require().NoError(err)
bootstrap, err := eth.BeaconAPIClient.GetBootstrap(header.Root)
s.Require().NoError(err)

if bootstrap.Data.Header.Beacon.Slot != executionHeight {
s.Require().Fail(fmt.Sprintf("creating client: expected exec height %d, to equal boostrap slot %d", executionHeight, bootstrap.Data.Header.Beacon.Slot))
}

unixTimestamp := bootstrap.Data.Header.Execution.Timestamp

currentPeriod := executionHeight / spec.Period()
currentPeriod := latestSlot / spec.Period()
clientUpdates, err := eth.BeaconAPIClient.GetLightClientUpdates(currentPeriod, 1)
s.Require().NoError(err)
s.Require().NotEmpty(clientUpdates)
s.Require().Len(clientUpdates, 1)

fmt.Println("Current period:", currentPeriod)

ethConsensusState := ethereumtypes.ConsensusState{
Slot: bootstrap.Data.Header.Beacon.Slot,
Expand All @@ -120,6 +124,9 @@ func (s *TestSuite) createEthereumLightClient(

ethConsensusStateBz, err := json.Marshal(&ethConsensusState)
s.Require().NoError(err)

fmt.Printf("Eth consensus state: %+v\n", ethConsensusState)

consensusState := ibcwasmtypes.ConsensusState{
Data: ethConsensusStateBz,
}
Expand Down Expand Up @@ -189,3 +196,6 @@ func (s *TestSuite) createDummyLightClient(ctx context.Context, cosmosChain *cos
s.Require().NoError(err)
s.Require().Equal(testvalues.FirstWasmClientID, ethereumLightClientID)
}

func CreateEthereumClientAndConsensusState() {
}
138 changes: 138 additions & 0 deletions e2e/interchaintestv8/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"strconv"
"strings"
"sync"
"testing"
Expand All @@ -25,12 +26,15 @@ import (
transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
channeltypesv2 "github.com/cosmos/ibc-go/v10/modules/core/04-channel/v2/types"

"github.com/strangelove-ventures/interchaintest/v8/testutil"

"github.com/cosmos/solidity-ibc-eureka/abigen/ibcerc20"
"github.com/cosmos/solidity-ibc-eureka/abigen/ics20transfer"

"github.com/srdtrk/solidity-ibc-eureka/e2e/v8/e2esuite"
"github.com/srdtrk/solidity-ibc-eureka/e2e/v8/operator"
"github.com/srdtrk/solidity-ibc-eureka/e2e/v8/testvalues"
ethereumtypes "github.com/srdtrk/solidity-ibc-eureka/e2e/v8/types/ethereum"
relayertypes "github.com/srdtrk/solidity-ibc-eureka/e2e/v8/types/relayer"
)

Expand Down Expand Up @@ -469,6 +473,140 @@ func (s *RelayerTestSuite) ICS20TransferERC20TokenBatchedAckToEthTest(
}))
}

func (s *RelayerTestSuite) TestMultiPeriodClientUpdateToCosmos() {
Copy link
Member

Choose a reason for hiding this comment

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

We should have some CI for this. Let's create an issue to split e2e.yml and link it here

ctx := context.Background()

s.SetupSuite(ctx, operator.ProofTypeGroth16) // Doesn't matter, since we won't relay to eth in this test

eth, simd := s.EthChain, s.CosmosChains[0]

ics20Address := ethcommon.HexToAddress(s.contractAddresses.Ics20Transfer)
erc20Address := ethcommon.HexToAddress(s.contractAddresses.Erc20)

ethereumUserAddress := crypto.PubkeyToAddress(s.key.PublicKey)
cosmosUserWallet := s.CosmosUsers[0]
cosmosUserAddress := cosmosUserWallet.FormattedAddress()

transferAmount := big.NewInt(testvalues.TransferAmount)

s.Require().True(s.Run("Approve the ICS20Transfer.sol contract to spend the erc20 tokens", func() {
tx, err := s.erc20Contract.Approve(s.GetTransactOpts(s.key, eth), ics20Address, transferAmount)
s.Require().NoError(err)

receipt, err := eth.GetTxReciept(ctx, tx.Hash())
s.Require().NoError(err)
s.Require().Equal(ethtypes.ReceiptStatusSuccessful, receipt.Status)
}))

s.Require().True(s.Run("Wait for period to change twice on Eth before relaying", func() {
_, ethClientState := s.GetEthereumClientState(ctx, simd, testvalues.FirstWasmClientID)
clientPeriod := ethClientState.LatestSlot / (ethClientState.EpochsPerSyncCommitteePeriod * ethClientState.SlotsPerEpoch)
err := testutil.WaitForCondition(time.Minute*30, time.Second*30, func() (bool, error) {
finalityUpdate, err := eth.BeaconAPIClient.GetFinalityUpdate()
if err != nil {
return false, err
}

finalitySlot, err := strconv.Atoi(finalityUpdate.Data.FinalizedHeader.Beacon.Slot)
if err != nil {
return false, err
}
finalityPeriod := uint64(finalitySlot) / (ethClientState.EpochsPerSyncCommitteePeriod * ethClientState.SlotsPerEpoch)

return finalityPeriod == clientPeriod+2, nil
})
s.Require().NoError(err)
}))

var (
sendTxHash []byte
escrowAddress ethcommon.Address
)
s.Require().True(s.Run("Send transfers on Ethereum", func() {
timeout := uint64(time.Now().Add(30 * time.Minute).Unix())

msgSendTransfer := ics20transfer.IICS20TransferMsgsSendTransferMsg{
Denom: erc20Address,
SourceClient: testvalues.CustomClientID,
DestPort: transfertypes.PortID,
Amount: transferAmount,
Receiver: cosmosUserAddress,
TimeoutTimestamp: timeout,
Memo: "",
}

tx, err := s.ics20Contract.SendTransfer(s.GetTransactOpts(s.key, eth), msgSendTransfer)
s.Require().NoError(err)

receipt, err := eth.GetTxReciept(ctx, tx.Hash())
s.Require().NoError(err)
s.Require().Equal(ethtypes.ReceiptStatusSuccessful, receipt.Status)

sendTxHash = tx.Hash().Bytes()

s.True(s.Run("Verify balances on Ethereum", func() {
// User balance on Ethereum
userBalance, err := s.erc20Contract.BalanceOf(nil, ethereumUserAddress)
s.Require().NoError(err)
s.Require().Equal(new(big.Int).Sub(testvalues.StartingERC20Balance, transferAmount), userBalance)

// Get the escrow address
escrowAddress, err = s.ics20Contract.GetEscrow(nil, testvalues.CustomClientID)
s.Require().NoError(err)

// ICS20 contract balance on Ethereum
escrowBalance, err := s.erc20Contract.BalanceOf(nil, escrowAddress)
s.Require().NoError(err)
s.Require().Equal(transferAmount, escrowBalance)
}))
}))

s.Require().True(s.Run("Receive packets on Cosmos chain", func() {
var relayTxBodyBz []byte
s.Require().True(s.Run("Retrieve relay tx", func() {
resp, err := s.RelayerClient.RelayByTx(context.Background(), &relayertypes.RelayByTxRequest{
SrcChain: eth.ChainID.String(),
DstChain: simd.Config().ChainID,
SourceTxIds: [][]byte{sendTxHash},
TargetClientId: testvalues.FirstWasmClientID,
})
s.Require().NoError(err)
s.Require().NotEmpty(resp.Tx)
s.Require().Empty(resp.Address)

relayTxBodyBz = resp.Tx

s.wasmFixtureGenerator.AddFixtureStep("receive_packets", ethereumtypes.RelayerMessages{
RelayerTxBody: hex.EncodeToString(relayTxBodyBz),
})
}))

var ackTxHash []byte
s.Require().True(s.Run("Broadcast relay tx", func() {
resp := s.BroadcastSdkTxBody(ctx, simd, s.SimdRelayerSubmitter, 2_000_000, relayTxBodyBz)

var err error
ackTxHash, err = hex.DecodeString(resp.TxHash)
s.Require().NoError(err)
s.Require().NotEmpty(ackTxHash)
}))

s.Require().True(s.Run("Verify balances on Cosmos chain", func() {
denomOnCosmos := transfertypes.NewDenom(s.contractAddresses.Erc20, transfertypes.NewHop(transfertypes.PortID, testvalues.FirstWasmClientID))

// User balance on Cosmos chain
resp, err := e2esuite.GRPCQuery[banktypes.QueryBalanceResponse](ctx, simd, &banktypes.QueryBalanceRequest{
Address: cosmosUserAddress,
Denom: denomOnCosmos.IBCDenom(),
})
s.Require().NoError(err)
s.Require().NotNil(resp.Balance)
s.Require().Equal(transferAmount, resp.Balance.Amount.BigInt())
s.Require().Equal(denomOnCosmos.IBCDenom(), resp.Balance.Denom)
}))
}))
}

func (s *RelayerTestSuite) Test_10_RecvPacketToCosmos() {
ctx := context.Background()
s.RecvPacketToCosmosTest(ctx, 10, big.NewInt(testvalues.TransferAmount))
Expand Down
2 changes: 2 additions & 0 deletions e2e/interchaintestv8/types/ethereum/types.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ClientState struct {
EpochsPerSyncCommitteePeriod uint64 `json:"epochs_per_sync_committee_period"`
// The fork parameters
ForkParameters ForkParameters `json:"fork_parameters"`
// The genesis slot
GenesisSlot uint64 `json:"genesis_slot"`
// The time of genesis (unix timestamp)
GenesisTime uint64 `json:"genesis_time"`
// The genesis validators root
Expand Down
Binary file modified e2e/interchaintestv8/wasm/cw_ics08_wasm_eth.wasm.gz
Binary file not shown.
10 changes: 6 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ generate-abi: build-contracts
generate-fixtures-wasm: clean
@echo "Generating fixtures... This may take a while."
@echo "Generating recvPacket and acknowledgePacket groth16 fixtures..."
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true SP1_PROVER=network go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferERC20TokenfromEthereumToCosmosAndBack_Groth16$' -timeout 40m
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferERC20TokenfromEthereumToCosmosAndBack_Groth16$' -timeout 60m
@echo "Generating native SdkCoin recvPacket groth16 fixtures..."
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true SP1_PROVER=network go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferNativeCosmosCoinsToEthereumAndBack_Groth16$' -timeout 40m
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferNativeCosmosCoinsToEthereumAndBack_Groth16$' -timeout 60m
@echo "Generating timeoutPacket groth16 fixtures..."
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true SP1_PROVER=network go test -v -run '^TestWithIbcEurekaTestSuite/TestTimeoutPacketFromEth_Groth16$' -timeout 40m
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true go test -v -run '^TestWithIbcEurekaTestSuite/TestTimeoutPacketFromEth_Groth16$' -timeout 60m
@echo "Generating multi-period client update fixtures..."
cd e2e/interchaintestv8 && GENERATE_WASM_FIXTURES=true go test -v -run '^TestWithRelayerTestSuite/TestMultiPeriodClientUpdateToCosmos$' -timeout 60m

# Generate go types for the e2e tests from the etheruem light client code
generate-ethereum-types:
Expand All @@ -104,7 +106,7 @@ generate-ethereum-types:
# For example, `just test-e2e TestWithIbcEurekaTestSuite/TestDeploy_Groth16`
test-e2e testname: clean
@echo "Running {{testname}} test..."
cd e2e/interchaintestv8 && go test -v -run '^{{testname}}$' -timeout 40m
cd e2e/interchaintestv8 && go test -v -run '^{{testname}}$' -timeout 120m

# Run any e2e test in the IbcEurekaTestSuite using the test's name
# For example, `just test-e2e-eureka TestDeploy_Groth16`
Expand Down
Loading
Loading