From b2ca07dc3d2fdf3e498aaa2ebda7d49cd340fcd8 Mon Sep 17 00:00:00 2001 From: Vladislav Markushin Date: Thu, 28 Sep 2023 11:28:45 -0300 Subject: [PATCH] update ABI, small refactor --- hyperspace/ethereum/scripts/generate_abi.sh | 0 .../ethereum/src/abi/ibc-connection-abi.json | 13 + hyperspace/ethereum/src/abi/ibc-host-abi.json | 44 +-- .../ethereum/src/abi/ibc-packet-abi.json | 341 ++++++++++++++++++ .../src/abi/ics20-transfer-bank-abi.json | 72 ++++ hyperspace/ethereum/src/utils.rs | 48 ++- hyperspace/testsuite/tests/ethereum_cosmos.rs | 14 +- .../icsxx-ethereum/src/client_def.rs | 2 +- 8 files changed, 483 insertions(+), 51 deletions(-) mode change 100644 => 100755 hyperspace/ethereum/scripts/generate_abi.sh diff --git a/hyperspace/ethereum/scripts/generate_abi.sh b/hyperspace/ethereum/scripts/generate_abi.sh old mode 100644 new mode 100755 diff --git a/hyperspace/ethereum/src/abi/ibc-connection-abi.json b/hyperspace/ethereum/src/abi/ibc-connection-abi.json index 70fa13023..1f190b668 100644 --- a/hyperspace/ethereum/src/abi/ibc-connection-abi.json +++ b/hyperspace/ethereum/src/abi/ibc-connection-abi.json @@ -527,5 +527,18 @@ ], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [], + "name": "getCommitmentPrefix", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "pure", + "type": "function" } ] diff --git a/hyperspace/ethereum/src/abi/ibc-host-abi.json b/hyperspace/ethereum/src/abi/ibc-host-abi.json index c0541973d..7b09de627 100644 --- a/hyperspace/ethereum/src/abi/ibc-host-abi.json +++ b/hyperspace/ethereum/src/abi/ibc-host-abi.json @@ -171,12 +171,12 @@ { "components": [ { - "internalType": "enum Channel.State", + "internalType": "enum ChannelState", "name": "state", "type": "uint8" }, { - "internalType": "enum Channel.Order", + "internalType": "enum ChannelOrder", "name": "ordering", "type": "uint8" }, @@ -193,7 +193,7 @@ "type": "string" } ], - "internalType": "struct ChannelCounterparty.Data", + "internalType": "struct ChannelCounterpartyData", "name": "counterparty", "type": "tuple" }, @@ -208,7 +208,7 @@ "type": "string" } ], - "internalType": "struct Channel.Data", + "internalType": "struct ChannelData", "name": "channel", "type": "tuple" }, @@ -318,12 +318,12 @@ "type": "string[]" } ], - "internalType": "struct Version.Data[]", + "internalType": "struct VersionData[]", "name": "versions", "type": "tuple[]" }, { - "internalType": "enum ConnectionEnd.State", + "internalType": "enum ConnectionEndState", "name": "state", "type": "uint8" }, @@ -347,12 +347,12 @@ "type": "bytes" } ], - "internalType": "struct MerklePrefix.Data", + "internalType": "struct MerklePrefixData", "name": "prefix", "type": "tuple" } ], - "internalType": "struct Counterparty.Data", + "internalType": "struct CounterpartyData", "name": "counterparty", "type": "tuple" }, @@ -362,7 +362,7 @@ "type": "uint64" } ], - "internalType": "struct ConnectionEnd.Data", + "internalType": "struct ConnectionEndData", "name": "connection", "type": "tuple" }, @@ -797,7 +797,7 @@ "type": "uint64" } ], - "internalType": "struct Height.Data", + "internalType": "struct HeightData", "name": "timeout_height", "type": "tuple" }, @@ -807,7 +807,7 @@ "type": "uint64" } ], - "internalType": "struct Packet.Data", + "internalType": "struct PacketData", "name": "packet", "type": "tuple" } @@ -852,12 +852,12 @@ { "components": [ { - "internalType": "enum Channel.State", + "internalType": "enum ChannelState", "name": "state", "type": "uint8" }, { - "internalType": "enum Channel.Order", + "internalType": "enum ChannelOrder", "name": "ordering", "type": "uint8" }, @@ -874,7 +874,7 @@ "type": "string" } ], - "internalType": "struct ChannelCounterparty.Data", + "internalType": "struct ChannelCounterpartyData", "name": "counterparty", "type": "tuple" }, @@ -889,7 +889,7 @@ "type": "string" } ], - "internalType": "struct Channel.Data", + "internalType": "struct ChannelData", "name": "channel", "type": "tuple" } @@ -980,12 +980,12 @@ "type": "string[]" } ], - "internalType": "struct Version.Data[]", + "internalType": "struct VersionData[]", "name": "versions", "type": "tuple[]" }, { - "internalType": "enum ConnectionEnd.State", + "internalType": "enum ConnectionEndState", "name": "state", "type": "uint8" }, @@ -1009,12 +1009,12 @@ "type": "bytes" } ], - "internalType": "struct MerklePrefix.Data", + "internalType": "struct MerklePrefixData", "name": "prefix", "type": "tuple" } ], - "internalType": "struct Counterparty.Data", + "internalType": "struct CounterpartyData", "name": "counterparty", "type": "tuple" }, @@ -1024,7 +1024,7 @@ "type": "uint64" } ], - "internalType": "struct ConnectionEnd.Data", + "internalType": "struct ConnectionEndData", "name": "connection", "type": "tuple" } @@ -1242,7 +1242,7 @@ "type": "uint64" } ], - "internalType": "struct Height.Data", + "internalType": "struct HeightData", "name": "timeout_height", "type": "tuple" }, @@ -1252,7 +1252,7 @@ "type": "uint64" } ], - "internalType": "struct Packet.Data", + "internalType": "struct PacketData", "name": "packet", "type": "tuple" } diff --git a/hyperspace/ethereum/src/abi/ibc-packet-abi.json b/hyperspace/ethereum/src/abi/ibc-packet-abi.json index 8eb54db04..ec769b177 100644 --- a/hyperspace/ethereum/src/abi/ibc-packet-abi.json +++ b/hyperspace/ethereum/src/abi/ibc-packet-abi.json @@ -206,6 +206,73 @@ "name": "SendPacket", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint64", + "name": "sequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "string", + "name": "source_port", + "type": "string" + }, + { + "indexed": true, + "internalType": "string", + "name": "source_channel", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "destination_port", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "destination_channel", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "indexed": false, + "internalType": "struct HeightData", + "name": "timeout_height", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "timeout_timestamp", + "type": "uint64" + } + ], + "name": "TimeoutOnClosePacket", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -273,6 +340,73 @@ "name": "TimeoutPacket", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint64", + "name": "sequence", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "string", + "name": "source_port", + "type": "string" + }, + { + "indexed": true, + "internalType": "string", + "name": "source_channel", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "destination_port", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "destination_channel", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "indexed": false, + "internalType": "struct HeightData", + "name": "timeout_height", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "timeout_timestamp", + "type": "uint64" + } + ], + "name": "TimeoutPacket", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -564,6 +698,213 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "components": [ + { + "components": [ + { + "internalType": "uint64", + "name": "sequence", + "type": "uint64" + }, + { + "internalType": "string", + "name": "source_port", + "type": "string" + }, + { + "internalType": "string", + "name": "source_channel", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_port", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_channel", + "type": "string" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "internalType": "struct HeightData", + "name": "timeout_height", + "type": "tuple" + }, + { + "internalType": "uint64", + "name": "timeout_timestamp", + "type": "uint64" + } + ], + "internalType": "struct PacketData", + "name": "packet", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "proofUnreceived", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "proofClose", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "internalType": "struct HeightData", + "name": "proofHeight", + "type": "tuple" + }, + { + "internalType": "uint64", + "name": "nextSequenceRecv", + "type": "uint64" + } + ], + "internalType": "struct IBCMsgsMsgTimeoutOnClose", + "name": "msg_", + "type": "tuple" + } + ], + "name": "timeoutOnClose", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "components": [ + { + "internalType": "uint64", + "name": "sequence", + "type": "uint64" + }, + { + "internalType": "string", + "name": "source_port", + "type": "string" + }, + { + "internalType": "string", + "name": "source_channel", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_port", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_channel", + "type": "string" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "internalType": "struct HeightData", + "name": "timeout_height", + "type": "tuple" + }, + { + "internalType": "uint64", + "name": "timeout_timestamp", + "type": "uint64" + } + ], + "internalType": "struct PacketData", + "name": "packet", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "proof", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "internalType": "struct HeightData", + "name": "proofHeight", + "type": "tuple" + }, + { + "internalType": "uint64", + "name": "nextSequenceRecv", + "type": "uint64" + } + ], + "internalType": "struct IBCMsgsMsgTimeoutPacket", + "name": "msg_", + "type": "tuple" + } + ], + "name": "timeoutPacket", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/hyperspace/ethereum/src/abi/ics20-transfer-bank-abi.json b/hyperspace/ethereum/src/abi/ics20-transfer-bank-abi.json index abf1b6ae6..a77bed825 100644 --- a/hyperspace/ethereum/src/abi/ics20-transfer-bank-abi.json +++ b/hyperspace/ethereum/src/abi/ics20-transfer-bank-abi.json @@ -402,6 +402,78 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint64", + "name": "sequence", + "type": "uint64" + }, + { + "internalType": "string", + "name": "source_port", + "type": "string" + }, + { + "internalType": "string", + "name": "source_channel", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_port", + "type": "string" + }, + { + "internalType": "string", + "name": "destination_channel", + "type": "string" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "revision_number", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "revision_height", + "type": "uint64" + } + ], + "internalType": "struct HeightData", + "name": "timeout_height", + "type": "tuple" + }, + { + "internalType": "uint64", + "name": "timeout_timestamp", + "type": "uint64" + } + ], + "internalType": "struct PacketData", + "name": "packet", + "type": "tuple" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "onTimeoutPacket", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/hyperspace/ethereum/src/utils.rs b/hyperspace/ethereum/src/utils.rs index e75f44454..b7ed66b40 100644 --- a/hyperspace/ethereum/src/utils.rs +++ b/hyperspace/ethereum/src/utils.rs @@ -17,13 +17,13 @@ use ethers_solc::{ output_selection::OutputSelection, Libraries, Optimizer, OptimizerDetails, Settings, StorageLayout, }, - Artifact, ConfigurableContractArtifact, EvmVersion, Project, ProjectCompileOutput, - ProjectPathsConfig, SolcConfig, + Artifact, ArtifactOutput, ConfigurableContractArtifact, EvmVersion, Project, + ProjectCompileOutput, ProjectPathsConfig, SolcConfig, }; use ibc::core::{ics02_client::client_state::ClientType, ics04_channel::packet::Packet}; use std::{ borrow::Borrow, - collections::HashMap, + collections::{HashMap, HashSet}, fs::File, iter::once, path::{Path, PathBuf}, @@ -702,6 +702,30 @@ where .collect() } +pub fn check_code_size<'a>( + artifacts: impl Iterator, +) { + let ignore_list = ["Verifier"].into_iter().collect::>(); + artifacts + .filter_map(|(name, artifact)| { + Some((name, artifact.bytecode.as_ref()?.object.as_bytes()?.len())) + }) + .filter(|(name, _)| { + let ignored = ignore_list.contains(name.as_str()); + if ignored { + log::warn!("{} size is ignored", name); + } + !ignored + }) + .for_each(|(name, size)| { + let max = 24 * 1024; + if size > max { + panic!("{} size is too big: {}/{}", name, size, max); + } + log::info!("{} size: {}/{}", name, size, max); + }); +} + pub async fn deploy_yui_ibc( project_output: &ProjectCompileOutput, diamond_project_output: &ProjectCompileOutput, @@ -722,22 +746,8 @@ where OwnershipFacet, ]; - project_output.artifacts().for_each(|(name, artifact)| { - let size = artifact.bytecode.as_ref().unwrap().object.as_bytes().unwrap().len(); - let max = 24 * 1024; - if size > max { - panic!("{} size is too big: {}/{}", name, size, max); - } - log::info!("{} size: {}/{}", name, size, max); - }); - diamond_project_output.artifacts().for_each(|(name, artifact)| { - let size = artifact.bytecode.as_ref().unwrap().object.as_bytes().unwrap().len(); - let max = 24 * 1024; - if size > max { - panic!("{} size is too big: {}/{}", name, size, max); - } - log::info!("{} size: {}/{}", name, size, max); - }); + check_code_size(project_output.artifacts()); + check_code_size(diamond_project_output.artifacts()); let acc = client.default_sender().unwrap(); diff --git a/hyperspace/testsuite/tests/ethereum_cosmos.rs b/hyperspace/testsuite/tests/ethereum_cosmos.rs index ffe44be64..052bac56b 100644 --- a/hyperspace/testsuite/tests/ethereum_cosmos.rs +++ b/hyperspace/testsuite/tests/ethereum_cosmos.rs @@ -39,6 +39,10 @@ use hyperspace_ethereum::{ }, utils::{DeployYuiIbc, ProviderImpl}, }; +use hyperspace_ethereum::{ + ibc_provider::{Ics20BankAbi, SendPacketFilter, TransferInitiatedFilter}, + utils::check_code_size, +}; use hyperspace_parachain::{finality_protocol::FinalityProtocol, ParachainClientConfig}; use hyperspace_primitives::{utils::create_clients, CommonClientConfig, IbcProvider}; use hyperspace_testsuite::{ @@ -111,15 +115,7 @@ pub async fn deploy_yui_ibc_and_tendermint_client_fixture() -> DeployYuiIbcTende ) .await; - project_output1.artifacts().for_each(|(name, artifact)| { - if let Some(size) = artifact.bytecode.as_ref().unwrap().object.as_bytes().map(|x| x.len()) { - let max = 24 * 1024; - if size > max { - log::warn!("{} size is too big: {}/{}", name, size, max); - } - log::info!("{} size: {}/{}", name, size, max); - } - }); + check_code_size(project_output1.artifacts()); let upd = project_output1.find_first("DelegateTendermintUpdate").unwrap(); let (abi, bytecode, _) = upd.clone().into_parts(); diff --git a/light-clients/icsxx-ethereum/src/client_def.rs b/light-clients/icsxx-ethereum/src/client_def.rs index 5ba941f59..e5b0508a5 100644 --- a/light-clients/icsxx-ethereum/src/client_def.rs +++ b/light-clients/icsxx-ethereum/src/client_def.rs @@ -145,7 +145,7 @@ where b.execution_payload.block_number as u64, ); let cs = Ctx::AnyConsensusState::wrap(&ConsensusState::new( - b.execution_payload.state_root.clone(), // b.header.state_root? + b.execution_payload.state_root.clone(), b.execution_payload.timestamp, )) .unwrap();