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

Finalize movement state lens #3604

Merged
merged 15 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
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
63 changes: 63 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ members = [
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-ics23-light-client-types",
"lib/state-lens-ics23-smt-light-client-types",

# these will all be re enabled and updated once ethereum-light-client is updated

Expand Down Expand Up @@ -119,12 +120,14 @@ members = [
"voyager/modules/client/tendermint",
"voyager/modules/client/state-lens/ics23-mpt",
"voyager/modules/client/state-lens/ics23-ics23",
"voyager/modules/client/state-lens/ics23-smt",

"voyager/modules/client-bootstrap/cometbls",
"voyager/modules/client-bootstrap/ethereum",
"voyager/modules/client-bootstrap/movement",
"voyager/modules/client-bootstrap/tendermint",
"voyager/modules/client-bootstrap/state-lens/ics23-mpt",
"voyager/modules/client-bootstrap/state-lens/ics23-smt",
"voyager/modules/client-bootstrap/state-lens/ics23-ics23",

"voyager/modules/consensus/berachain",
Expand Down Expand Up @@ -224,6 +227,7 @@ scroll-rpc = { path = "lib/scroll-rpc", default-features = fal

state-lens-ics23-ics23-light-client-types = { path = "lib/state-lens-ics23-ics23-light-client-types", default-features = false }
state-lens-ics23-mpt-light-client-types = { path = "lib/state-lens-ics23-mpt-light-client-types", default-features = false }
state-lens-ics23-smt-light-client-types = { path = "lib/state-lens-ics23-smt-light-client-types", default-features = false }

tendermint-light-client = { path = "cosmwasm/ibc-union/light-clients/tendermint", default-features = false }
tendermint-light-client-types = { path = "lib/tendermint-light-client-types", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions cosmwasm/ibc-union/light-clients/berachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crate-type = ["cdylib", "rlib"]
beacon-api-types = { workspace = true, features = ["ssz"] }
cosmwasm-std = { workspace = true, features = ["abort", "cosmwasm_2_1"] }
ethereum-light-client = { workspace = true, features = ["library"] }
serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }

berachain-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
Expand Down
12 changes: 12 additions & 0 deletions cosmwasm/ibc-union/light-clients/berachain/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ pub fn instantiate(
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
ibc_union_light_client::query::<BerachainLightClient>(deps, env, msg).map_err(Into::into)
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MigrateMsg {}

#[entry_point]
pub fn migrate(
_deps: DepsMut,
_env: Env,
_msg: MigrateMsg,
) -> Result<Response, IbcClientError<BerachainLightClient>> {
Ok(Response::new())
}
12 changes: 12 additions & 0 deletions cosmwasm/ibc-union/light-clients/movement/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ pub fn instantiate(
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
ibc_union_light_client::query::<MovementLightClient>(deps, env, msg).map_err(Into::into)
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MigrateMsg {}

#[entry_point]
pub fn migrate(
_deps: DepsMut,
_env: Env,
_msg: MigrateMsg,
) -> Result<Response, IbcClientError<MovementLightClient>> {
Ok(Response::new())
}
16 changes: 14 additions & 2 deletions evm/contracts/clients/StateLensIcs23MptClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ library StateLensIcs23MptLib {
function encode(
ConsensusState memory consensusState
) internal pure returns (bytes memory) {
return abi.encode(consensusState);
return abi.encode(
consensusState.timestamp,
consensusState.stateRoot,
consensusState.storageRoot
);
}

function encode(
ClientState memory clientState
) internal pure returns (bytes memory) {
return abi.encode(clientState);
return abi.encode(
clientState.l2ChainId,
clientState.l1ClientId,
clientState.l2ClientId,
clientState.l2LatestHeight,
clientState.timestampOffset,
clientState.stateRootOffset,
clientState.storageRootOffset
);
}

function commit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ConsensusState {
bytes32 stateRoot;
}

library StateLensIcs23MoveLib {
library StateLensIcs23SmtLib {
uint256 public constant EVM_IBC_COMMITMENT_SLOT = 0;

event CreateLensClient(
Expand All @@ -48,14 +48,21 @@ library StateLensIcs23MoveLib {

function encode(
ConsensusState memory consensusState
) internal pure returns (bytes memory) {
return abi.encode(consensusState);
) public pure returns (bytes memory) {
return abi.encode(consensusState.timestamp, consensusState.stateRoot);
}

function encode(
ClientState memory clientState
) internal pure returns (bytes memory) {
return abi.encode(clientState);
) public pure returns (bytes memory) {
return abi.encode(
clientState.l2ChainId,
clientState.l1ClientId,
clientState.l2ClientId,
clientState.l2LatestHeight,
clientState.timestampOffset,
clientState.stateRootOffset
);
}

function commit(
Expand Down Expand Up @@ -91,14 +98,14 @@ library StateLensIcs23MoveLib {
}
}

contract StateLensIcs23MoveClient is
contract StateLensIcs23SmtClient is
ILightClient,
Initializable,
UUPSUpgradeable,
OwnableUpgradeable,
PausableUpgradeable
{
using StateLensIcs23MoveLib for *;
using StateLensIcs23SmtLib for *;

address private ibcHandler;

Expand Down Expand Up @@ -130,26 +137,22 @@ contract StateLensIcs23MoveClient is
string memory counterpartyChainId
)
{
// ClientState calldata clientState;
// assembly {
// clientState := clientStateBytes.offset
// }
// ConsensusState calldata consensusState;
// assembly {
// consensusState := consensusStateBytes.offset
// }
ClientState memory clientState =
abi.decode(clientStateBytes, (ClientState));
ConsensusState memory consensusState =
abi.decode(consensusStateBytes, (ConsensusState));
ClientState calldata clientState;
assembly {
clientState := clientStateBytes.offset
}
ConsensusState calldata consensusState;
assembly {
consensusState := consensusStateBytes.offset
}

if (clientState.l2LatestHeight == 0 || consensusState.timestamp == 0) {
revert StateLensIcs23MoveLib.ErrInvalidInitialConsensusState();
revert StateLensIcs23SmtLib.ErrInvalidInitialConsensusState();
}
clientStates[clientId] = clientState;
consensusStates[clientId][clientState.l2LatestHeight] = consensusState;

emit StateLensIcs23MoveLib.CreateLensClient(
emit StateLensIcs23SmtLib.CreateLensClient(
clientId,
clientState.l1ClientId,
clientState.l2ClientId,
Expand All @@ -174,7 +177,10 @@ contract StateLensIcs23MoveClient is
uint32 clientId,
bytes calldata clientMessageBytes
) external override onlyIBC returns (ConsensusStateUpdate memory) {
Header memory header = abi.decode(clientMessageBytes, (Header));
Header calldata header;
assembly {
header := clientMessageBytes.offset
}

ClientState storage clientState = clientStates[clientId];
ILightClient l1Client =
Expand All @@ -193,18 +199,18 @@ contract StateLensIcs23MoveClient is
abi.encodePacked(keccak256(header.l2ConsensusState))
)
) {
revert StateLensIcs23MoveLib.ErrInvalidL1Proof();
revert StateLensIcs23SmtLib.ErrInvalidL1Proof();
}

bytes memory rawL2ConsensusState = header.l2ConsensusState;
uint64 l2Timestamp = uint64(
uint256(
StateLensIcs23MoveLib.extractMemory(
StateLensIcs23SmtLib.extractMemory(
rawL2ConsensusState, clientState.timestampOffset
)
)
);
bytes32 l2StateRoot = StateLensIcs23MoveLib.extractMemory(
bytes32 l2StateRoot = StateLensIcs23SmtLib.extractMemory(
rawL2ConsensusState, clientState.stateRootOffset
);

Expand All @@ -231,7 +237,7 @@ contract StateLensIcs23MoveClient is
uint32 clientId,
bytes calldata clientMessageBytes
) external override onlyIBC {
revert StateLensIcs23MoveLib.ErrUnsupported();
revert StateLensIcs23SmtLib.ErrUnsupported();
}

function verifyMembership(
Expand Down Expand Up @@ -300,7 +306,7 @@ contract StateLensIcs23MoveClient is

function _onlyIBC() internal view {
if (msg.sender != ibcHandler) {
revert StateLensIcs23MoveLib.ErrNotIBC();
revert StateLensIcs23SmtLib.ErrNotIBC();
}
}

Expand Down
22 changes: 22 additions & 0 deletions evm/evm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ _: {
jq --compact-output --slurp 'map(.abi) | add' \
${contracts}/out/StateLensIcs23Ics23Client.sol/StateLensIcs23Ics23Client.json \
${contracts}/out/StateLensIcs23Ics23Client.sol/StateLensIcs23Ics23Lib.json > state-lens-ics23-ics23-client.json

jq --compact-output --slurp 'map(.abi) | add' \
${contracts}/out/StateLensIcs23SmtClient.sol/StateLensIcs23SmtClient.json \
${contracts}/out/StateLensIcs23SmtClient.sol/StateLensIcs23SmtLib.json > state-lens-ics23-smt-client.json
''
);

Expand Down Expand Up @@ -713,6 +717,12 @@ _: {
value = eth-deploy-single ({ kind = "StateLensIcs23Ics23Client"; } // args);
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-deploy-${args.network}-state-lens-ics23-smt-client";
value = eth-deploy-single ({ kind = "StateLensIcs23SmtClient"; } // args);
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-deploy-${args.network}-ucs03";
Expand Down Expand Up @@ -785,6 +795,18 @@ _: {
);
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-upgrade-${args.network}-state-lens-ics23-smt-client";
value = eth-upgrade (
{
dry = false;
protocol = "StateLensIcs23SmtClient";
}
// args
);
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-dryupgrade-${args.network}-ibc";
Expand Down
Loading
Loading