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

Update yui-relayer to 0.4.22 #25

Merged
merged 4 commits into from
Jan 27, 2024
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
2 changes: 1 addition & 1 deletion e2e/config/demo/ibc-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mnemonic": "math razor capable expose worth grape metal sunset metal sudden usage scheme",
"path": "m/44'/60'/0'/0/0"
},
"ibc_address": "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841",
"ibc_address": "0xaa43d337145E8930d01cb4E60Abf6595C692921E",
"initial_send_checkpoint": 0,
"initial_recv_checkpoint": 0,
"enable_debug_trace": false,
Expand Down
2 changes: 1 addition & 1 deletion e2e/config/demo/ibc-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mnemonic": "math razor capable expose worth grape metal sunset metal sudden usage scheme",
"path": "m/44'/60'/0'/0/0"
},
"ibc_address": "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841",
"ibc_address": "0xaa43d337145E8930d01cb4E60Abf6595C692921E",
"initial_send_checkpoint": 0,
"initial_recv_checkpoint": 0,
"enable_debug_trace": false,
Expand Down
2 changes: 2 additions & 0 deletions e2e/contracts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.PHONY:deploy
deploy:
npm i
cp truffle-config.js node_modules/@hyperledger-labs/yui-ibc-solidity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest yui-ibc-solidity doesn't use truffle. But this e2e still uses truffle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshidan If you just want the compiler to recognize it as target, might be better to put a file like this in contracts/ instead

cd node_modules/@hyperledger-labs/yui-ibc-solidity && npx truffle compile
npx truffle migrate --network bsc_local2 --reset
npx truffle migrate --network bsc_local --reset

Expand Down
68 changes: 33 additions & 35 deletions e2e/contracts/contracts/clients/ParliaClient.sol
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
pragma solidity ^0.8.12;

import "@hyperledger-labs/yui-ibc-solidity/contracts/core/02-client/ILightClient.sol";
import "@hyperledger-labs/yui-ibc-solidity/contracts/core/02-client/IBCHeight.sol";
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/Client.sol";
import {
IbcLightclientsParliaV1ClientState as ClientState,
IbcLightclientsParliaV1ConsensusState as ConsensusState,
IbcLightclientsParliaV1Header as Header
IbcLightclientsParliaV1ClientState as ClientState,
IbcLightclientsParliaV1ConsensusState as ConsensusState,
IbcLightclientsParliaV1Header as Header
} from "../ibc/lightclients/parlia/v1/parlia.sol";
import {GoogleProtobufAny as Any} from "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol";
import "solidity-bytes-utils/contracts/BytesLib.sol";
import "solidity-rlp/contracts/Helper.sol";
import "solidity-mpt/src/MPTProof.sol";

contract ParliaClient is ILightClient {
using MPTProof for bytes;
using RLPReader for bytes;
using RLPReader for RLPReader.RLPItem;
using BytesLib for bytes;
using IBCHeight for Height.Data;

///ibc.lightclients.${module}.v1.${resource}
Expand All @@ -28,9 +26,9 @@ contract ParliaClient is ILightClient {

bytes32 private constant HEADER_TYPE_URL_HASH = keccak256(abi.encodePacked(HEADER_TYPE_URL));
bytes32 private constant CLIENT_STATE_TYPE_URL_HASH =
keccak256(abi.encodePacked(CLIENT_STATE_TYPE_URL));
keccak256(abi.encodePacked(CLIENT_STATE_TYPE_URL));
bytes32 private constant CONSENSUS_STATE_TYPE_URL_HASH =
keccak256(abi.encodePacked(CONSENSUS_STATE_TYPE_URL));
keccak256(abi.encodePacked(CONSENSUS_STATE_TYPE_URL));

uint256 private constant COMMITMENT_SLOT = 0;
uint8 private constant ACCOUNT_STORAGE_ROOT_INDEX = 2;
Expand Down Expand Up @@ -83,20 +81,20 @@ contract ParliaClient is ILightClient {
consensusStates[clientId][height.toUint128()] = consensusState;
statuses[clientId] = ClientStatus.Active;
return (
keccak256(clientStateBytes),
ConsensusStateUpdate({consensusStateCommitment: keccak256(consensusStateBytes), height: height}),
true
keccak256(clientStateBytes),
ConsensusStateUpdate({consensusStateCommitment: keccak256(consensusStateBytes), height: height}),
true
);
}

/**
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
*/
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
external
view
override
returns (uint64, bool)
external
view
override
returns (uint64, bool)
{
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
return (consensusState.timestamp, consensusState.timestamp != 0);
Expand All @@ -119,10 +117,10 @@ contract ParliaClient is ILightClient {
* 5. persist the state(s) on the host
*/
function updateClient(string calldata clientId, bytes calldata clientMessageBytes)
external
onlyIBC
override
returns (bytes32 clientStateCommitment, ConsensusStateUpdate[] memory updates, bool ok)
external
onlyIBC
override
returns (bytes32 clientStateCommitment, ConsensusStateUpdate[] memory updates, bool ok)
{
Height.Data memory height;
uint64 timestamp;
Expand All @@ -144,14 +142,14 @@ contract ParliaClient is ILightClient {
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
consensusState.timestamp = timestamp;
consensusState.state_root = abi.encodePacked(
verifyStorageProof(BytesLib.toAddress(clientState.ibc_store_address, 0), stateRoot, accountProof));
verifyStorageProof(address(bytes20(clientState.ibc_store_address)), stateRoot, accountProof));

anyConsensusState.type_url = CONSENSUS_STATE_TYPE_URL;
anyConsensusState.value = ConsensusState.encode(consensusState);

updates = new ConsensusStateUpdate[](1);
updates[0] =
ConsensusStateUpdate({consensusStateCommitment: keccak256(Any.encode(anyConsensusState)), height: height});
ConsensusStateUpdate({consensusStateCommitment: keccak256(Any.encode(anyConsensusState)), height: height});
return (keccak256(Any.encode(anyClientState)), updates, true);
}

Expand All @@ -173,7 +171,7 @@ contract ParliaClient is ILightClient {
require(consensusState.timestamp != 0, "consensus state not found");
return verifyMembership(
proof,
consensusState.state_root.toBytes32(0),
bytes32(consensusState.state_root),
keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT)),
keccak256(value)
);
Expand All @@ -195,7 +193,7 @@ contract ParliaClient is ILightClient {
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
require(consensusState.timestamp != 0, "consensus state not found");
return verifyNonMembership(
proof, consensusState.state_root.toBytes32(0), keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT))
proof, bytes32(consensusState.state_root), keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT))
);
}

Expand Down Expand Up @@ -228,8 +226,8 @@ contract ParliaClient is ILightClient {
) external view returns (bytes memory clientStateBytes, bool) {
ClientState.Data storage clientState = clientStates[clientId];
return (Any.encode(Any.Data({
type_url: CLIENT_STATE_TYPE_URL,
value: ClientState.encode(clientState)
type_url: CLIENT_STATE_TYPE_URL,
value: ClientState.encode(clientState)
})), true);
}

Expand All @@ -243,8 +241,8 @@ contract ParliaClient is ILightClient {
) external view returns (bytes memory consensusStateBytes, bool) {
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
return (Any.encode(Any.Data({
type_url: CONSENSUS_STATE_TYPE_URL,
value: ConsensusState.encode(consensusState)
type_url: CONSENSUS_STATE_TYPE_URL,
value: ConsensusState.encode(consensusState)
})), true);
}

Expand All @@ -259,14 +257,14 @@ contract ParliaClient is ILightClient {
RLPReader.RLPItem[] memory items = rlpEthHeader.toRlpItem().toList();
Height.Data memory height = Height.Data({revision_number: 0, revision_height: uint64(items[8].toUint())});
uint64 timestamp = uint64(items[11].toUint());
bytes32 stateRoot = items[3].toBytes().toBytes32(0);
bytes32 stateRoot = bytes32(items[3].toBytes());
return (height,stateRoot, timestamp, header.account_proof);
}

function unmarshalClientState(bytes calldata bz)
internal
pure
returns (ClientState.Data memory clientState, bool ok)
internal
pure
returns (ClientState.Data memory clientState, bool ok)
{
Any.Data memory anyClientState = Any.decode(bz);
if (keccak256(abi.encodePacked(anyClientState.type_url)) != CLIENT_STATE_TYPE_URL_HASH) {
Expand All @@ -276,9 +274,9 @@ contract ParliaClient is ILightClient {
}

function unmarshalConsensusState(bytes calldata bz)
internal
pure
returns (ConsensusState.Data memory consensusState, bool ok)
internal
pure
returns (ConsensusState.Data memory consensusState, bool ok)
{
Any.Data memory anyConsensusState = Any.decode(bz);
if (keccak256(abi.encodePacked(anyConsensusState.type_url)) != CONSENSUS_STATE_TYPE_URL_HASH) {
Expand All @@ -301,4 +299,4 @@ contract ParliaClient is ILightClient {
require(msg.sender == ibcHandler);
_;
}
}
}
2 changes: 1 addition & 1 deletion e2e/contracts/contracts/ibc/core/client/v1/client.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
pragma solidity ^0.8.12;
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol";
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
pragma solidity ^0.8.12;
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol";
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
pragma solidity ^0.8.12;
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol";
import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol";
import "../../../core/client/v1/client.sol";
Expand Down
10 changes: 6 additions & 4 deletions e2e/contracts/migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const IBCClient = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCClient");
const IBCConnection = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCConnection");
const IBCConnection = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCConnectionSelfStateNoValidation");
const IBCChannelHandshake = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCChannelHandshake");
const IBCPacket = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCPacket");
const IBCChannelPacketSendRecv = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCChannelPacketSendRecv");
const IBCChannelPacketTimeout = artifacts.require("@hyperledger-labs/yui-ibc-solidity/IBCChannelPacketTimeout");
const IBCHandler = artifacts.require("@hyperledger-labs/yui-ibc-solidity/OwnableIBCHandler");
const ERC20Token = artifacts.require("@hyperledger-labs/yui-ibc-solidity/ERC20Token");
const ICS20TransferBank = artifacts.require("@hyperledger-labs/yui-ibc-solidity/ICS20TransferBank");
Expand All @@ -12,8 +13,9 @@ module.exports = async function (deployer) {
await deployer.deploy(IBCClient);
await deployer.deploy(IBCConnection);
await deployer.deploy(IBCChannelHandshake);
await deployer.deploy(IBCPacket);
await deployer.deploy(IBCHandler, IBCClient.address, IBCConnection.address, IBCChannelHandshake.address, IBCPacket.address);
await deployer.deploy(IBCChannelPacketSendRecv);
await deployer.deploy(IBCChannelPacketTimeout);
await deployer.deploy(IBCHandler, IBCClient.address, IBCConnection.address, IBCChannelHandshake.address, IBCChannelPacketSendRecv.address, IBCChannelPacketTimeout.address);

await deployer.deploy(ParliaClient, IBCHandler.address);
await deployer.deploy(ERC20Token, "simple_erc_20_token_for_test", "simple_erc_20_token_for_test", 1000000);
Expand Down
Loading
Loading