Skip to content

Commit

Permalink
use proto definition of lcp v0.2.4
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jan 24, 2024
1 parent 37894e0 commit 4d593ed
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
26 changes: 13 additions & 13 deletions contracts/LCPClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,34 +270,34 @@ contract LCPClient is ILightClient {
ProtoClientState.Data storage clientState = clientStates[clientId];
ConsensusState storage consensusState;

LCPCommitment.UpdateClientMessage memory commitment = LCPCommitment.parseUpdateClientMessage(message.commitment);
LCPCommitment.UpdateClientMessage memory emsg = LCPCommitment.parseUpdateClientMessage(message.elc_message);
if (clientState.latest_height.revision_number == 0 && clientState.latest_height.revision_height == 0) {
require(commitment.emittedStates.length != 0, "EmittedStates must be non-nil");
require(emsg.emittedStates.length != 0, "EmittedStates must be non-nil");
} else {
consensusState = consensusStates[clientId][commitment.prevHeight.toUint128()];
require(commitment.prevStateId != bytes32(0), "PrevStateID must be non-nil");
require(consensusState.stateId == commitment.prevStateId, "unexpected StateID");
consensusState = consensusStates[clientId][emsg.prevHeight.toUint128()];
require(emsg.prevStateId != bytes32(0), "PrevStateID must be non-nil");
require(consensusState.stateId == emsg.prevStateId, "unexpected StateID");
}

LCPCommitment.validationContextEval(commitment.context, block.timestamp * 1e9);
LCPCommitment.validationContextEval(emsg.context, block.timestamp * 1e9);

require(isActiveKey(clientId, address(bytes20(message.signer))), "the key isn't active");

require(
verifyCommitmentProof(keccak256(message.commitment), message.signature, address(bytes20(message.signer))),
verifyCommitmentProof(keccak256(message.elc_message), message.signature, address(bytes20(message.signer))),
"failed to verify the commitment"
);

if (clientState.latest_height.lt(commitment.postHeight)) {
clientState.latest_height = commitment.postHeight;
if (clientState.latest_height.lt(emsg.postHeight)) {
clientState.latest_height = emsg.postHeight;
}

consensusState = consensusStates[clientId][commitment.postHeight.toUint128()];
consensusState.stateId = commitment.postStateId;
consensusState.timestamp = uint64(commitment.timestamp);
consensusState = consensusStates[clientId][emsg.postHeight.toUint128()];
consensusState.stateId = emsg.postStateId;
consensusState.timestamp = uint64(emsg.timestamp);

heights = new Height.Data[](1);
heights[0] = commitment.postHeight;
heights[0] = emsg.postHeight;
return heights;
}

Expand Down
18 changes: 9 additions & 9 deletions contracts/proto/ibc/lightclients/lcp/v1/LCP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library IbcLightclientsLcpV1UpdateClientMessage {

//struct definition
struct Data {
bytes commitment;
bytes elc_message;
bytes signer;
bytes signature;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ library IbcLightclientsLcpV1UpdateClientMessage {
(fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs);
pointer += bytesRead;
if (fieldId == 1) {
pointer += _read_commitment(pointer, bs, r);
pointer += _read_elc_message(pointer, bs, r);
} else
if (fieldId == 2) {
pointer += _read_signer(pointer, bs, r);
Expand All @@ -85,13 +85,13 @@ library IbcLightclientsLcpV1UpdateClientMessage {
* @param r The in-memory struct
* @return The number of bytes decoded
*/
function _read_commitment(
function _read_elc_message(
uint256 p,
bytes memory bs,
Data memory r
) internal pure returns (uint) {
(bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs);
r.commitment = x;
r.elc_message = x;
return sz;
}

Expand Down Expand Up @@ -162,14 +162,14 @@ library IbcLightclientsLcpV1UpdateClientMessage {
uint256 offset = p;
uint256 pointer = p;

if (r.commitment.length != 0) {
if (r.elc_message.length != 0) {
pointer += ProtoBufRuntime._encode_key(
1,
ProtoBufRuntime.WireType.LengthDelim,
pointer,
bs
);
pointer += ProtoBufRuntime._encode_bytes(r.commitment, pointer, bs);
pointer += ProtoBufRuntime._encode_bytes(r.elc_message, pointer, bs);
}
if (r.signer.length != 0) {
pointer += ProtoBufRuntime._encode_key(
Expand Down Expand Up @@ -232,7 +232,7 @@ library IbcLightclientsLcpV1UpdateClientMessage {
Data memory r
) internal pure returns (uint) {
uint256 e;
e += 1 + ProtoBufRuntime._sz_lendelim(r.commitment.length);
e += 1 + ProtoBufRuntime._sz_lendelim(r.elc_message.length);
e += 1 + ProtoBufRuntime._sz_lendelim(r.signer.length);
e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length);
return e;
Expand All @@ -243,7 +243,7 @@ library IbcLightclientsLcpV1UpdateClientMessage {
Data memory r
) internal pure returns (bool) {

if (r.commitment.length != 0) {
if (r.elc_message.length != 0) {
return false;
}

Expand All @@ -266,7 +266,7 @@ library IbcLightclientsLcpV1UpdateClientMessage {
* @param output The in-storage struct
*/
function store(Data memory input, Data storage output) internal {
output.commitment = input.commitment;
output.elc_message = input.elc_message;
output.signer = input.signer;
output.signature = input.signature;

Expand Down
2 changes: 1 addition & 1 deletion proto/ibc/lightclients/lcp/v1/LCP.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@hyperledger-labs/yui-ibc-solidity/proto/core/02-client/Client.proto";
option go_package = "github.com/datachainlab/lcp/go/light-clients/lcp/types";

message UpdateClientMessage {
bytes commitment = 1;
bytes elc_message = 1;
bytes signer = 2;
bytes signature = 3;
}
Expand Down
2 changes: 1 addition & 1 deletion test/LCPClientBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract contract BaseLCPClientBenchmark is BasicTest {
internal
returns (UpdateClientMessage.Data memory message)
{
message.commitment =
message.elc_message =
readDecodedBytes(string(abi.encodePacked(updateClientFilePrefix, commandResultSuffix)), ".message");
message.signer =
readDecodedBytes(string(abi.encodePacked(updateClientFilePrefix, commandResultSuffix)), ".signer");
Expand Down
2 changes: 1 addition & 1 deletion test/LCPClientTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ contract LCPClientTest is BasicTest {
internal
returns (UpdateClientMessage.Data memory message)
{
message.commitment =
message.elc_message =
readDecodedBytes(string(abi.encodePacked(updateClientFilePrefix, commandResultSuffix)), ".message");
message.signer =
readDecodedBytes(string(abi.encodePacked(updateClientFilePrefix, commandResultSuffix)), ".signer");
Expand Down

0 comments on commit 4d593ed

Please sign in to comment.