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: remove TrustedSyncCommittee #398

Merged
merged 20 commits into from
Mar 18, 2025
Merged
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion e2e/interchaintestv8/e2esuite/utils.go
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ func (s *TestSuite) GetEthereumClientState(ctx context.Context, cosmosChain *cos

var ethClientState ethereumtypes.ClientState
err = json.Unmarshal(wasmClientState.Data, &ethClientState)
s.Require().NoError(err)
s.Require().NoError(err, "failed to unmarshal ethereum client state: %s", string(wasmClientState.Data))

return wasmClientState, ethClientState
}
65 changes: 29 additions & 36 deletions e2e/interchaintestv8/types/ethereum/types.gen.go
Original file line number Diff line number Diff line change
@@ -79,33 +79,32 @@ type Fork struct {
Version string `json:"version"`
}

// The consensus state of the Ethereum light client
// The consensus state of the Ethereum light client corresponding to a finalized header
//
// The consensus state at the initial state
type ConsensusState struct {
// aggregate public key of current sync committee
// aggregate public key of current sync committee at the finalized header
CurrentSyncCommittee string `json:"current_sync_committee"`
// aggregate public key of next sync committee
// aggregate public key of next sync committee at the finalized header if known
NextSyncCommittee string `json:"next_sync_committee"`
// The slot number
// The slot number of the finalized header
Slot uint64 `json:"slot"`
// The state merkle root
// The state merkle root of the finalized header
StateRoot string `json:"state_root"`
// The storage merkle root
// The storage merkle root of the tracked contract at the finalized header
StorageRoot string `json:"storage_root"`
// The unix timestamp at the time of the slot. It is calculated from the genesis time and
// slots per.
// The execution timestamp of the finalized header
Timestamp uint64 `json:"timestamp"`
}

// The header of a light client update
type Header struct {
// The account update
AccountUpdate AccountUpdate `json:"account_update"`
// The trusted sync committee
ActiveSyncCommittee ActiveSyncCommittee `json:"active_sync_committee"`
// The consensus update
ConsensusUpdate LightClientUpdate `json:"consensus_update"`
// The trusted sync committee
TrustedSyncCommittee TrustedSyncCommittee `json:"trusted_sync_committee"`
}

// The account update
@@ -122,6 +121,26 @@ type AccountProof struct {
StorageRoot string `json:"storage_root"`
}

// The trusted sync committee
//
// # The active sync committee
//
// # The current sync committee
//
// The next sync committee
type ActiveSyncCommittee struct {
Current *SyncCommittee `json:"Current,omitempty"`
Next *SyncCommittee `json:"Next,omitempty"`
}

// The sync committee data
type SyncCommittee struct {
// The aggregate public key of the sync committee
AggregatePubkey string `json:"aggregate_pubkey"`
// The public keys of the sync committee
Pubkeys []string `json:"pubkeys"`
}

// The consensus update
//
// A light client update
@@ -210,14 +229,6 @@ type ExecutionPayloadHeader struct {
WithdrawalsRoot string `json:"withdrawals_root"`
}

// The sync committee data
type SyncCommittee struct {
// The aggregate public key of the sync committee
AggregatePubkey string `json:"aggregate_pubkey"`
// The public keys of the sync committee
Pubkeys []string `json:"pubkeys"`
}

// Sync committee aggregate signature
//
// The sync committee aggregate
@@ -228,24 +239,6 @@ type SyncAggregate struct {
SyncCommitteeSignature string `json:"sync_committee_signature"`
}

// The trusted sync committee
type TrustedSyncCommittee struct {
// The current sync committee
SyncCommittee ActiveSyncCommittee `json:"sync_committee"`
// The trusted slot
TrustedSlot uint64 `json:"trusted_slot"`
}

// The current sync committee
//
// # The active sync committee
//
// The next sync committee
type ActiveSyncCommittee struct {
Current *SyncCommittee `json:"Current,omitempty"`
Next *SyncCommittee `json:"Next,omitempty"`
}

// The key-value storage proof for a smart contract account
type StorageProof struct {
// The key of the storage
Binary file modified e2e/interchaintestv8/wasm/cw_ics08_wasm_eth.wasm.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
@@ -84,13 +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 go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferERC20TokenfromEthereumToCosmosAndBack_Groth16$' -timeout 60m
cd e2e/interchaintestv8 && ETH_TESTNET_TYPE=pos 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 go test -v -run '^TestWithIbcEurekaTestSuite/TestICS20TransferNativeCosmosCoinsToEthereumAndBack_Groth16$' -timeout 60m
cd e2e/interchaintestv8 && ETH_TESTNET_TYPE=pos 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 go test -v -run '^TestWithIbcEurekaTestSuite/TestTimeoutPacketFromEth_Groth16$' -timeout 60m
cd e2e/interchaintestv8 && ETH_TESTNET_TYPE=pos 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
cd e2e/interchaintestv8 && ETH_TESTNET_TYPE=pos 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:
10 changes: 10 additions & 0 deletions packages/ethereum/ethereum-light-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -177,6 +177,16 @@ pub enum EthereumIBCError {
consensus_state_slot: u64,
update_finalized_slot: u64,
},

#[error(
"client and consensus slot mismatch: \
client state slot: {client_state_slot}, \
consensus state slot: {consensus_state_slot}"
)]
ClientAndConsensusSlotMismatch {
client_state_slot: u64,
consensus_state_slot: u64,
},
}

#[derive(Debug, PartialEq, Eq, Clone, thiserror::Error)]
13 changes: 2 additions & 11 deletions packages/ethereum/ethereum-light-client/src/header.rs
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ use ethereum_types::{
/// The header of a light client update
#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
pub struct Header {
/// The trusted sync committee
pub trusted_sync_committee: TrustedSyncCommittee,
/// The active sync committee (untrusted)
pub active_sync_committee: ActiveSyncCommittee,
/// The consensus update
pub consensus_update: LightClientUpdate,
/// The account update
@@ -26,15 +26,6 @@ pub struct AccountUpdate {
pub account_proof: AccountProof,
}

/// The trusted sync committee
#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
pub struct TrustedSyncCommittee {
/// The trusted slot
pub trusted_slot: u64,
/// The current sync committee
pub sync_committee: ActiveSyncCommittee,
}

/// The active sync committee
#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
pub enum ActiveSyncCommittee {

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -30,30 +30,30 @@
"genesis_slot": 0
},
"genesis_slot": 0,
"genesis_time": 1741827702,
"genesis_time": 1742218032,
"genesis_validators_root": "d61ea484febacfae5298d52a2b581f3e305a51f3112a9241b968dccf019f7b11",
"ibc_commitment_slot": "0x1260944489272988d9df285149b5aa1b0f48f2136d6f416159f840a3e0747600",
"ibc_contract_address": "0x0bfd4d8567a47c3c599a5014929e77050db40dd8",
"ibc_contract_address": "0x28a2e342554287865daac0348a36547f36804264",
"is_frozen": false,
"latest_slot": 32,
"min_sync_committee_participants": 32,
"seconds_per_slot": 6,
"slots_per_epoch": 8
},
"consensus_state": {
"current_sync_committee": "0x96102a599965ab066c84aaae09cabf74686c28bcfc4899dc1378083ae133cf6c65bd319b196557f00213ff9879dedd35",
"next_sync_committee": "0x96102a599965ab066c84aaae09cabf74686c28bcfc4899dc1378083ae133cf6c65bd319b196557f00213ff9879dedd35",
"current_sync_committee": "0xb53a10c2fd371ae90fb20e615aad7d6d46af107b78017cb7164ddd485c052f8243b9f9db43797e8e347649f42153fb8f",
"next_sync_committee": "0xb53a10c2fd371ae90fb20e615aad7d6d46af107b78017cb7164ddd485c052f8243b9f9db43797e8e347649f42153fb8f",
"slot": 32,
"state_root": "0x585bf08700285f5eb6363024d9610e540a8a847b823d29de6e075b0875d5f463",
"state_root": "0xdae91a56957b1193299ce74622476f7d29e3d7e8a6962f9980cc2d0d0c8bfc1a",
"storage_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": 1741827894
"timestamp": 1742218224
}
},
"name": "initial_state"
},
{
"data": {
"relayer_tx_body": "ac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000c24b98c330a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000051000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000067d22fea0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000b636f736d6f736875622d31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000930382d7761736d2d3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000087472616e7366657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087472616e73666572000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000769637332302d3100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a6170706c69636174696f6e2f782d736f6c69646974792d6162690000000000000000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000002a30786330643639663537346266343735363162643034376237656538333539666262626237323361333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783331343065346531393336383462656638383466363031306130633536363135303663316564623400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d636f736d6f73316b32327334667374647077796b656a6c64776d32387a6a686e346d6e6b307766703966786435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008746573746d656d6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000005a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020003562d7e2a39652b550c64eb6fb75c6560316f3cdd2da6e4a71d0d8d07b65b90000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000054000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000067d22f68d04bac3fd70efc9a6d094bebe7db6c39ed31c6bbcf65498848511d21eed140ab93bf5f47655fc222cb4fb3ded44a11b2103d79c408be89bcb572ac9dd8b445d30000000000000000000000000000000000000000000000000000000067d22ffb4d2c3b6e579b86ad53404ffe44e22edac25ddf99b63ce9c1751e4e53fa96708193bf5f47655fc222cb4fb3ded44a11b2103d79c408be89bcb572ac9dd8b445d30000000000000000000000000000000000000000000000000000000067d22fff000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000005100000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000012754500000000000000000000000000000000000000000000000000000000001baf8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036962630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001230382d7761736d2d3002000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"relayer_tx_body": "ac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000d44b98c330a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000054000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000067d824aa0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000b636f736d6f736875622d31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000930382d7761736d2d3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000087472616e7366657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087472616e73666572000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000769637332302d3100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a6170706c69636174696f6e2f782d736f6c69646974792d6162690000000000000000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000002a30783038356536633735303666646439623064646439353432646362616163313038366635356333666500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783062313061353930373566316535663938336338393339633537373466353866663864336266643400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d636f736d6f7331766d6a6d657439617677323434683470726c727a653075303971637378736a6737633832356e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008746573746d656d6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000a688f6a93260f933b072020380d232a0a0a835c2353438282444db6e1eafbc0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000054000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000182d9a4a414a669c27c08cea1fd9fdc5e05677de9f498d822dd9369a0d5dc2ef81434d792efbc008d1ae522ef7a98238526e5554c7e49a7b4809f58139cc0f54b45315311ecbb75c000000000000000000000000000000000000000000000000182d9a6dfcf7190b8b6b7a1c3befc302419fce33775297014ad950ae9db7f3be1a125ce8346832e9d1ae522ef7a98238526e5554c7e49a7b4809f58139cc0f54b45315311ecbb75c000000000000000000000000000000000000000000000000182d9a6ebaf85d28000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000005400000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000012754500000000000000000000000000000000000000000000000000000000001baf8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036962630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001230382d7761736d2d3002000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010411b6a09d2e5ab15584b44815a55fa0ba5b89af19573784c20e4d9aeaaee315059fb2f1ba210055d546ae81c4e77983166d1c46d4dc7541b3013a042055c01e1aa79b781b06761b1ba3a4ee12ddb52bafdaaf294e6c2ae0d6af76741f7dd3d5c0b20ec5490195a53487fe7f0c148ab9f38dd8b657a4c297946c1b8fd3e10d404050f6002f0c95cf4eebe167408c092e10fe9ebf677ed8f4391b5306a737424bbface216e81fed8c5a03f984177fe61c018ad298f56b419cdf89f1e2ffab7112d020c455af14ac34135c972448c5d09176abefbcb7af42803ce3b63983d498772feaba68640713d36505ec22a7965f13b2c72f449435827dc89ca0abd10c3e5ab4ff1b52ba0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"name": "timeout_packets"
}
71 changes: 42 additions & 29 deletions packages/ethereum/ethereum-light-client/src/update.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,12 @@ use crate::{

/// Takes in the current client and consensus state and a new header and returns the updated
/// consensus state and optionally the updated client state (if it needs to be updated)
///
/// # Returns
/// Returns the updated slot, the updated consensus state and optionally the updated client state.
///
/// Current implementation requires the client and consensus states to be updated since historical updates are not allowed.
///
/// # Errors
/// Returns an error if the store period is not equal to the finalized period
#[allow(clippy::module_name_repetitions, clippy::needless_pass_by_value)]
@@ -15,25 +21,29 @@ pub fn update_consensus_state(
current_client_state: ClientState,
header: Header,
) -> Result<(u64, ConsensusState, Option<ClientState>), EthereumIBCError> {
let trusted_sync_committee = header.trusted_sync_committee;
let trusted_slot = trusted_sync_committee.trusted_slot;

let consensus_update = header.consensus_update;
ensure!(
current_client_state.latest_slot == current_consensus_state.slot,
EthereumIBCError::ClientAndConsensusSlotMismatch {
client_state_slot: current_client_state.latest_slot,
consensus_state_slot: current_consensus_state.slot
}
);

let store_period =
current_client_state.compute_sync_committee_period_at_slot(current_consensus_state.slot);
let store_slot = current_consensus_state.slot;
let store_period = current_client_state.compute_sync_committee_period_at_slot(store_slot);

let update_finalized_period = current_client_state
.compute_sync_committee_period_at_slot(consensus_update.finalized_header.beacon.slot);
let update_finalized_slot = header.consensus_update.finalized_header.beacon.slot;
let update_finalized_period =
current_client_state.compute_sync_committee_period_at_slot(update_finalized_slot);

let mut new_consensus_state = current_consensus_state.clone();
let mut new_client_state: Option<ClientState> = None;

if let Some(next_sync_committee) = current_consensus_state.next_sync_committee {
// sync committee only changes when the period change
if update_finalized_period == store_period + 1 {
new_consensus_state.current_sync_committee = next_sync_committee;
new_consensus_state.next_sync_committee = consensus_update
new_consensus_state.next_sync_committee = header
.consensus_update
.next_sync_committee
.map(|c| c.aggregate_pubkey);
}
@@ -43,29 +53,32 @@ pub fn update_consensus_state(
update_finalized_period == store_period,
EthereumIBCError::StorePeriodMustBeEqualToFinalizedPeriod
);
new_consensus_state.next_sync_committee = consensus_update
new_consensus_state.next_sync_committee = header
.consensus_update
.next_sync_committee
.map(|c| c.aggregate_pubkey);
}

// Some updates can be only for updating the sync committee, therefore the slot number can be
// smaller. We don't want to save a new state if this is the case.
// TODO: we might to remove this functionality if we don't use it as it complicates the light client
let updated_slot = core::cmp::max(trusted_slot, consensus_update.finalized_header.beacon.slot);

if consensus_update.finalized_header.beacon.slot > current_consensus_state.slot {
new_consensus_state.slot = consensus_update.finalized_header.beacon.slot;
new_consensus_state.state_root = consensus_update.finalized_header.execution.state_root;
new_consensus_state.storage_root = header.account_update.account_proof.storage_root;
new_consensus_state.timestamp = consensus_update.finalized_header.execution.timestamp;

if current_client_state.latest_slot < consensus_update.finalized_header.beacon.slot {
new_client_state = Some(ClientState {
latest_slot: consensus_update.finalized_header.beacon.slot,
..current_client_state
});
ensure!(
update_finalized_slot > store_slot,
EthereumIBCError::HistoricalUpdateNotAllowed {
consensus_state_slot: store_slot,
update_finalized_slot,
}
}
);

new_consensus_state.slot = update_finalized_slot;
new_consensus_state.state_root = header
.consensus_update
.finalized_header
.execution
.state_root;
new_consensus_state.storage_root = header.account_update.account_proof.storage_root;
new_consensus_state.timestamp = header.consensus_update.finalized_header.execution.timestamp;

Ok((updated_slot, new_consensus_state, new_client_state))
let new_client_state = Some(ClientState {
latest_slot: update_finalized_slot,
..current_client_state
});
Ok((update_finalized_slot, new_consensus_state, new_client_state))
}
2 changes: 1 addition & 1 deletion packages/ethereum/ethereum-light-client/src/verify.rs
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ pub fn verify_header<V: BlsVerify>(
) -> Result<(), EthereumIBCError> {
let trusted_consensus_state = TrustedConsensusState::new(
consensus_state.clone(),
header.trusted_sync_committee.sync_committee.clone(),
header.active_sync_committee.clone(),
&bls_verifier,
)?;

23 changes: 8 additions & 15 deletions packages/relayer-lib/src/tx_builder/eth_to_cosmos.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use alloy::{primitives::Address, providers::Provider};
use anyhow::Result;
use ethereum_apis::{beacon_api::client::BeaconApiClient, eth_api::client::EthApiClient};
use ethereum_light_client::consensus_state::ConsensusState;
use ethereum_light_client::header::{AccountUpdate, ActiveSyncCommittee, TrustedSyncCommittee};
use ethereum_light_client::header::{AccountUpdate, ActiveSyncCommittee};
use ethereum_light_client::{client_state::ClientState, header::Header};
use ethereum_types::consensus::light_client_header::{
LightClientFinalityUpdate, LightClientUpdate,
@@ -196,7 +196,7 @@ where
async fn light_client_update_to_header(
&self,
ethereum_client_state: ClientState,
trusted_sync_committee: TrustedSyncCommittee,
active_sync_committee: ActiveSyncCommittee,
update: LightClientUpdate,
) -> Result<Header> {
tracing::debug!(
@@ -221,7 +221,7 @@ where
};

Ok(Header {
trusted_sync_committee,
active_sync_committee,
account_update,
consensus_update: update,
})
@@ -352,14 +352,11 @@ where
.get_sync_commitee_for_finalized_slot(update.finalized_header.beacon.slot)
.await?;

let trusted_sync_committee = TrustedSyncCommittee {
trusted_slot: latest_trusted_slot,
sync_committee: ActiveSyncCommittee::Next(previous_next_sync_committee),
};
let active_sync_committee = ActiveSyncCommittee::Next(previous_next_sync_committee);
let header = self
.light_client_update_to_header(
ethereum_client_state.clone(),
trusted_sync_committee.clone(),
active_sync_committee.clone(),
update.clone(),
)
.await?;
@@ -386,17 +383,13 @@ where
.get_sync_commitee_for_finalized_slot(finality_update.attested_header.beacon.slot)
.await?;
// TODO: Add asserts to make sure they are in the correct period
let trusted_sync_committee = TrustedSyncCommittee {
trusted_slot: latest_trusted_slot,
sync_committee: ActiveSyncCommittee::Current(
finality_update_sync_committee.clone(),
),
};
let active_sync_committee =
ActiveSyncCommittee::Current(finality_update_sync_committee.clone());

let header = self
.light_client_update_to_header(
ethereum_client_state.clone(),
trusted_sync_committee.clone(),
active_sync_committee.clone(),
finality_update.clone().into(),
)
.await?;