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 ethereum-ibc-relay-chain to v0.2.13 #26

Merged
merged 1 commit into from
Mar 22, 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: 0 additions & 2 deletions e2e/contracts/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.PHONY:deploy
deploy:
npm i
cp truffle-config.js node_modules/@hyperledger-labs/yui-ibc-solidity
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
16 changes: 16 additions & 0 deletions e2e/contracts/contracts/Dependencies.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.12;

import {IBCClient} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/02-client/IBCClient.sol";
import {IBCConnectionSelfStateNoValidation} from
"@hyperledger-labs/yui-ibc-solidity/contracts/core/03-connection/IBCConnectionSelfStateNoValidation.sol";
import {IBCChannelHandshake} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/04-channel/IBCChannelHandshake.sol";
import {IBCChannelPacketSendRecv} from
"@hyperledger-labs/yui-ibc-solidity/contracts/core/04-channel/IBCChannelPacketSendRecv.sol";
import {IBCChannelPacketTimeout} from
"@hyperledger-labs/yui-ibc-solidity/contracts/core/04-channel/IBCChannelPacketTimeout.sol";
import {IIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-handler/IIBCHandler.sol";
import {OwnableIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-handler/OwnableIBCHandler.sol";
import {ERC20Token} from "@hyperledger-labs/yui-ibc-solidity/contracts/apps/20-transfer/ERC20Token.sol";
import {ICS20TransferBank} from "@hyperledger-labs/yui-ibc-solidity/contracts/apps/20-transfer/ICS20TransferBank.sol";
import {ICS20Bank} from "@hyperledger-labs/yui-ibc-solidity/contracts/apps/20-transfer/ICS20Bank.sol";
107 changes: 39 additions & 68 deletions e2e/contracts/contracts/clients/ParliaClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,31 @@ contract ParliaClient is ILightClient {
}

/**
* @dev createClient creates a new client with the given state
* @dev initializeClient creates a new client with the given state
*/
function createClient(string calldata clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes)
external
override
onlyIBC
returns (bytes32 clientStateCommitment, ConsensusStateUpdate memory update, bool ok) {
function initializeClient(string calldata clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes)
external virtual override onlyIBC
returns (Height.Data memory height) {
ClientState.Data memory clientState;
ConsensusState.Data memory consensusState;
bool ok;

(clientState, ok) = unmarshalClientState(clientStateBytes);
if (!ok) {
return (clientStateCommitment, update, false);
revert("invalid client state");
}
(consensusState, ok) = unmarshalConsensusState(consensusStateBytes);
if (!ok) {
return (clientStateCommitment, update, false);
revert("invalid cons state");
}
/* can be genesis block
if (
clientState.latest_height.revision_height == 0 || consensusState.timestamp == 0
) {
return (clientStateCommitment, update, false);
}
*/

Height.Data memory height;
height.revision_height = clientState.latest_height.revision_height;
height.revision_number = clientState.latest_height.revision_number;

clientStates[clientId] = clientState;
consensusStates[clientId][height.toUint128()] = consensusState;
statuses[clientId] = ClientStatus.Active;
return (
keccak256(clientStateBytes),
ConsensusStateUpdate({consensusStateCommitment: keccak256(consensusStateBytes), height: height}),
true
);
return Height.Data({revision_number: 0, revision_height: clientState.latest_height.revision_height});
}

/**
Expand All @@ -94,18 +81,29 @@ contract ParliaClient is ILightClient {
external
view
override
returns (uint64, bool)
returns (uint64)
{
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
return (consensusState.timestamp, consensusState.timestamp != 0);
return consensusState.timestamp;
}

/**
* @dev getLatestHeight returns the latest height of the client state corresponding to `clientId`.
*/
function getLatestHeight(string calldata clientId) external view override returns (Height.Data memory, bool) {
function getLatestHeight(string calldata clientId) external view virtual override returns (Height.Data memory) {
ClientState.Data storage clientState = clientStates[clientId];
return (Height.Data({revision_number: 0, revision_height: clientState.latest_height.revision_height}), clientState.latest_height.revision_height != 0);
return Height.Data({revision_number: 0, revision_height: clientState.latest_height.revision_height});
}

/**
* @dev routeUpdateClient returns the calldata to the receiving function of the client message.
* The light client encodes a client message as ethereum ABI.
*/
function routeUpdateClient(string calldata clientId, bytes calldata protoClientMessage) external pure virtual override returns (bytes4, bytes memory)
{
Any.Data memory any = Any.decode(protoClientMessage);
Header.Data memory header = Header.decode(any.value);
return (this.updateClient.selector, abi.encode(clientId, header));
}

/**
Expand All @@ -116,41 +114,27 @@ contract ParliaClient is ILightClient {
* 4. update state(s) with the client message
* 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)
function updateClient(string calldata clientId, Header.Data calldata header)
public
returns (Height.Data[] memory heights)
{
Height.Data memory height;
uint64 timestamp;
bytes32 stateRoot;
bytes memory accountProof;
Any.Data memory anyClientState;
Any.Data memory anyConsensusState;

(height, stateRoot, timestamp, accountProof) = parseHeader(clientMessageBytes);

ClientState.Data storage clientState = clientStates[clientId];
clientState.latest_height.revision_number = height.revision_number;
clientState.latest_height.revision_height = height.revision_height;
anyClientState.type_url = CLIENT_STATE_TYPE_URL;
anyClientState.value = ClientState.encode(clientState);
bytes memory rlpEthHeader = header.headers[0].header;
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 = bytes32(items[3].toBytes());

//TODO verify header

ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
consensusState.timestamp = timestamp;
consensusState.state_root = abi.encodePacked(
verifyStorageProof(address(bytes20(clientState.ibc_store_address)), stateRoot, accountProof));

anyConsensusState.type_url = CONSENSUS_STATE_TYPE_URL;
anyConsensusState.value = ConsensusState.encode(consensusState);
clientStates[clientId].latest_height.revision_number = height.revision_number;
clientStates[clientId].latest_height.revision_height = height.revision_height;
consensusStates[clientId][height.toUint128()].timestamp = timestamp;
consensusStates[clientId][height.toUint128()].state_root = abi.encodePacked(
verifyStorageProof(address(bytes20(clientStates[clientId].ibc_store_address)), stateRoot, header.account_proof));

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

/**
Expand Down Expand Up @@ -248,19 +232,6 @@ contract ParliaClient is ILightClient {

/* Internal functions */

function parseHeader(bytes memory bz) internal pure returns (Height.Data memory, bytes32, uint64, bytes memory) {
Any.Data memory any = Any.decode(bz);
require(keccak256(abi.encodePacked(any.type_url)) == HEADER_TYPE_URL_HASH, "invalid header type");
Header.Data memory header = Header.decode(any.value);
bytes memory rlpEthHeader = header.headers[0].header;

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 = bytes32(items[3].toBytes());
return (height,stateRoot, timestamp, header.account_proof);
}

function unmarshalClientState(bytes calldata bz)
internal
pure
Expand Down
Loading
Loading