From bb68983ac67e16f34fd80f5bda8159bda06612d2 Mon Sep 17 00:00:00 2001 From: kaancaglan Date: Thu, 9 Jan 2025 12:52:33 +0300 Subject: [PATCH] chore(move): nix-fmt applied Signed-off-by: kaancaglan --- .../sources/move_in_cosmos_client.move | 115 ++++++++++-------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/move/move-ibc/sources/move_in_cosmos_client.move b/move/move-ibc/sources/move_in_cosmos_client.move index c3bf2185d9..46e4a345f2 100644 --- a/move/move-ibc/sources/move_in_cosmos_client.move +++ b/move/move-ibc/sources/move_in_cosmos_client.move @@ -2,7 +2,6 @@ module ibc::move_in_cosmos_client { use std::signer; use aptos_std::vector; use aptos_std::aptos_hash::keccak256; - use aptos_std::error; use std::event; use std::object; use aptos_std::copyable_any; @@ -33,14 +32,14 @@ module ibc::move_in_cosmos_client { l2_latest_height: u64, timestamp_offset: u16, state_root_offset: u16, - storage_root_offset: u16, + storage_root_offset: u16 } /// Consensus State struct ConsensusState has copy, drop, store { timestamp: u64, state_root: vector, - storage_root: vector, + storage_root: vector } /// Header @@ -48,15 +47,16 @@ module ibc::move_in_cosmos_client { l1_height: u64, l2_height: u64, l2_inclusion_proof: vector, - l2_consensus_state: vector, + l2_consensus_state: vector } /// ConsensusStateUpdate struct ConsensusStateUpdate has copy, drop, store { client_state_commitment: vector, consensus_state_commitment: vector, - height: u64, + height: u64 } + struct ConsensusStatesTuple has copy, drop, store { client_id: u32, l2_height: u64 @@ -74,7 +74,7 @@ module ibc::move_in_cosmos_client { /// Storage for the module struct EvmInCosmosStorage has key { client_states: Table, - consensus_states: Table, + consensus_states: Table } struct SignerRef has key { @@ -99,12 +99,10 @@ module ibc::move_in_cosmos_client { /// Initialize the module storage fun init_module(account: &signer) { - assert!( - signer::address_of(account) == @ibc, ERR_NOT_IBC - ); + assert!(signer::address_of(account) == @ibc, ERR_NOT_IBC); let storage = EvmInCosmosStorage { client_states: table::new(), - consensus_states: table::new(), + consensus_states: table::new() }; let vault_constructor_ref = &object::create_named_object(account, VAULT_SEED); @@ -125,12 +123,10 @@ module ibc::move_in_cosmos_client { public fun create_client( account: &signer, client_id: u32, - client_state_bcs: copyable_any::Any,//vector, + client_state_bcs: copyable_any::Any, //vector, consensus_state_bcs: copyable_any::Any //vector - ): ConsensusStateUpdate acquires EvmInCosmosStorage{ - assert!( - signer::address_of(account) == @ibc, ERR_NOT_IBC - ); + ): ConsensusStateUpdate acquires EvmInCosmosStorage { + assert!(signer::address_of(account) == @ibc, ERR_NOT_IBC); let store = borrow_global_mut(get_vault_addr()); let client_state = copyable_any::unpack(client_state_bcs); @@ -166,20 +162,17 @@ module ibc::move_in_cosmos_client { ConsensusStateUpdate { client_state_commitment, consensus_state_commitment, - height: client_state.l2_latest_height, + height: client_state.l2_latest_height } } public fun misbehaviour( - _client_id: u32, - _client_msg_bytes: vector + _client_id: u32, _client_msg_bytes: vector ) { - abort ERR_UNSUPPORTED + abort ERR_UNSUPPORTED } - public fun is_frozen( - client_id: u32 - ): bool { + public fun is_frozen(client_id: u32): bool { cometbls_lc::is_frozen(client_id) } @@ -189,9 +182,9 @@ module ibc::move_in_cosmos_client { height: u64, proof: &vector, path: &vector, - value: &vector, + value: &vector ): bool acquires EvmInCosmosStorage { - if(is_frozen(client_id)) { + if (is_frozen(client_id)) { abort ERR_CLIENT_FROZEN }; let store = borrow_global(get_vault_addr()); @@ -205,12 +198,18 @@ module ibc::move_in_cosmos_client { l2_height: height }; - let cons_state: ConsensusState = *table::borrow(&store.consensus_states, cons_state_tuple); + let cons_state: ConsensusState = + *table::borrow(&store.consensus_states, cons_state_tuple); let storage_root = cons_state.storage_root; - let (is_exist, proven_value) = mpt_verifier::verify_trie_value(proof, &keccak256(slot), storage_root); - - is_exist && (mpt_verifier::encode_uint(mpt_verifier::load_u256_big_endian(value)) == keccak256(proven_value)) + let (is_exist, proven_value) = + mpt_verifier::verify_trie_value(proof, &keccak256(slot), storage_root); + + is_exist + && ( + mpt_verifier::encode_uint(mpt_verifier::load_u256_big_endian(value)) + == keccak256(proven_value) + ) } /// Verify non-membership in the trie @@ -218,9 +217,9 @@ module ibc::move_in_cosmos_client { client_id: u32, height: u64, proof: &vector, - path: &vector, + path: &vector ): bool acquires EvmInCosmosStorage { - if(is_frozen(client_id)) { + if (is_frozen(client_id)) { abort ERR_CLIENT_FROZEN }; let store = borrow_global(get_vault_addr()); @@ -234,16 +233,16 @@ module ibc::move_in_cosmos_client { l2_height: height }; - let cons_state: ConsensusState = *table::borrow(&store.consensus_states, cons_state_tuple); + let cons_state: ConsensusState = + *table::borrow(&store.consensus_states, cons_state_tuple); let storage_root = cons_state.storage_root; + let (is_exist, _proven_value) = + mpt_verifier::verify_trie_value(proof, &keccak256(slot), storage_root); - let (is_exist, _proven_value) = mpt_verifier::verify_trie_value(proof, &keccak256(slot), storage_root); - - !is_exist + !is_exist } - /// Update the client with a new header public fun update_client( _account: &signer, // TODO: not sure if this is needed @@ -253,29 +252,44 @@ module ibc::move_in_cosmos_client { let store = borrow_global_mut(get_vault_addr()); let header = copyable_any::unpack
(header_bcs); - + let client_state = table::borrow_mut(&mut store.client_states, client_id); - let proof = commitment::consensus_state_commitment_key( - client_state.l2_client_id, - header.l2_height - ); + let proof = + commitment::consensus_state_commitment_key( + client_state.l2_client_id, header.l2_height + ); - if(cometbls_lc::verify_membership( + if (cometbls_lc::verify_membership( client_state.l1_client_id, header.l1_height, header.l2_inclusion_proof, proof, keccak256(header.l2_consensus_state) - ) != 0 ) { // TODO: its returning u64 not bool + ) != 0) { // TODO: its returning u64 not bool abort ERR_INVALID_L1_PROOF }; let raw_l2_consensus_state = &header.l2_consensus_state; // TODO: Not sure about the below - let l2_timestamp = from_bcs::to_u64(vector::slice(raw_l2_consensus_state, (client_state.timestamp_offset as u64), (client_state.timestamp_offset as u64) + 8)); - let l2_state_root = vector::slice(raw_l2_consensus_state, (client_state.state_root_offset as u64), (client_state.state_root_offset as u64) + 32); - let l2_storage_root = vector::slice(raw_l2_consensus_state, (client_state.storage_root_offset as u64), (client_state.storage_root_offset as u64) + 32); + let l2_timestamp = + from_bcs::to_u64( + vector::slice( + raw_l2_consensus_state, + (client_state.timestamp_offset as u64), + (client_state.timestamp_offset as u64) + 8 + ) + ); + let l2_state_root = vector::slice( + raw_l2_consensus_state, + (client_state.state_root_offset as u64), + (client_state.state_root_offset as u64) + 32 + ); + let l2_storage_root = vector::slice( + raw_l2_consensus_state, + (client_state.storage_root_offset as u64), + (client_state.storage_root_offset as u64) + 32 + ); if (header.l2_height > client_state.l2_latest_height) { client_state.l2_latest_height = header.l2_height; @@ -284,7 +298,7 @@ module ibc::move_in_cosmos_client { let consensus_state = ConsensusState { timestamp: l2_timestamp, state_root: l2_state_root, - storage_root: l2_storage_root, + storage_root: l2_storage_root }; let cons_state_tuple = ConsensusStatesTuple { client_id: client_id, @@ -297,16 +311,13 @@ module ibc::move_in_cosmos_client { ); let client_state_commitment = keccak256(bcs::to_bytes(client_state)); - let consensus_state_commitment = keccak256(bcs::to_bytes(&consensus_state)); + let consensus_state_commitment = + keccak256(bcs::to_bytes(&consensus_state)); ConsensusStateUpdate { client_state_commitment, consensus_state_commitment, - height: header.l2_height, + height: header.l2_height } } - - - - }