@@ -7,7 +7,8 @@ import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/Client.sol";
77import {
88IbcLightclientsParliaV1ClientState as ClientState,
99IbcLightclientsParliaV1ConsensusState as ConsensusState,
10- IbcLightclientsParliaV1Header as Header
10+ IbcLightclientsParliaV1Header as Header,
11+ IbcLightclientsParliaV1ProveState as ProveState
1112} from "../ibc/lightclients/parlia/v1/parlia.sol " ;
1213import {GoogleProtobufAny as Any} from "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol " ;
1314import {RLPReader} from "@hyperledger-labs/yui-ibc-solidity/contracts/clients/qbft/RLPReader.sol " ;
@@ -132,16 +133,14 @@ contract ParliaClient is ILightClient {
132133 RLPReader.RLPItem[] memory items = rlpEthHeader.toRlpItem ().toList ();
133134 Height.Data memory height = Height.Data ({revision_number: 0 , revision_height: uint64 (items[8 ].toUint ())});
134135 uint64 timestamp = uint64 (items[11 ].toUint ());
135- bytes32 stateRoot = bytes32 ( items[3 ].toBytes () );
136+ bytes memory stateRoot = items[3 ].toBytes ();
136137
137138 //TODO verify header
138139
139140 clientStates[clientId].latest_height.revision_number = height.revision_number;
140141 clientStates[clientId].latest_height.revision_height = height.revision_height;
141142 consensusStates[clientId][height.toUint128 ()].timestamp = timestamp;
142- consensusStates[clientId][height.toUint128 ()].state_root = abi.encodePacked (
143- verifyStorageProof (address (bytes20 (clientStates[clientId].ibc_store_address)), stateRoot, header.account_proof));
144-
143+ consensusStates[clientId][height.toUint128 ()].state_root = stateRoot;
145144 heights = new Height.Data [](1 );
146145 heights[0 ] = height;
147146 return heights;
@@ -164,6 +163,7 @@ contract ParliaClient is ILightClient {
164163 ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128 ()];
165164 require (consensusState.timestamp != 0 , "consensus state not found " );
166165 return verifyMembership (
166+ clientId,
167167 proof,
168168 bytes32 (consensusState.state_root),
169169 keccak256 (abi.encodePacked (keccak256 (path), COMMITMENT_SLOT)),
@@ -187,22 +187,32 @@ contract ParliaClient is ILightClient {
187187 ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128 ()];
188188 require (consensusState.timestamp != 0 , "consensus state not found " );
189189 return verifyNonMembership (
190- proof, bytes32 (consensusState.state_root), keccak256 (abi.encodePacked (keccak256 (path), COMMITMENT_SLOT))
190+ clientId,
191+ proof,
192+ bytes32 (consensusState.state_root),
193+ keccak256 (abi.encodePacked (keccak256 (path), COMMITMENT_SLOT))
191194 );
192195 }
193196
194197 // Same as IBFT2Client.sol
195- function verifyMembership (bytes calldata proof , bytes32 root , bytes32 slot , bytes32 expectedValue )
198+ function verifyMembership (string memory clientId , bytes calldata proof , bytes32 root , bytes32 slot , bytes32 expectedValue )
196199 internal
197- pure
200+ view
198201 returns (bool )
199202 {
203+ ProveState.Data memory proveState = ProveState.decode (proof);
204+ bytes memory storageRoot = abi.encodePacked (
205+ verifyStorageProof (
206+ address (bytes20 (clientStates[clientId].ibc_store_address)),
207+ root,
208+ proveState.account_proof));
209+
200210 bytes32 path = keccak256 (abi.encodePacked (slot));
201- bytes memory dataHash = proof. verifyRLPProof (root , path);
211+ bytes memory dataHash = proveState.commitment_proof. verifyRLPProof (bytes32 (storageRoot) , path);
202212 return expectedValue == bytes32 (dataHash.toRlpItem ().toUint ());
203213 }
204214
205- function verifyNonMembership (bytes calldata proof , bytes32 root , bytes32 slot ) internal pure returns (bool ) {
215+ function verifyNonMembership (string calldata clientId , bytes calldata proof , bytes32 root , bytes32 slot ) internal pure returns (bool ) {
206216 // bytes32 path = keccak256(abi.encodePacked(slot));
207217 // bytes memory dataHash = proof.verifyRLPProof(root, path); // reverts if proof is invalid
208218 // return dataHash.toRlpItem().toBytes().length == 0;
0 commit comments