From 49701924dd6a44331354454d6762762032fd9db4 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 14 Mar 2025 17:35:24 +0900 Subject: [PATCH] Move accountProof into ProveState (#53) --- .../contracts/clients/ParliaClient.sol | 30 +- .../ibc/lightclients/parlia/v1/parlia.sol | 392 +++++++++++++++--- module/config.pb.go | 60 +-- module/header.go | 12 - module/header_test.go | 21 +- module/parlia.pb.go | 374 ++++++++++++----- module/proof.go | 28 +- module/prover.go | 29 +- module/prover_test.go | 13 +- module/setup.go | 7 +- proto/ibc/lightclients/parlia/v1/parlia.proto | 16 +- tests/prover_network_test.go | 5 +- .../internal/membership/verify_membership.go | 22 +- tool/testdata/internal/update_client.go | 7 - 14 files changed, 730 insertions(+), 286 deletions(-) diff --git a/e2e/contracts/contracts/clients/ParliaClient.sol b/e2e/contracts/contracts/clients/ParliaClient.sol index 6f3dc32e..2b61ba19 100644 --- a/e2e/contracts/contracts/clients/ParliaClient.sol +++ b/e2e/contracts/contracts/clients/ParliaClient.sol @@ -7,7 +7,8 @@ import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/Client.sol"; import { IbcLightclientsParliaV1ClientState as ClientState, IbcLightclientsParliaV1ConsensusState as ConsensusState, -IbcLightclientsParliaV1Header as Header +IbcLightclientsParliaV1Header as Header, +IbcLightclientsParliaV1ProveState as ProveState } from "../ibc/lightclients/parlia/v1/parlia.sol"; import {GoogleProtobufAny as Any} from "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; import {RLPReader} from "@hyperledger-labs/yui-ibc-solidity/contracts/clients/qbft/RLPReader.sol"; @@ -132,16 +133,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 = bytes32(items[3].toBytes()); + bytes memory stateRoot = items[3].toBytes(); //TODO verify header 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)); - + consensusStates[clientId][height.toUint128()].state_root = stateRoot; heights = new Height.Data[](1); heights[0] = height; return heights; @@ -164,6 +163,7 @@ contract ParliaClient is ILightClient { ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()]; require(consensusState.timestamp != 0, "consensus state not found"); return verifyMembership( + clientId, proof, bytes32(consensusState.state_root), keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT)), @@ -187,22 +187,32 @@ contract ParliaClient is ILightClient { ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()]; require(consensusState.timestamp != 0, "consensus state not found"); return verifyNonMembership( - proof, bytes32(consensusState.state_root), keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT)) + clientId, + proof, + bytes32(consensusState.state_root), + keccak256(abi.encodePacked(keccak256(path), COMMITMENT_SLOT)) ); } // Same as IBFT2Client.sol - function verifyMembership(bytes calldata proof, bytes32 root, bytes32 slot, bytes32 expectedValue) + function verifyMembership(string memory clientId, bytes calldata proof, bytes32 root, bytes32 slot, bytes32 expectedValue) internal - pure + view returns (bool) { + ProveState.Data memory proveState = ProveState.decode(proof); + bytes memory storageRoot = abi.encodePacked( + verifyStorageProof( + address(bytes20(clientStates[clientId].ibc_store_address)), + root, + proveState.account_proof)); + bytes32 path = keccak256(abi.encodePacked(slot)); - bytes memory dataHash = proof.verifyRLPProof(root, path); + bytes memory dataHash = proveState.commitment_proof.verifyRLPProof(bytes32(storageRoot), path); return expectedValue == bytes32(dataHash.toRlpItem().toUint()); } - function verifyNonMembership(bytes calldata proof, bytes32 root, bytes32 slot) internal pure returns (bool) { + function verifyNonMembership(string calldata clientId, bytes calldata proof, bytes32 root, bytes32 slot) internal pure returns (bool) { // bytes32 path = keccak256(abi.encodePacked(slot)); // bytes memory dataHash = proof.verifyRLPProof(root, path); // reverts if proof is invalid // return dataHash.toRlpItem().toBytes().length == 0; diff --git a/e2e/contracts/contracts/ibc/lightclients/parlia/v1/parlia.sol b/e2e/contracts/contracts/ibc/lightclients/parlia/v1/parlia.sol index 8ba5c1c3..9674ff2b 100644 --- a/e2e/contracts/contracts/ibc/lightclients/parlia/v1/parlia.sol +++ b/e2e/contracts/contracts/ibc/lightclients/parlia/v1/parlia.sol @@ -699,9 +699,10 @@ library IbcLightclientsParliaV1Header { struct Data { IbcLightclientsParliaV1ETHHeader.Data[] headers; IbcCoreClientV1Height.Data trusted_height; - bytes account_proof; bytes[] current_validators; bytes[] previous_validators; + uint32 current_turn_length; + uint32 previous_turn_length; } // Decoder section @@ -741,7 +742,7 @@ library IbcLightclientsParliaV1Header { returns (Data memory, uint) { Data memory r; - uint[6] memory counters; + uint[7] memory counters; uint256 fieldId; ProtoBufRuntime.WireType wireType; uint256 bytesRead; @@ -757,13 +758,16 @@ library IbcLightclientsParliaV1Header { pointer += _read_trusted_height(pointer, bs, r); } else if (fieldId == 3) { - pointer += _read_account_proof(pointer, bs, r); + pointer += _read_unpacked_repeated_current_validators(pointer, bs, nil(), counters); } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_current_validators(pointer, bs, nil(), counters); + pointer += _read_unpacked_repeated_previous_validators(pointer, bs, nil(), counters); } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_previous_validators(pointer, bs, nil(), counters); + pointer += _read_current_turn_length(pointer, bs, r); + } else + if (fieldId == 6) { + pointer += _read_previous_turn_length(pointer, bs, r); } else { pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); @@ -775,13 +779,13 @@ library IbcLightclientsParliaV1Header { require(r.headers.length == 0); r.headers = new IbcLightclientsParliaV1ETHHeader.Data[](counters[1]); } - if (counters[4] > 0) { + if (counters[3] > 0) { require(r.current_validators.length == 0); - r.current_validators = new bytes[](counters[4]); + r.current_validators = new bytes[](counters[3]); } - if (counters[5] > 0) { + if (counters[4] > 0) { require(r.previous_validators.length == 0); - r.previous_validators = new bytes[](counters[5]); + r.previous_validators = new bytes[](counters[4]); } while (pointer < offset + sz) { @@ -790,10 +794,10 @@ library IbcLightclientsParliaV1Header { if (fieldId == 1) { pointer += _read_unpacked_repeated_headers(pointer, bs, r, counters); } else - if (fieldId == 4) { + if (fieldId == 3) { pointer += _read_unpacked_repeated_current_validators(pointer, bs, r, counters); } else - if (fieldId == 5) { + if (fieldId == 4) { pointer += _read_unpacked_repeated_previous_validators(pointer, bs, r, counters); } else { @@ -817,7 +821,7 @@ library IbcLightclientsParliaV1Header { uint256 p, bytes memory bs, Data memory r, - uint[6] memory counters + uint[7] memory counters ) internal pure returns (uint) { /** * if `r` is NULL, then only counting the number of fields. @@ -854,15 +858,25 @@ library IbcLightclientsParliaV1Header { * @param p The offset of bytes array to start decode * @param bs The bytes array to be decoded * @param r The in-memory struct + * @param counters The counters for repeated fields * @return The number of bytes decoded */ - function _read_account_proof( + function _read_unpacked_repeated_current_validators( uint256 p, bytes memory bs, - Data memory r + Data memory r, + uint[7] memory counters ) internal pure returns (uint) { + /** + * if `r` is NULL, then only counting the number of fields. + */ (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.account_proof = x; + if (isNil(r)) { + counters[3] += 1; + } else { + r.current_validators[r.current_validators.length - counters[3]] = x; + counters[3] -= 1; + } return sz; } @@ -874,11 +888,11 @@ library IbcLightclientsParliaV1Header { * @param counters The counters for repeated fields * @return The number of bytes decoded */ - function _read_unpacked_repeated_current_validators( + function _read_unpacked_repeated_previous_validators( uint256 p, bytes memory bs, Data memory r, - uint[6] memory counters + uint[7] memory counters ) internal pure returns (uint) { /** * if `r` is NULL, then only counting the number of fields. @@ -887,7 +901,7 @@ library IbcLightclientsParliaV1Header { if (isNil(r)) { counters[4] += 1; } else { - r.current_validators[r.current_validators.length - counters[4]] = x; + r.previous_validators[r.previous_validators.length - counters[4]] = x; counters[4] -= 1; } return sz; @@ -898,25 +912,32 @@ library IbcLightclientsParliaV1Header { * @param p The offset of bytes array to start decode * @param bs The bytes array to be decoded * @param r The in-memory struct - * @param counters The counters for repeated fields * @return The number of bytes decoded */ - function _read_unpacked_repeated_previous_validators( + function _read_current_turn_length( uint256 p, bytes memory bs, - Data memory r, - uint[6] memory counters + Data memory r ) internal pure returns (uint) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - if (isNil(r)) { - counters[5] += 1; - } else { - r.previous_validators[r.previous_validators.length - counters[5]] = x; - counters[5] -= 1; - } + (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); + r.current_turn_length = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_previous_turn_length( + uint256 p, + bytes memory bs, + Data memory r + ) internal pure returns (uint) { + (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); + r.previous_turn_length = x; return sz; } @@ -1012,19 +1033,10 @@ library IbcLightclientsParliaV1Header { ); pointer += IbcCoreClientV1Height._encode_nested(r.trusted_height, pointer, bs); - if (r.account_proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, - ProtoBufRuntime.WireType.LengthDelim, - pointer, - bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.account_proof, pointer, bs); - } if (r.current_validators.length != 0) { for(i = 0; i < r.current_validators.length; i++) { pointer += ProtoBufRuntime._encode_key( - 4, + 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs) @@ -1035,7 +1047,7 @@ library IbcLightclientsParliaV1Header { if (r.previous_validators.length != 0) { for(i = 0; i < r.previous_validators.length; i++) { pointer += ProtoBufRuntime._encode_key( - 5, + 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs) @@ -1043,6 +1055,24 @@ library IbcLightclientsParliaV1Header { pointer += ProtoBufRuntime._encode_bytes(r.previous_validators[i], pointer, bs); } } + if (r.current_turn_length != 0) { + pointer += ProtoBufRuntime._encode_key( + 5, + ProtoBufRuntime.WireType.Varint, + pointer, + bs + ); + pointer += ProtoBufRuntime._encode_uint32(r.current_turn_length, pointer, bs); + } + if (r.previous_turn_length != 0) { + pointer += ProtoBufRuntime._encode_key( + 6, + ProtoBufRuntime.WireType.Varint, + pointer, + bs + ); + pointer += ProtoBufRuntime._encode_uint32(r.previous_turn_length, pointer, bs); + } return pointer - offset; } // nested encoder @@ -1090,13 +1120,14 @@ library IbcLightclientsParliaV1Header { e += 1 + ProtoBufRuntime._sz_lendelim(IbcLightclientsParliaV1ETHHeader._estimate(r.headers[i])); } e += 1 + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1Height._estimate(r.trusted_height)); - e += 1 + ProtoBufRuntime._sz_lendelim(r.account_proof.length); for(i = 0; i < r.current_validators.length; i++) { e += 1 + ProtoBufRuntime._sz_lendelim(r.current_validators[i].length); } for(i = 0; i < r.previous_validators.length; i++) { e += 1 + ProtoBufRuntime._sz_lendelim(r.previous_validators[i].length); } + e += 1 + ProtoBufRuntime._sz_uint32(r.current_turn_length); + e += 1 + ProtoBufRuntime._sz_uint32(r.previous_turn_length); return e; } // empty checker @@ -1109,15 +1140,19 @@ library IbcLightclientsParliaV1Header { return false; } - if (r.account_proof.length != 0) { + if (r.current_validators.length != 0) { return false; } - if (r.current_validators.length != 0) { + if (r.previous_validators.length != 0) { return false; } - if (r.previous_validators.length != 0) { + if (r.current_turn_length != 0) { + return false; + } + + if (r.previous_turn_length != 0) { return false; } @@ -1138,9 +1173,10 @@ library IbcLightclientsParliaV1Header { } IbcCoreClientV1Height.store(input.trusted_height, output.trusted_height); - output.account_proof = input.account_proof; output.current_validators = input.current_validators; output.previous_validators = input.previous_validators; + output.current_turn_length = input.current_turn_length; + output.previous_turn_length = input.previous_turn_length; } @@ -1858,4 +1894,262 @@ library IbcLightclientsParliaV1Misbehaviour { } } } -//library IbcLightclientsParliaV1Misbehaviour \ No newline at end of file +//library IbcLightclientsParliaV1Misbehaviour + +library IbcLightclientsParliaV1ProveState { + + + //struct definition + struct Data { + bytes account_proof; + bytes commitment_proof; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x, ) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x, ) = _decode(32, bs, bs.length); + store(x, self); + } + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) + internal + pure + returns (Data memory, uint) + { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_account_proof(pointer, bs, r); + } else + if (fieldId == 2) { + pointer += _read_commitment_proof(pointer, bs, r); + } else + { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_account_proof( + uint256 p, + bytes memory bs, + Data memory r + ) internal pure returns (uint) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.account_proof = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_commitment_proof( + uint256 p, + bytes memory bs, + Data memory r + ) internal pure returns (uint) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.commitment_proof = x; + return sz; + } + + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) + internal + pure + returns (uint) + { + uint256 offset = p; + uint256 pointer = p; + + if (r.account_proof.length != 0) { + pointer += ProtoBufRuntime._encode_key( + 1, + ProtoBufRuntime.WireType.LengthDelim, + pointer, + bs + ); + pointer += ProtoBufRuntime._encode_bytes(r.account_proof, pointer, bs); + } + if (r.commitment_proof.length != 0) { + pointer += ProtoBufRuntime._encode_key( + 2, + ProtoBufRuntime.WireType.LengthDelim, + pointer, + bs + ); + pointer += ProtoBufRuntime._encode_bytes(r.commitment_proof, pointer, bs); + } + return pointer - offset; + } + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) + internal + pure + returns (uint) + { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate( + Data memory r + ) internal pure returns (uint) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(r.account_proof.length); + e += 1 + ProtoBufRuntime._sz_lendelim(r.commitment_proof.length); + return e; + } + // empty checker + + function _empty( + Data memory r + ) internal pure returns (bool) { + + if (r.account_proof.length != 0) { + return false; + } + + if (r.commitment_proof.length != 0) { + return false; + } + + return true; + } + + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.account_proof = input.account_proof; + output.commitment_proof = input.commitment_proof; + + } + + + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcLightclientsParliaV1ProveState \ No newline at end of file diff --git a/module/config.pb.go b/module/config.pb.go index 68e02bb7..5763c035 100644 --- a/module/config.pb.go +++ b/module/config.pb.go @@ -31,8 +31,11 @@ type ProverConfig struct { TrustingPeriod time.Duration `protobuf:"bytes,1,opt,name=trusting_period,json=trustingPeriod,proto3,stdduration" json:"trusting_period"` MaxClockDrift time.Duration `protobuf:"bytes,2,opt,name=max_clock_drift,json=maxClockDrift,proto3,stdduration" json:"max_clock_drift"` // Fraction of the trusting period that is allowed to pass before the client is considered expired - RefreshThresholdRate *Fraction `protobuf:"bytes,3,opt,name=refresh_threshold_rate,json=refreshThresholdRate,proto3" json:"refresh_threshold_rate,omitempty"` - RefreshBlockDifferenceThreshold uint64 `protobuf:"varint,4,opt,name=refresh_block_difference_threshold,json=refreshBlockDifferenceThreshold,proto3" json:"refresh_block_difference_threshold,omitempty"` + RefreshThresholdRate *Fraction `protobuf:"bytes,3,opt,name=refresh_threshold_rate,json=refreshThresholdRate,proto3" json:"refresh_threshold_rate,omitempty"` + // Difference in blocks to refresh. + // Refresh if the difference between blocks in the chain and ClientState exceeds this value. + // If the value is 0, no refresh decision is made. + RefreshBlockDifferenceThreshold uint64 `protobuf:"varint,4,opt,name=refresh_block_difference_threshold,json=refreshBlockDifferenceThreshold,proto3" json:"refresh_block_difference_threshold,omitempty"` } func (m *ProverConfig) Reset() { *m = ProverConfig{} } @@ -158,33 +161,32 @@ func init() { } var fileDescriptor_4d00ceb9ab8b08a6 = []byte{ - // 402 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xcf, 0x6a, 0xd5, 0x40, - 0x14, 0xc6, 0x33, 0xd7, 0x20, 0x75, 0xaa, 0x16, 0x42, 0x91, 0x58, 0x34, 0xb9, 0xdc, 0x8d, 0x45, - 0xe8, 0x0c, 0xe8, 0x1b, 0xa4, 0x45, 0xf0, 0xcf, 0xa2, 0x06, 0x57, 0x82, 0x84, 0xc9, 0x64, 0x92, - 0x0c, 0x26, 0x73, 0xc2, 0xb9, 0x13, 0xa9, 0x6f, 0xe1, 0xd2, 0x47, 0xba, 0xcb, 0x2e, 0x05, 0xa1, - 0xca, 0xbd, 0x2f, 0x22, 0x99, 0x24, 0xbd, 0xae, 0xc4, 0xd5, 0x0c, 0xe7, 0x7c, 0xdf, 0xef, 0x3b, - 0x7c, 0xf4, 0x39, 0xaa, 0x46, 0x7c, 0x55, 0xc8, 0x3b, 0x84, 0x2f, 0x0a, 0xd7, 0xbc, 0x13, 0xd8, - 0x68, 0xc1, 0x25, 0x98, 0x52, 0x57, 0xd3, 0xc3, 0x3a, 0x04, 0x0b, 0xc1, 0xd3, 0x49, 0xcb, 0x26, - 0x2d, 0x1b, 0xb5, 0x6c, 0x14, 0x9d, 0x44, 0x15, 0x40, 0xd5, 0x28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, 0x67, 0xfa, 0x56, 0xa1, 0xb0, 0x80, 0xae, 0x52, 0x3f, 0xdd, 0x0f, 0x82, 0x25, 0x3d, - 0x2c, 0x94, 0x81, 0x56, 0x1b, 0xb7, 0x5f, 0xb8, 0xfd, 0xdf, 0xa3, 0xe4, 0xf5, 0x66, 0x1b, 0x91, - 0xeb, 0x6d, 0x44, 0x7e, 0x6f, 0x23, 0xf2, 0x6d, 0x17, 0x79, 0xd7, 0xbb, 0xc8, 0xfb, 0xb1, 0x8b, - 0xbc, 0x8f, 0xbc, 0xd2, 0xb6, 0xee, 0x73, 0x26, 0xa1, 0xe5, 0x85, 0xb0, 0x42, 0xd6, 0x42, 0x9b, - 0x46, 0xe4, 0x5c, 0xe7, 0xf2, 0x6c, 0xac, 0xe0, 0xcc, 0x35, 0xc3, 0x5b, 0x28, 0xfa, 0x46, 0xe5, - 0x77, 0x5d, 0xe9, 0x2f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0xdb, 0xef, 0x3f, 0x4b, 0x7e, 0x02, - 0x00, 0x00, + // 396 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0xaa, 0xd3, 0x40, + 0x14, 0x86, 0x93, 0x5a, 0xe4, 0x3a, 0x57, 0xbd, 0x10, 0x2e, 0x12, 0x8b, 0xa6, 0xa5, 0x1b, 0x8b, + 0xd0, 0x19, 0xd0, 0x37, 0x68, 0x8b, 0xa0, 0x75, 0x51, 0x82, 0x2b, 0x41, 0xc2, 0x64, 0x32, 0x49, + 0x06, 0x93, 0x39, 0xe1, 0x74, 0x22, 0xf5, 0x2d, 0x5c, 0xfa, 0x48, 0x5d, 0x76, 0x23, 0xb8, 0x52, + 0x69, 0x5f, 0x44, 0x32, 0x49, 0x5a, 0x57, 0x72, 0x57, 0x33, 0x9c, 0xf9, 0xff, 0xef, 0x3f, 0xf3, + 0x93, 0x97, 0x28,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, 0xc7, 0xc7, 0xed, 0xbe, 0x2a, 0x4d, 0x25, + 0x4a, 0x2d, 0xe4, 0x25, 0xcf, 0x1f, 0x4e, 0xdc, 0xd9, 0x30, 0x1c, 0x77, 0xca, 0x85, 0xdd, 0xee, + 0xac, 0x3b, 0x03, 0xa7, 0xef, 0xc8, 0x55, 0x1f, 0xe7, 0x3d, 0x23, 0x0f, 0x74, 0x5d, 0x4a, 0xe4, + 0x06, 0xd0, 0x96, 0x39, 0x0c, 0x2f, 0x03, 0x6f, 0x42, 0xae, 0x13, 0xa9, 0xa1, 0x54, 0xda, 0xbe, + 0x0f, 0xec, 0xfb, 0xbf, 0xa3, 0xc5, 0xdb, 0xfd, 0x31, 0x70, 0x0f, 0xc7, 0xc0, 0xfd, 0x73, 0x0c, + 0xdc, 0x6f, 0xa7, 0xc0, 0x39, 0x9c, 0x02, 0xe7, 0xe7, 0x29, 0x70, 0x3e, 0xb2, 0x4c, 0x99, 0xbc, + 0x8e, 0xa9, 0x80, 0x92, 0x25, 0xdc, 0x70, 0x91, 0x73, 0xa5, 0x0b, 0x1e, 0x33, 0x15, 0x8b, 0x79, + 0xfb, 0xf9, 0xb9, 0xed, 0x84, 0x95, 0x90, 0xd4, 0x85, 0x8c, 0xef, 0xdb, 0xba, 0x5f, 0xff, 0x0d, + 0x00, 0x00, 0xff, 0xff, 0x70, 0xff, 0x73, 0x50, 0x78, 0x02, 0x00, 0x00, } func (m *ProverConfig) Marshal() (dAtA []byte, err error) { diff --git a/module/header.go b/module/header.go index e90b499c..9498d139 100644 --- a/module/header.go +++ b/module/header.go @@ -6,7 +6,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" ) @@ -35,9 +34,6 @@ func (h *Header) ValidateBasic() error { if _, err := h.Target(); err != nil { return err } - if _, err := decodeAccountProof(h.AccountProof); err != nil { - return err - } return nil } @@ -74,11 +70,3 @@ func (h *Header) Last() (*types.Header, error) { } return decodedHeaders[len(decodedHeaders)-1], nil } - -func (h *Header) Account(path common.Address) (*types.StateAccount, error) { - target, err := h.Target() - if err != nil { - return nil, err - } - return verifyAccount(target, h.AccountProof, path) -} diff --git a/module/header_test.go b/module/header_test.go index 9474cc79..d1d0d1b9 100644 --- a/module/header_test.go +++ b/module/header_test.go @@ -2,7 +2,6 @@ package module import ( "encoding/hex" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/suite" "testing" @@ -25,17 +24,8 @@ func (ts *HeaderTestSuite) TestNewHeaderSuccess() { ethHeader, err := newETHHeader(rawHeader) ts.Require().NoError(err) - accountProof := []string{ - "0xf901f1a080679a623dfdd0dfa34cb5c1db80292abdc2a9e75f5026e3d24cd10ea58f8e0da04f4d7ef0e932874f07aec064ee1281cd6a3245fceab78bdd6a8d2d7a86d27451a0a715335e2de6e91c28910eff04e8709ff6ca93862121a0b52560071867a9f14080a0842db9556e659d64ca9d2d33229ebac6e7e2185f42bd07965464de8064d94ac8a0d94bd2db341ab9d3d7f4fe0aa569bb21dfac0d5eb0ec008c7af23d7f2ed98ec1a0cee66e2515872d5f4b42ada7cc733288809c11ab99aa0d25eb941236074f9904a0f3aa8d1774f013d8af0fdd8364c7833f16b42ad377e485b754f5cdae6fedaa2fa0bffc6b17aaf862725aaf4af4ecda3ed70d4102b875451eb965259ead260b06c7a026a29f57f5efaf83a8f098ed0ba0f53aac353364ce498a82d589e7bcf1f84e76a01a25f2cac2c6a021225ea182c3c391c0fafac96cb38896eb45648a5c33f31b6ca0d4d6b410f89044b335cc7b14221050035d87d390043bf6d84bc0f8005391f213a092dfa1004df4e71ccfaf3a6d682718f1fbb2d1e6411566e139f1efa74874c303a078455f6ef72aa4dc670e9b467fdbe29d37b5c4eb526ee07b372d2bcea57871eaa05911bcb62e4ba3117ca428f93305ebf06247d573f25bb0fff22681716c21744da0f47e1a054e1ee9ac18fd711b2571c2cab26e88d1a5be46d7078723076866265880", - "0xf851808080808080808080a08ffa88d75a03fd29af8cb1a4ac016e32ef8e39631a6bf45d79a34adfc4ecb1448080a0a1161a49c0c7e7a92a2efe173abffdbb1ed91e5235688e2edbc4e38078dc5c5580808080", - "0xf869a02012683435c076b898a6cac1c03e41900e379104fefd4219d99f7908cb59cfb3b846f8440180a0c3608871098f21b59607ef3fb9412a091de9246ad1281a92f5b07dc2f465b7a0a07498e14000b8457a51de3cd583e9337cfa52aee2c2e9f945fac35a820e685904", - } - accountProofRLP, err := encodeRLP(accountProof) - ts.Require().NoError(err) - header := Header{ - Headers: []*ETHHeader{ethHeader}, - AccountProof: accountProofRLP, + Headers: []*ETHHeader{ethHeader}, } target, err := header.Target() ts.Require().NoError(err) @@ -46,18 +36,11 @@ func (ts *HeaderTestSuite) TestNewHeaderSuccess() { ts.Require().Equal(turnLength, uint8(1)) ts.Require().NoError(header.ValidateBasic()) ts.Require().Equal(header.GetHeight().GetRevisionHeight(), target.Number.Uint64()) - account, err := header.Account(common.HexToAddress("aa43d337145e8930d01cb4e60abf6595c692921e")) - ts.Require().NoError(err) - ts.Require().Equal(account.Root, common.HexToHash("c3608871098f21b59607ef3fb9412a091de9246ad1281a92f5b07dc2f465b7a0")) - ts.Require().Equal(account.CodeHash, common.Hex2Bytes("7498e14000b8457a51de3cd583e9337cfa52aee2c2e9f945fac35a820e685904")) - ts.Require().Equal(account.Nonce, uint64(1)) - ts.Require().Equal(account.Balance.Uint64(), uint64(0)) } func (ts *HeaderTestSuite) TestNewHeaderError() { header := Header{ - Headers: []*ETHHeader{}, - AccountProof: []byte{}, + Headers: []*ETHHeader{}, } ts.Require().Error(header.ValidateBasic()) } diff --git a/module/parlia.pb.go b/module/parlia.pb.go index 278b5929..9032ed80 100644 --- a/module/parlia.pb.go +++ b/module/parlia.pb.go @@ -111,11 +111,10 @@ var xxx_messageInfo_ETHHeader proto.InternalMessageInfo type Header struct { Headers []*ETHHeader `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty"` TrustedHeight *types.Height `protobuf:"bytes,2,opt,name=trusted_height,json=trustedHeight,proto3" json:"trusted_height,omitempty"` - AccountProof []byte `protobuf:"bytes,3,opt,name=account_proof,json=accountProof,proto3" json:"account_proof,omitempty"` - CurrentValidators [][]byte `protobuf:"bytes,4,rep,name=current_validators,json=currentValidators,proto3" json:"current_validators,omitempty"` - PreviousValidators [][]byte `protobuf:"bytes,5,rep,name=previous_validators,json=previousValidators,proto3" json:"previous_validators,omitempty"` - CurrentTurnLength uint32 `protobuf:"varint,6,opt,name=current_turn_length,json=currentTurnLength,proto3" json:"current_turn_length,omitempty"` - PreviousTurnLength uint32 `protobuf:"varint,7,opt,name=previous_turn_length,json=previousTurnLength,proto3" json:"previous_turn_length,omitempty"` + CurrentValidators [][]byte `protobuf:"bytes,3,rep,name=current_validators,json=currentValidators,proto3" json:"current_validators,omitempty"` + PreviousValidators [][]byte `protobuf:"bytes,4,rep,name=previous_validators,json=previousValidators,proto3" json:"previous_validators,omitempty"` + CurrentTurnLength uint32 `protobuf:"varint,5,opt,name=current_turn_length,json=currentTurnLength,proto3" json:"current_turn_length,omitempty"` + PreviousTurnLength uint32 `protobuf:"varint,6,opt,name=previous_turn_length,json=previousTurnLength,proto3" json:"previous_turn_length,omitempty"` } func (m *Header) Reset() { *m = Header{} } @@ -230,12 +229,51 @@ func (m *Misbehaviour) XXX_DiscardUnknown() { var xxx_messageInfo_Misbehaviour proto.InternalMessageInfo +type ProveState struct { + AccountProof []byte `protobuf:"bytes,1,opt,name=account_proof,json=accountProof,proto3" json:"account_proof,omitempty"` + CommitmentProof []byte `protobuf:"bytes,2,opt,name=commitment_proof,json=commitmentProof,proto3" json:"commitment_proof,omitempty"` +} + +func (m *ProveState) Reset() { *m = ProveState{} } +func (m *ProveState) String() string { return proto.CompactTextString(m) } +func (*ProveState) ProtoMessage() {} +func (*ProveState) Descriptor() ([]byte, []int) { + return fileDescriptor_dc631224085c6c85, []int{5} +} +func (m *ProveState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProveState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProveState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProveState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProveState.Merge(m, src) +} +func (m *ProveState) XXX_Size() int { + return m.Size() +} +func (m *ProveState) XXX_DiscardUnknown() { + xxx_messageInfo_ProveState.DiscardUnknown(m) +} + +var xxx_messageInfo_ProveState proto.InternalMessageInfo + func init() { proto.RegisterType((*ClientState)(nil), "ibc.lightclients.parlia.v1.ClientState") proto.RegisterType((*ETHHeader)(nil), "ibc.lightclients.parlia.v1.ETHHeader") proto.RegisterType((*Header)(nil), "ibc.lightclients.parlia.v1.Header") proto.RegisterType((*ConsensusState)(nil), "ibc.lightclients.parlia.v1.ConsensusState") proto.RegisterType((*Misbehaviour)(nil), "ibc.lightclients.parlia.v1.Misbehaviour") + proto.RegisterType((*ProveState)(nil), "ibc.lightclients.parlia.v1.ProveState") } func init() { @@ -243,54 +281,55 @@ func init() { } var fileDescriptor_dc631224085c6c85 = []byte{ - // 739 bytes of a gzipped FileDescriptorProto + // 761 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcd, 0x6e, 0xeb, 0x44, - 0x14, 0xc7, 0xe3, 0x34, 0x37, 0x1f, 0xd3, 0xe4, 0x56, 0x77, 0x6e, 0x29, 0x6e, 0x00, 0x37, 0x4a, - 0x85, 0x88, 0x90, 0x6a, 0x93, 0x20, 0x21, 0x36, 0xa8, 0x6a, 0x53, 0xa4, 0x54, 0xb4, 0x52, 0xe5, - 0x56, 0x2c, 0xd8, 0x58, 0xe3, 0xf1, 0xc4, 0x1e, 0x61, 0x7b, 0xa2, 0x99, 0x71, 0x54, 0x78, 0x0a, - 0x96, 0xbc, 0x02, 0x4f, 0xc1, 0xb6, 0xcb, 0x2e, 0x59, 0xf1, 0xd1, 0x3e, 0x02, 0x3b, 0x56, 0x68, - 0x3e, 0x92, 0x06, 0x95, 0xaf, 0xbb, 0x9b, 0x73, 0xce, 0xff, 0x77, 0xac, 0xf3, 0x9f, 0x33, 0x06, - 0x1f, 0xd0, 0x18, 0x07, 0x39, 0x4d, 0x33, 0x89, 0x73, 0x4a, 0x4a, 0x29, 0x82, 0x05, 0xe2, 0x39, - 0x45, 0xc1, 0x72, 0x6c, 0x4f, 0xfe, 0x82, 0x33, 0xc9, 0x60, 0x9f, 0xc6, 0xd8, 0xdf, 0x14, 0xfa, - 0xb6, 0xbc, 0x1c, 0xf7, 0x77, 0x53, 0x96, 0x32, 0x2d, 0x0b, 0xd4, 0xc9, 0x10, 0xfd, 0x03, 0xd5, - 0x1a, 0x33, 0x4e, 0x02, 0x43, 0xa8, 0x96, 0xe6, 0x64, 0x05, 0x5e, 0xca, 0x58, 0x9a, 0x93, 0x40, - 0x47, 0x71, 0x35, 0x0f, 0x92, 0x8a, 0x23, 0x49, 0x59, 0x69, 0xea, 0xc3, 0x3f, 0xea, 0x60, 0x7b, - 0xaa, 0x81, 0x6b, 0x89, 0x24, 0x81, 0xfb, 0xa0, 0x8d, 0x33, 0x44, 0xcb, 0x88, 0x26, 0xae, 0x33, - 0x70, 0x46, 0x8d, 0xb0, 0xa5, 0xe3, 0xf3, 0x04, 0x7e, 0x08, 0x5e, 0xd1, 0x18, 0x47, 0x42, 0x32, - 0x4e, 0x22, 0x94, 0x24, 0x9c, 0x08, 0xe1, 0xd6, 0x07, 0xce, 0xa8, 0x1b, 0xee, 0xd0, 0x18, 0x5f, - 0xab, 0xfc, 0x89, 0x49, 0xc3, 0x8f, 0xc0, 0xae, 0xd2, 0x62, 0x56, 0x14, 0x54, 0x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 0x0a, 0x9e, 0x00, 0x33, 0x27, 0x49, 0x56, 0x2e, 0xd7, 0xff, 0xd3, 0xe5, - 0x9e, 0x25, 0xac, 0xcd, 0x87, 0xa0, 0x87, 0x30, 0x66, 0x55, 0x29, 0xa3, 0x05, 0x67, 0x6c, 0x6e, - 0xaf, 0xb4, 0x6b, 0x93, 0x57, 0x2a, 0x07, 0x8f, 0x00, 0xc4, 0x15, 0xe7, 0xa4, 0x94, 0xd1, 0x12, - 0xe5, 0x34, 0x41, 0x92, 0x71, 0xe1, 0x36, 0x06, 0x5b, 0xa3, 0x6e, 0xf8, 0xca, 0x56, 0xbe, 0x5c, - 0x17, 0x60, 0x00, 0x5e, 0x2f, 0x38, 0x59, 0x52, 0x56, 0x89, 0x4d, 0xfd, 0x0b, 0xad, 0x87, 0xab, - 0xd2, 0x06, 0xe0, 0x83, 0xd7, 0xab, 0xfe, 0xb2, 0xe2, 0x65, 0x94, 0x93, 0x32, 0x95, 0x99, 0xbe, - 0xa1, 0xde, 0xfa, 0x03, 0x37, 0x15, 0x2f, 0x2f, 0x74, 0x41, 0xad, 0xe3, 0xfa, 0x03, 0x9b, 0x40, - 0x4b, 0x03, 0xeb, 0x2f, 0x3c, 0x11, 0xc3, 0x1f, 0x1d, 0xf0, 0x72, 0xca, 0x4a, 0x41, 0x4a, 0x51, - 0x09, 0xf3, 0x34, 0xde, 0x03, 0x40, 0xa8, 0x43, 0xc4, 0x19, 0x93, 0xf6, 0x92, 0x3a, 0x3a, 0x13, - 0x32, 0x26, 0xe1, 0xbb, 0xa0, 0x23, 0x69, 0x41, 0x84, 0x44, 0xc5, 0x42, 0xdb, 0xda, 0x08, 0x9f, - 0x12, 0xf0, 0x13, 0xf0, 0xf6, 0x73, 0x47, 0xa2, 0x0c, 0x89, 0xcc, 0x1a, 0xf8, 0xd6, 0x33, 0x5b, - 0x66, 0x48, 0x64, 0xf0, 0x53, 0xe0, 0xfe, 0x8d, 0x35, 0x06, 0x6c, 0x68, 0x70, 0x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 0x82, 0x25, 0xaf, 0xc0, 0x53, 0xb0, 0xed, 0x0a, 0x75, 0xc9, 0x8a, 0x8f, 0xf6, 0x2d, 0x58, 0xa1, + 0xf9, 0xc8, 0x07, 0x2a, 0x5f, 0x77, 0x37, 0x73, 0xce, 0xff, 0x77, 0xc6, 0xe7, 0x3f, 0xc7, 0x03, + 0xde, 0xa3, 0x31, 0x0e, 0x72, 0x9a, 0x66, 0x12, 0xe7, 0x94, 0x94, 0x52, 0x04, 0x0b, 0xc4, 0x73, + 0x8a, 0x82, 0xe5, 0xd8, 0xae, 0xfc, 0x05, 0x67, 0x92, 0xc1, 0x3e, 0x8d, 0xb1, 0xbf, 0x2d, 0xf4, + 0x6d, 0x7a, 0x39, 0xee, 0x3f, 0x4f, 0x59, 0xca, 0xb4, 0x2c, 0x50, 0x2b, 0x43, 0xf4, 0xf7, 0x55, + 0x69, 0xcc, 0x38, 0x09, 0x0c, 0xa1, 0x4a, 0x9a, 0x95, 0x15, 0x78, 0x29, 0x63, 0x69, 0x4e, 0x02, + 0xbd, 0x8b, 0xab, 0x79, 0x90, 0x54, 0x1c, 0x49, 0xca, 0x4a, 0x93, 0x1f, 0xfe, 0x51, 0x07, 0xbb, + 0x53, 0x0d, 0x5c, 0x49, 0x24, 0x09, 0x7c, 0x09, 0xda, 0x38, 0x43, 0xb4, 0x8c, 0x68, 0xe2, 0x3a, + 0x03, 0x67, 0xd4, 0x0c, 0x77, 0xf4, 0xfe, 0x2c, 0x81, 0x1f, 0x80, 0xa7, 0x34, 0xc6, 0x91, 0x90, + 0x8c, 0x93, 0x08, 0x25, 0x09, 0x27, 0x42, 0xb8, 0xf5, 0x81, 0x33, 0xea, 0x86, 0x7b, 0x34, 0xc6, + 0x57, 0x2a, 0x7e, 0x6c, 0xc2, 0xf0, 0x43, 0xf0, 0x5c, 0x69, 0x31, 0x2b, 0x0a, 0x2a, 0x0b, 0xd5, + 0x4a, 0x24, 0x72, 0x26, 0xdd, 0x86, 0x96, 0x43, 0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+ 0x5d, 0xee, 0x59, 0xc2, 0xda, 0x7c, 0x08, 0x20, 0xae, 0x38, 0x27, 0xa5, 0x8c, 0x96, 0x28, 0xa7, + 0x09, 0x92, 0x8c, 0x0b, 0xb7, 0x31, 0x68, 0x8c, 0xba, 0xe1, 0x53, 0x9b, 0xf9, 0x62, 0x9d, 0x80, + 0x01, 0x78, 0xb6, 0xe0, 0x64, 0x49, 0x59, 0x25, 0xb6, 0xf5, 0x4d, 0xad, 0x87, 0xab, 0xd4, 0x16, + 0xe0, 0x83, 0x67, 0xab, 0xfa, 0xb2, 0xe2, 0x65, 0x94, 0x93, 0x32, 0x95, 0x99, 0xbe, 0xca, 0xde, + 0xfa, 0x80, 0xeb, 0x8a, 0x97, 0xe7, 0x3a, 0xa1, 0x26, 0x6d, 0x7d, 0xc0, 0x36, 0xd0, 0xd2, 0xc0, + 0xfa, 0x84, 0x0d, 0x31, 0xfc, 0xd1, 0x01, 0x4f, 0xa6, 0xac, 0x14, 0xa4, 0x14, 0x95, 0x30, 0x53, + 0xff, 0x0e, 0x00, 0x42, 0x2d, 0x22, 0xce, 0x98, 0xb4, 0xfe, 0x77, 0x74, 0x24, 0x64, 0x4c, 0xc2, + 0xb7, 0x41, 0x47, 0xd2, 0x82, 0x08, 0x89, 0x8a, 0x85, 0x76, 0xac, 0x19, 0x6e, 0x02, 0xf0, 0x63, + 0xf0, 0xe6, 0x63, 0x47, 0xa2, 0x0c, 0x89, 0xcc, 0x8e, 0xfb, 0x1b, 0x8f, 0x6c, 0x99, 0x21, 0x91, + 0xc1, 0x4f, 0x80, 0xfb, 0x37, 0xd6, 0x18, 0xb0, 0xa9, 0xc1, 0x17, 0x8f, 0xfd, 0x51, 0xe4, 0xf0, + 0x07, 0x07, 0x74, 0x2f, 0xa8, 0x88, 0x49, 0x86, 0x54, 0x9a, 0xc3, 0xb7, 0x40, 0xc7, 0xdc, 0xdb, + 0xea, 0xb7, 0xed, 0x84, 0x6d, 0x13, 0x38, 0x4b, 0xe0, 0xa7, 0xa0, 0x6d, 0xee, 0x3f, 0x1a, 0xdb, + 0xeb, 0x1e, 0xfe, 0xdb, 0xd8, 0xfc, 0x75, 0x66, 0xc6, 0x5b, 0xf8, 0x44, 0xf7, 0xf3, 0x4a, 0xf8, + 0x64, 0xf8, 0x15, 0x00, 0x97, 0x9c, 0x2d, 0x89, 0x31, 0xfa, 0x00, 0xf4, 0x10, 0xc6, 0xac, 0x2a, + 0x65, 0xb4, 0xe0, 0x8c, 0xcd, 0xad, 0xd7, 0x5d, 0x1b, 0xbc, 0x54, 0x31, 0xf8, 0x3e, 0x78, 0x7d, + 0xf3, 0x70, 0x58, 0x9d, 0x7d, 0x67, 0x36, 0x71, 0x2d, 0x3d, 0xb9, 0xb8, 0xfd, 0xdd, 0xab, 0xdd, + 0xde, 0x7b, 0xce, 0xdd, 0xbd, 0xe7, 0xfc, 0x76, 0xef, 0x39, 0xdf, 0x3d, 0x78, 0xb5, 0xbb, 0x07, + 0xaf, 0xf6, 0xf3, 0x83, 0x57, 0xfb, 0x32, 0x48, 0xa9, 0xcc, 0xaa, 0xd8, 0xc7, 0xac, 0x08, 0x12, + 0x24, 0x91, 0x7e, 0xc9, 0x72, 0x14, 0x07, 0x34, 0xc6, 0x87, 0xe6, 0x93, 0x0f, 0x39, 0xc9, 0xd1, + 0x37, 0x41, 0xc1, 0x92, 0x2a, 0x27, 0x71, 0x4b, 0xff, 0xd4, 0x1f, 0xfd, 0x19, 0x00, 0x00, 0xff, + 0xff, 0x0f, 0xe3, 0xdf, 0x4c, 0xb2, 0x05, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { @@ -426,12 +465,12 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.PreviousTurnLength != 0 { i = encodeVarintParlia(dAtA, i, uint64(m.PreviousTurnLength)) i-- - dAtA[i] = 0x38 + dAtA[i] = 0x30 } if m.CurrentTurnLength != 0 { i = encodeVarintParlia(dAtA, i, uint64(m.CurrentTurnLength)) i-- - dAtA[i] = 0x30 + dAtA[i] = 0x28 } if len(m.PreviousValidators) > 0 { for iNdEx := len(m.PreviousValidators) - 1; iNdEx >= 0; iNdEx-- { @@ -439,7 +478,7 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.PreviousValidators[iNdEx]) i = encodeVarintParlia(dAtA, i, uint64(len(m.PreviousValidators[iNdEx]))) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x22 } } if len(m.CurrentValidators) > 0 { @@ -448,16 +487,9 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.CurrentValidators[iNdEx]) i = encodeVarintParlia(dAtA, i, uint64(len(m.CurrentValidators[iNdEx]))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } } - if len(m.AccountProof) > 0 { - i -= len(m.AccountProof) - copy(dAtA[i:], m.AccountProof) - i = encodeVarintParlia(dAtA, i, uint64(len(m.AccountProof))) - i-- - dAtA[i] = 0x1a - } if m.TrustedHeight != nil { { size, err := m.TrustedHeight.MarshalToSizedBuffer(dAtA[:i]) @@ -590,6 +622,43 @@ func (m *Misbehaviour) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ProveState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProveState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProveState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CommitmentProof) > 0 { + i -= len(m.CommitmentProof) + copy(dAtA[i:], m.CommitmentProof) + i = encodeVarintParlia(dAtA, i, uint64(len(m.CommitmentProof))) + i-- + dAtA[i] = 0x12 + } + if len(m.AccountProof) > 0 { + i -= len(m.AccountProof) + copy(dAtA[i:], m.AccountProof) + i = encodeVarintParlia(dAtA, i, uint64(len(m.AccountProof))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintParlia(dAtA []byte, offset int, v uint64) int { offset -= sovParlia(v) base := offset @@ -661,10 +730,6 @@ func (m *Header) Size() (n int) { l = m.TrustedHeight.Size() n += 1 + l + sovParlia(uint64(l)) } - l = len(m.AccountProof) - if l > 0 { - n += 1 + l + sovParlia(uint64(l)) - } if len(m.CurrentValidators) > 0 { for _, b := range m.CurrentValidators { l = len(b) @@ -731,6 +796,23 @@ func (m *Misbehaviour) Size() (n int) { return n } +func (m *ProveState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.AccountProof) + if l > 0 { + n += 1 + l + sovParlia(uint64(l)) + } + l = len(m.CommitmentProof) + if l > 0 { + n += 1 + l + sovParlia(uint64(l)) + } + return n +} + func sovParlia(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1180,40 +1262,6 @@ func (m *Header) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountProof", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParlia - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthParlia - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthParlia - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AccountProof = append(m.AccountProof[:0], dAtA[iNdEx:postIndex]...) - if m.AccountProof == nil { - m.AccountProof = []byte{} - } - iNdEx = postIndex - case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field CurrentValidators", wireType) } @@ -1245,7 +1293,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { m.CurrentValidators = append(m.CurrentValidators, make([]byte, postIndex-iNdEx)) copy(m.CurrentValidators[len(m.CurrentValidators)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 5: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PreviousValidators", wireType) } @@ -1277,7 +1325,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { m.PreviousValidators = append(m.PreviousValidators, make([]byte, postIndex-iNdEx)) copy(m.PreviousValidators[len(m.PreviousValidators)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 6: + case 5: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field CurrentTurnLength", wireType) } @@ -1296,7 +1344,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { break } } - case 7: + case 6: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field PreviousTurnLength", wireType) } @@ -1661,6 +1709,124 @@ func (m *Misbehaviour) Unmarshal(dAtA []byte) error { } return nil } +func (m *ProveState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParlia + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProveState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProveState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountProof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParlia + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthParlia + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthParlia + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AccountProof = append(m.AccountProof[:0], dAtA[iNdEx:postIndex]...) + if m.AccountProof == nil { + m.AccountProof = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommitmentProof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParlia + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthParlia + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthParlia + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CommitmentProof = append(m.CommitmentProof[:0], dAtA[iNdEx:postIndex]...) + if m.CommitmentProof == nil { + m.CommitmentProof = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParlia(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParlia + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipParlia(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/module/proof.go b/module/proof.go index aa70bfa5..0f54071d 100644 --- a/module/proof.go +++ b/module/proof.go @@ -16,11 +16,11 @@ import ( "github.com/ethereum/go-ethereum/trie" ) -func (pr *Prover) getAccountProof(height int64) ([]byte, common.Hash, error) { +func (pr *Prover) getAccountProof(height uint64) ([]byte, common.Hash, error) { stateProof, err := pr.chain.GetProof( pr.chain.IBCAddress(), nil, - big.NewInt(height), + big.NewInt(0).SetUint64(height), ) if err != nil { return nil, common.Hash{}, fmt.Errorf("failed to get account proof %+v", err) @@ -28,7 +28,7 @@ func (pr *Prover) getAccountProof(height int64) ([]byte, common.Hash, error) { return stateProof.AccountProofRLP, common.BytesToHash(stateProof.StorageHash[:]), nil } -func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ([]byte, error) { +func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ([]byte, []byte, error) { // calculate slot for commitment storageKey := crypto.Keccak256Hash(append( crypto.Keccak256Hash(path).Bytes(), @@ -36,7 +36,7 @@ func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ( )) storageKeyHex, err := storageKey.MarshalText() if err != nil { - return nil, fmt.Errorf("failed to marshal slot: height = %d, %+v", height.GetRevisionHeight(), err) + return nil, nil, fmt.Errorf("failed to marshal slot: height = %d, %+v", height.GetRevisionHeight(), err) } // call eth_getProof @@ -46,14 +46,14 @@ func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ( big.NewInt(int64(height.GetRevisionHeight())), ) if err != nil { - return nil, fmt.Errorf("failed to get state commitment proof : address = %s, height = %d, slot = %v, %+v", + return nil, nil, fmt.Errorf("failed to get state commitment proof : address = %s, height = %d, slot = %v, %+v", pr.chain.IBCAddress(), height.GetRevisionHeight(), storageKeyHex, err) } - return stateProof.StorageProofRLP[0], nil + return stateProof.AccountProofRLP, stateProof.StorageProofRLP[0], nil } func (pr *Prover) GetStorageRoot(header *types.Header) (common.Hash, error) { - rlpAccountProof, _, err := pr.getAccountProof(header.Number.Int64()) + rlpAccountProof, _, err := pr.getAccountProof(header.Number.Uint64()) if err != nil { return common.Hash{}, err } @@ -170,24 +170,16 @@ func verifyAccount(target *types.Header, accountProof []byte, path common.Addres return &account, nil } -type getAccountProof = func(height int64) ([]byte, common.Hash, error) - -func withProofAndValidators(headerFn getHeaderFn, accountProofFn getAccountProof, height uint64, ethHeaders []*ETHHeader) (core.Header, error) { - - // get RLP-encoded account proof - rlpAccountProof, _, err := accountProofFn(int64(height)) - if err != nil { - return nil, fmt.Errorf("failed to get account proof : height = %d, %+v", height, err) - } +func withValidators(headerFn getHeaderFn, height uint64, ethHeaders []*ETHHeader) (core.Header, error) { header := &Header{ - AccountProof: rlpAccountProof, - Headers: ethHeaders, + Headers: ethHeaders, } // Get validator set for verify headers previousEpoch := getPreviousEpoch(height) var previousTurnLength uint8 + var err error header.PreviousValidators, previousTurnLength, err = queryValidatorSetAndTurnLength(headerFn, previousEpoch) header.PreviousTurnLength = uint32(previousTurnLength) if err != nil { diff --git a/module/prover.go b/module/prover.go index b9862171..d3d5d8b6 100644 --- a/module/prover.go +++ b/module/prover.go @@ -94,7 +94,7 @@ func (pr *Prover) GetLatestFinalizedHeaderByLatestHeight(latestBlockNumber uint6 return nil, err } // Make headers verifiable - return pr.withProofAndValidators(height, finalizedHeader) + return pr.withValidators(height, finalizedHeader) } // SetupHeadersForUpdate creates a new header based on a given header @@ -126,7 +126,7 @@ func (pr *Prover) SetupHeadersForUpdateByLatestHeight(clientStateLatestHeight ex if ethHeaders == nil { return nil, nil } - return pr.withProofAndValidators(height, ethHeaders) + return pr.withValidators(height, ethHeaders) } latestHeight, err := pr.chain.LatestHeight() if err != nil { @@ -142,7 +142,19 @@ func (pr *Prover) SetupHeadersForUpdateByLatestHeight(clientStateLatestHeight ex func (pr *Prover) ProveState(ctx core.QueryContext, path string, value []byte) ([]byte, clienttypes.Height, error) { proofHeight := toHeight(ctx.Height()) - proof, err := pr.getStateCommitmentProof([]byte(path), proofHeight) + accountProof, commitmentProof, err := pr.getStateCommitmentProof([]byte(path), proofHeight) + if err != nil { + return nil, proofHeight, err + } + ret := ProveState{ + AccountProof: accountProof, + CommitmentProof: commitmentProof, + } + proof, err := ret.Marshal() + if err != nil { + return nil, proofHeight, err + } + return proof, proofHeight, err } @@ -213,8 +225,8 @@ func (pr *Prover) CheckRefreshRequired(counterparty core.ChainInfoICS02Querier) } -func (pr *Prover) withProofAndValidators(height uint64, ethHeaders []*ETHHeader) (core.Header, error) { - return withProofAndValidators(pr.chain.Header, pr.getAccountProof, height, ethHeaders) +func (pr *Prover) withValidators(height uint64, ethHeaders []*ETHHeader) (core.Header, error) { + return withValidators(pr.chain.Header, height, ethHeaders) } func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState, exported.ConsensusState, error) { @@ -234,11 +246,6 @@ func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState return nil, nil, err } - stateRoot, err := pr.GetStorageRoot(header) - if err != nil { - return nil, nil, err - } - chainID, err := pr.chain.CanonicalChainID(context.TODO()) if err != nil { return nil, nil, err @@ -258,7 +265,7 @@ func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState Timestamp: header.Time, PreviousValidatorsHash: makeEpochHash(previousValidators, previousTurnLength), CurrentValidatorsHash: makeEpochHash(currentValidators, currentTurnLength), - StateRoot: stateRoot.Bytes(), + StateRoot: header.Root.Bytes(), } return &clientState, &consensusState, nil } diff --git a/module/prover_test.go b/module/prover_test.go index ce6462ca..ccb94c83 100644 --- a/module/prover_test.go +++ b/module/prover_test.go @@ -96,6 +96,9 @@ func TestProverTestSuite(t *testing.T) { } func (ts *ProverTestSuite) SetupTest() { + err := log.InitLogger("DEBUG", "text", "stdout") + ts.Require().NoError(err) + signerConfig := &hd.SignerConfig{ Mnemonic: "math razor capable expose worth grape metal sunset metal sudden usage scheme", Path: "m/44'/60'/0'/0/0", @@ -113,9 +116,6 @@ func (ts *ProverTestSuite) SetupTest() { err = chain.Init("", 0, codec, false) ts.Require().NoError(err) - err = log.InitLogger("DEBUG", "text", "stdout") - ts.Require().NoError(err) - err = chain.SetRelayInfo(&core.PathEnd{ ClientID: "mock-client-0", ConnectionID: "connection-0", @@ -162,8 +162,13 @@ func (ts *ProverTestSuite) TestQueryClientStateWithProof() { ts.Require().Equal(proofHeight.GetRevisionNumber(), uint64(0)) ts.Require().Equal(proofHeight.GetRevisionHeight(), uint64(21400)) + decoded := ProveState{} + ts.Require().NoError(decoded.Unmarshal(proof)) + + expected, _ := ts.chain.GetProof(common.Address{}, nil, nil) + ts.Require().Equal(common.Bytes2Hex(decoded.AccountProof), common.Bytes2Hex(expected.AccountProofRLP)) // storage_key is 0x0c0dd47e5867d48cad725de0d09f9549bd564c1d143f6c1f451b26ccd981eeae - ts.Require().Equal(common.Bytes2Hex(proof), "f853f8518080a0143145e818eeff83817419a6632ea193fd1acaa4f791eb17282f623f38117f568080808080808080a016cbf6e0ba10512eb618d99a1e34025adb7e6f31d335bda7fb20c8bb95fb5b978080808080") + ts.Require().Equal(common.Bytes2Hex(decoded.CommitmentProof), "f853f8518080a0143145e818eeff83817419a6632ea193fd1acaa4f791eb17282f623f38117f568080808080808080a016cbf6e0ba10512eb618d99a1e34025adb7e6f31d335bda7fb20c8bb95fb5b978080808080") } func (ts *ProverTestSuite) TestConnection() { diff --git a/module/setup.go b/module/setup.go index a4e6a645..dc86ec3d 100644 --- a/module/setup.go +++ b/module/setup.go @@ -18,6 +18,8 @@ func setupHeadersForUpdate( latestFinalizedHeader *Header, latestHeight exported.Height, ) ([]core.Header, error) { + logger := log.GetLogger() + logger.Debug("setupHeadersForUpdate start", "target", latestFinalizedHeader.GetHeight().GetRevisionHeight()) targetHeaders := make([]core.Header, 0) // Needless to update already saved state @@ -40,11 +42,12 @@ func setupHeadersForUpdate( return nil, err } if verifiableEpoch == nil { - log.GetLogger().Error("[FastFinalityError]", fmt.Errorf("insufficient vote attestation: epochHeight=%d, trustedEpochHeight=%d", epochHeight, trustedEpochHeight)) + logger.Error("[FastFinalityError]", fmt.Errorf("insufficient vote attestation: epochHeight=%d, trustedEpochHeight=%d", epochHeight, trustedEpochHeight)) return withTrustedHeight(targetHeaders, clientStateLatestHeight), nil } targetHeaders = append(targetHeaders, verifiableEpoch) trustedEpochHeight = epochHeight + logger.Debug("setup epoch header", "height", epochHeight) } return withTrustedHeight(append(targetHeaders, latestFinalizedHeader), clientStateLatestHeight), nil } @@ -78,7 +81,7 @@ func withTrustedHeight(targetHeaders []core.Header, clientStateLatestHeight expo } h.(*Header).TrustedHeight = &trustedHeight - logger.Debug("setupHeadersForUpdate", "target", h.GetHeight(), "trusted", trustedHeight, "headerSize", len(h.(*Header).Headers)) + logger.Debug("setupHeadersForUpdate end", "target", h.GetHeight(), "trusted", trustedHeight, "headerSize", len(h.(*Header).Headers)) } return targetHeaders } diff --git a/proto/ibc/lightclients/parlia/v1/parlia.proto b/proto/ibc/lightclients/parlia/v1/parlia.proto index 5c703500..762a126e 100644 --- a/proto/ibc/lightclients/parlia/v1/parlia.proto +++ b/proto/ibc/lightclients/parlia/v1/parlia.proto @@ -28,11 +28,10 @@ message ETHHeader { message Header { repeated ETHHeader headers = 1; ibc.core.client.v1.Height trusted_height = 2; - bytes account_proof = 3; - repeated bytes current_validators = 4; - repeated bytes previous_validators = 5; - uint32 current_turn_length = 6; - uint32 previous_turn_length = 7; + repeated bytes current_validators = 3; + repeated bytes previous_validators = 4; + uint32 current_turn_length = 5; + uint32 previous_turn_length = 6; } message ConsensusState { @@ -46,4 +45,9 @@ message Misbehaviour { string client_id = 1; Header header_1 = 2; Header header_2 = 3; -} \ No newline at end of file +} + +message ProveState { + bytes account_proof = 1; + bytes commitment_proof = 2; +} diff --git a/tests/prover_network_test.go b/tests/prover_network_test.go index 727cdbf2..6ded93c1 100644 --- a/tests/prover_network_test.go +++ b/tests/prover_network_test.go @@ -56,7 +56,6 @@ func (ts *ProverNetworkTestSuite) TestQueryLatestFinalizedHeader() { ts.Require().NotNil(t.RequestsHash) // Check Pargue Enabled ts.Require().True(len(h.PreviousValidators) >= 1) ts.Require().True(len(h.CurrentValidators) >= 1) - ts.Require().True(len(h.AccountProof) >= 1) ts.Require().True(h.CurrentTurnLength >= 1 && h.CurrentTurnLength <= 9) ts.Require().True(h.PreviousTurnLength >= 1 && h.PreviousTurnLength <= 9) } @@ -99,9 +98,7 @@ func (ts *ProverNetworkTestSuite) TestSuccessCreateInitialLightClientState() { ts.Require().Equal(consState.CurrentValidatorsHash, module.MakeEpochHash(cVal, cTurn)) ts.Require().Equal(consState.PreviousValidatorsHash, module.MakeEpochHash(pVal, pTurn)) ts.Require().Equal(consState.Timestamp, header.Time) - storageRoot, err := ts.prover.GetStorageRoot(header) - ts.Require().NoError(err) - ts.Require().Equal(common.BytesToHash(consState.StateRoot), storageRoot) + ts.Require().Equal(common.BytesToHash(consState.StateRoot), header.Root) } func (ts *ProverNetworkTestSuite) makeChain(rpcAddr string, ibcChainID string) module.Chain { diff --git a/tool/testdata/internal/membership/verify_membership.go b/tool/testdata/internal/membership/verify_membership.go index 6a01565e..29fb9a5e 100644 --- a/tool/testdata/internal/membership/verify_membership.go +++ b/tool/testdata/internal/membership/verify_membership.go @@ -2,7 +2,6 @@ package membership import ( "context" - "fmt" "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" conntypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" types3 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" @@ -15,10 +14,7 @@ import ( "github.com/spf13/cobra" "log" "math/big" -) - -const ( - ibcAddress = "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841" + "os" ) type verifyMembershipModule struct { @@ -52,7 +48,7 @@ func (m *verifyMembershipModule) latest() *cobra.Command { } path := host.ConnectionPath("connection-0") - stateRoot, proof, proofHeight, err := m.proveState(chainID, 8645, path, commitment) + stateRoot, proof, proofHeight, err := m.proveState(chainID, path, commitment) if err != nil { log.Panic(err) } @@ -65,10 +61,13 @@ func (m *verifyMembershipModule) latest() *cobra.Command { } } -func (m *verifyMembershipModule) proveState(chainID uint64, port int64, path string, value []byte) (common.Hash, []byte, types.Height, error) { +func (m *verifyMembershipModule) proveState(chainID uint64, path string, value []byte) (common.Hash, []byte, types.Height, error) { + rpcAddr := os.Getenv("BSC_RPC_ADDR") + ibcAddress := os.Getenv("BSC_IBC_ADDR") + log.Println(rpcAddr, ibcAddress) chain, err := ethereum.NewChain(ethereum.ChainConfig{ EthChainId: chainID, - RpcAddr: fmt.Sprintf("http://localhost:%d", port), + RpcAddr: rpcAddr, Signer: internal.CreateSignerConfig(), IbcAddress: ibcAddress, }) @@ -89,13 +88,14 @@ func (m *verifyMembershipModule) proveState(chainID uint64, port int64, path str return common.Hash{}, nil, types.Height{}, err } - stateRoot, err := prover.GetStorageRoot(header) + proof, proofHeight, err := prover.ProveState(ctx, path, value) + storageRoot, err := prover.GetStorageRoot(header) if err != nil { return common.Hash{}, nil, types.Height{}, err } + log.Println("storageRoot", storageRoot) - proof, proofHeight, err := prover.ProveState(ctx, path, value) - return stateRoot, proof, proofHeight, err + return header.Root, proof, proofHeight, err } func CreateVerifyMembership() *cobra.Command { diff --git a/tool/testdata/internal/update_client.go b/tool/testdata/internal/update_client.go index c5461f14..dd402c2e 100644 --- a/tool/testdata/internal/update_client.go +++ b/tool/testdata/internal/update_client.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "log" - "os" ) type updateClientModule struct { @@ -150,11 +149,6 @@ func (m *updateClientModule) printHeader(prover *module.Prover, chain module.Cha return errors.WithStack(err) } - account, err := header.Account(common.HexToAddress(os.Getenv("BSC_IBC_ADDR"))) - if err != nil { - return errors.WithStack(err) - } - // setup updating, err := prover.SetupHeadersForUpdateByLatestHeight(types.NewHeight(header.GetHeight().GetRevisionNumber(), target.Number.Uint64()-1), header) if err != nil { @@ -181,7 +175,6 @@ func (m *updateClientModule) printHeader(prover *module.Prover, chain module.Cha return err } log.Println("header", common.Bytes2Hex(marshal)) - log.Println("stateRoot", account.Root) log.Println("height", header.GetHeight().GetRevisionHeight()) log.Println("trustedHeight", trustedHeight) log.Println("currentEpochHashOfTrustedHeight", common.Bytes2Hex(module.MakeEpochHash(currentValidatorSetOfTrustedHeight, currentTurnLengthOfTrustedHeight)))