Skip to content

Commit

Permalink
chore: pr fixes
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Jan 22, 2025
1 parent dfb054a commit cf67d42
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 80 deletions.
26 changes: 0 additions & 26 deletions evm/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -494,32 +494,6 @@ contract DeployStateLensIcs23SmtClient is UnionScript {
}
}

contract RegisterIcs23SmtClient is Script {
using LibString for *;

address immutable handler;
address immutable client;

constructor() {
handler = vm.envAddress("IBC_HANDLER");
client = vm.envAddress("CLIENT");
}

function run() public {
uint256 privateKey = vm.envUint("PRIVATE_KEY");

address owner = vm.addr(privateKey);

vm.startBroadcast(privateKey);

IBCHandler(handler).registerClient(
LightClients.STATE_LENS_ICS23_SMT, StateLensIcs23SmtClient(client)
);

vm.stopBroadcast();
}
}

contract DeployIBC is UnionScript {
Deployer immutable deployer;

Expand Down
2 changes: 1 addition & 1 deletion lib/voyager-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl ClientType {
/// [ICS23]: https://github.com/cosmos/ics23
pub const STATE_LENS_ICS23_ICS23: &'static str = "state-lens/ics23/ics23";

/// A client tracking a [Aptos] chain, verified through that chain's consensus as
/// A client tracking an [Aptos] chain, verified through that chain's consensus as
/// settled on an intermediary [ICS-23] chain.
///
/// [ICS23]: https://github.com/cosmos/ics23
Expand Down
10 changes: 0 additions & 10 deletions move/move-ibc/sources/ics23.move
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,4 @@ module ibc::ics23 {
// )
// );
// }

#[test]
fun test_decode() {
let mem_proof =
decode_membership_proof(
x"4103f64b1e5af826603673cac212ceedb720fb845c66aa7ce71ca304905ad66b6e518f45ebee8d9b85345cea31097b92cbe2ad1bdf6f28edb6d678edc90beb33a45f20c157348fc7d075310f7d6c66f776051837111fda874a1dd3028d1194bc0b84d0060002b691e7020c070204b691e7022021202e60f5d93b1af14ad194d1d178ef53a7c52a101f441d23be54545ec1d96c011b280408b691e702202474ff5887b23d801a16c134c792f21ff3ce9251de3bd3c7a625b76fe3a9b6582000070610b691e702202120464094ac3afa7acaf1b44f50c789b7317cb2562054e1825833d206e68be2dce8070816b691e7022021207a543411b7ab4cdc2c61d08600d81e0b6847b7f9e3af92458b970ce1b0d11098070a2eb691e702202120b6c279988f0719237378323464860c08b562866b18c9d6867fdf727061aa3f01070e66b691e702202120a060f1df88ed45d0933ff584fb79db0118a81695d4a1f221b07965c209479ec22910d401b691e70220b3c357c7c3f497292320aa40d8fdfea78a04c7014b3ecaa401d06a78e280a04820000812d203b691e7022021202f751293c3774c7b9851a9659b59814a10accecd2466c319ea80ad894c62dcd229148006b691e7022065b3fe92c7d5951d8d020fce65f3d752fe654e1b718989ee7ea2f5dc130165e6200029168e0cb691e70220919a75b56ea1cd4ade3fa2a5abf5f532d1a60a7373426e65f1d99403bc97dd6c2000081aaa1ab691e7022021205eb5a5643abe553a8d412f00434bbd2a478f8b09ce6e34598ad81a258522b999291cb63bb691e70220cebfbcee54dc4bc8e5c9f92883f68fd9f61aaa598053d10acdcf011e6b5043e82000047761736d20c72e21ec48b1a939c2e222550a28351efc670e599748959ad2c048c23bcf8d2d01000221012d4d7964d98298ac3383588a55b5464f8633ef52c99a2e6b35ccf97228db77a3002101e30f8d11d327eee46be8cd501e84c9a96e9b35baccd92a81999fdf5915a1dd4200"
);
std::debug::print(&vector::is_empty(&mem_proof.sub_proof.leaf_prefix));
std::debug::print(&vector::is_empty(&mem_proof.top_level_proof.leaf_prefix));
}
}
46 changes: 24 additions & 22 deletions move/move-ibc/sources/light_client.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module ibc::light_client {
use std::string::{Self, String};

const E_UNKNOWN_CLIENT_TYPE: u64 = 1;
const CLIENT_TYPE_STATE_LENS_ICS23_MPT: vector<u8> = b"state-lens/ics23/mpt";
const CLIENT_TYPE_COMETBLS: vector<u8> = b"cometbls";

public fun create_client(
client_type: String,
Expand All @@ -12,7 +14,7 @@ module ibc::light_client {
client_state_bytes: vector<u8>,
consensus_state_bytes: vector<u8>
): (vector<u8>, vector<u8>) {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
let (client_state, consensus_state) =
cometbls_lc::create_client(
ibc_signer,
Expand All @@ -21,7 +23,7 @@ module ibc::light_client {
consensus_state_bytes
);
return (client_state, consensus_state)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
let (client_state, consensus_state) =
statelens_lc::create_client(
ibc_signer,
Expand All @@ -36,19 +38,19 @@ module ibc::light_client {
}

public fun status(client_type: String, client_id: u32): u64 {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::status(client_id)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::status(client_id)
};
abort E_UNKNOWN_CLIENT_TYPE

}

public fun latest_height(client_type: String, client_id: u32): u64 {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::latest_height(client_id)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::latest_height(client_id)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -57,9 +59,9 @@ module ibc::light_client {
public fun check_for_misbehaviour(
client_type: String, client_id: u32, header: vector<u8>
): bool {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::check_for_misbehaviour(client_id, header)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::check_for_misbehaviour(client_id, header)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -68,9 +70,9 @@ module ibc::light_client {
public fun update_client(
client_type: String, client_id: u32, client_msg: vector<u8>
): (vector<u8>, vector<vector<u8>>, vector<u64>) {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::update_client(client_id, client_msg)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::update_client(client_id, client_msg)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -79,9 +81,9 @@ module ibc::light_client {
public fun report_misbehaviour(
client_type: String, client_id: u32, misbehaviour: vector<u8>
) {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
cometbls_lc::report_misbehaviour(client_id, misbehaviour)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
statelens_lc::report_misbehaviour(client_id, misbehaviour)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -90,18 +92,18 @@ module ibc::light_client {
public fun get_timestamp_at_height(
client_type: String, client_id: u32, height: u64
): u64 {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::get_timestamp_at_height(client_id, height)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::get_timestamp_at_height(client_id, height)
};
abort E_UNKNOWN_CLIENT_TYPE
}

public fun get_client_state(client_type: String, client_id: u32): vector<u8> {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::get_client_state(client_id)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::get_client_state(client_id)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -110,9 +112,9 @@ module ibc::light_client {
public fun get_consensus_state(
client_type: String, client_id: u32, height: u64
): vector<u8> {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::get_consensus_state(client_id, height)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::get_consensus_state(client_id, height)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -126,9 +128,9 @@ module ibc::light_client {
key: vector<u8>,
value: vector<u8>
): u64 {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::verify_membership(client_id, height, proof, key, value)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::verify_membership(client_id, height, proof, key, value)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand All @@ -141,9 +143,9 @@ module ibc::light_client {
proof: vector<u8>,
path: vector<u8>
): u64 {
if (string::bytes(&client_type) == &b"cometbls") {
if (string::bytes(&client_type) == &CLIENT_TYPE_COMETBLS) {
return cometbls_lc::verify_non_membership(client_id, height, proof, path)
} else if (string::bytes(&client_type) == &b"state-lens/ics23/mpt") {
} else if (string::bytes(&client_type) == &CLIENT_TYPE_STATE_LENS_ICS23_MPT) {
return statelens_lc::verify_non_membership(client_id, height, proof, path)
};
abort E_UNKNOWN_CLIENT_TYPE
Expand Down
11 changes: 0 additions & 11 deletions move/move-ibc/sources/state_lens_lc.move
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,4 @@ module ibc::statelens_lc {

object::create_object_address(&vault_addr, bcs::to_bytes<u32>(&client_id))
}

#[test]
fun decode_test() {
let client_state = x"0531373030300100000013000000e898300000000000000020004000";
let client_state = decode_client_state(client_state);
let consensus_state =
x"000000000000000000000000000000000000000000000000181c75935aab8000f5c411575dae56d013ca1b7626896a9e96b457c14043091768d3d021fd5ebf333a42f6ef5bdc9ebe38b19ba1b8578f6e20e2a552bba787951c185159c721a165";
let consensus_state = decode_consensus_state(consensus_state);
std::debug::print(&client_state);
std::debug::print(&consensus_state);
}
}
6 changes: 6 additions & 0 deletions voyager/modules/client-bootstrap/movement/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ pub struct Config {
pub movement_rest_url: String,

/// The relayers that are allowed to modify this light client
///
/// Note that the light client had to be permissioned for now since
/// we are waiting for our [PR] to be merged so that we can fetch
/// the necessary proofs.
///
/// [PR]: https://github.com/movementlabsxyz/movement/pull/645
pub whitelisted_relayers: Vec<cosmwasm_std::Addr>,
}

Expand Down
16 changes: 6 additions & 10 deletions voyager/modules/client/state-lens/ics23-smt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ impl ClientModule for Module {
}
}

type SelfConsensusState = ConsensusState;
type SelfClientState = ClientState;

impl Module {
pub fn decode_consensus_state(consensus_state: &[u8]) -> RpcResult<SelfConsensusState> {
SelfConsensusState::decode_as::<EthAbi>(consensus_state).map_err(|err| {
pub fn decode_consensus_state(consensus_state: &[u8]) -> RpcResult<ConsensusState> {
ConsensusState::decode_as::<EthAbi>(consensus_state).map_err(|err| {
ErrorObject::owned(
FATAL_JSONRPC_ERROR_CODE,
format!("unable to decode consensus state: {err}"),
Expand All @@ -104,7 +101,7 @@ impl Module {
})
}

pub fn decode_client_state(&self, client_state: &[u8]) -> RpcResult<SelfClientState> {
pub fn decode_client_state(&self, client_state: &[u8]) -> RpcResult<ClientState> {
match self.ibc_interface {
SupportedIbcInterface::IbcSolidity => {
ClientState::abi_decode_params(client_state, true).map_err(|err| {
Expand All @@ -115,15 +112,14 @@ impl Module {
)
})
}
SupportedIbcInterface::IbcCosmwasm => {
<SelfClientState>::decode_as::<Bincode>(client_state).map_err(|err| {
SupportedIbcInterface::IbcCosmwasm => <ClientState>::decode_as::<Bincode>(client_state)
.map_err(|err| {
ErrorObject::owned(
FATAL_JSONRPC_ERROR_CODE,
format!("unable to decode client state: {err}"),
None::<()>,
)
})
}
}),
}
}

Expand Down
2 changes: 2 additions & 0 deletions voyager/plugins/transaction/aptos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ impl PluginServer<ModuleCall, ModuleCallback> for Module {

let signed_tx = raw.sign(pk, pk.public_key()).unwrap();

// TODO(aeryz): we normally should've send a batch transaction but
// movement don't allow it now.
dbg!(&signed_tx);
let res = self
.aptos_client
Expand Down

0 comments on commit cf67d42

Please sign in to comment.