From 0865da2d1a5c82aa0375e9a81c17ea04d59a4cca Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sun, 30 Jun 2024 23:30:25 +0900 Subject: [PATCH 1/3] qbft: add `max_clock_drift` to client state Signed-off-by: Jun Kimura --- .gas-snapshot | 126 +++++++++++++------------- contracts/clients/qbft/QBFTClient.sol | 5 + contracts/proto/QBFT.sol | 36 ++++++++ pkg/ibc/clients/qbft/QBFT.pb.go | 101 ++++++++++++++------- pkg/testing/chains.go | 22 +++-- proto/clients/qbft/QBFT.proto | 5 + 6 files changed, 191 insertions(+), 104 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index a32df250..e3f821ae 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,73 +1,73 @@ -IBCMockAppTest:testHandshake() (gas: 3537520) -IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 2644408) -IBCMockAppTest:testPacketRelay() (gas: 9584548) -IBCMockAppTest:testPacketTimeout() (gas: 2981201) -IBCTest:testBenchmarkCreateMockClient() (gas: 209410) -IBCTest:testBenchmarkLCUpdateMockClient() (gas: 39945) -IBCTest:testBenchmarkRecvPacket() (gas: 133353) -IBCTest:testBenchmarkSendPacket() (gas: 80964) -IBCTest:testBenchmarkUpdateMockClient() (gas: 137373) +IBCMockAppTest:testHandshake() (gas: 4420400) +IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3334308) +IBCMockAppTest:testPacketRelay() (gas: 13931868) +IBCMockAppTest:testPacketTimeout() (gas: 4279269) +IBCTest:testBenchmarkCreateMockClient() (gas: 233366) +IBCTest:testBenchmarkLCUpdateMockClient() (gas: 62005) +IBCTest:testBenchmarkRecvPacket() (gas: 158921) +IBCTest:testBenchmarkSendPacket() (gas: 128424) +IBCTest:testBenchmarkUpdateMockClient() (gas: 160229) IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 947, ~: 947) -TestICS02:testCreateClient() (gas: 33302626) -TestICS02:testInvalidCreateClient() (gas: 33152264) -TestICS02:testInvalidUpdateClient() (gas: 33154327) -TestICS02:testRegisterClient() (gas: 32897266) -TestICS02:testRegisterClientDuplicatedClientType() (gas: 32880491) -TestICS02:testRegisterClientInvalidClientType() (gas: 32864530) -TestICS02:testUpdateClient() (gas: 33319687) -TestICS03Handshake:testConnOpenAck() (gas: 1631658) -TestICS03Handshake:testConnOpenConfirm() (gas: 1766077) -TestICS03Handshake:testConnOpenInit() (gas: 1279190) -TestICS03Handshake:testConnOpenTry() (gas: 2160696) -TestICS03Handshake:testInvalidConnOpenAck() (gas: 2031548) -TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2095798) -TestICS03Handshake:testInvalidConnOpenInit() (gas: 666951) -TestICS03Handshake:testInvalidConnOpenTry() (gas: 2101089) +TestICS02:testCreateClient() (gas: 36328221) +TestICS02:testInvalidCreateClient() (gas: 36225735) +TestICS02:testInvalidUpdateClient() (gas: 36224438) +TestICS02:testRegisterClient() (gas: 35880037) +TestICS02:testRegisterClientDuplicatedClientType() (gas: 35865346) +TestICS02:testRegisterClientInvalidClientType() (gas: 35894673) +TestICS02:testUpdateClient() (gas: 36392638) +TestICS03Handshake:testConnOpenAck() (gas: 1858318) +TestICS03Handshake:testConnOpenConfirm() (gas: 2054253) +TestICS03Handshake:testConnOpenInit() (gas: 1429882) +TestICS03Handshake:testConnOpenTry() (gas: 2398932) +TestICS03Handshake:testInvalidConnOpenAck() (gas: 2422020) +TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535722) +TestICS03Handshake:testInvalidConnOpenInit() (gas: 783147) +TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342609) TestICS03Version:testCopyVersions() (gas: 558658) TestICS03Version:testFindSupportedVersion() (gas: 19400) TestICS03Version:testIsSupportedVersion() (gas: 7864) TestICS03Version:testPickVersion() (gas: 25327) TestICS03Version:testVerifyProposedVersion() (gas: 11777) TestICS03Version:testVerifySupportedFeature() (gas: 4153) -TestICS04Handshake:testBindPort() (gas: 37502) -TestICS04Handshake:testChanClose() (gas: 8864072) -TestICS04Handshake:testChanOpenAck() (gas: 2988216) -TestICS04Handshake:testChanOpenConfirm() (gas: 3170513) -TestICS04Handshake:testChanOpenInit() (gas: 2274533) -TestICS04Handshake:testChanOpenTry() (gas: 2759774) -TestICS04Handshake:testInvalidChanOpenAck() (gas: 2115402) -TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2171859) -TestICS04Handshake:testInvalidChanOpenInit() (gas: 1299857) -TestICS04Handshake:testInvalidChanOpenTry() (gas: 1378320) -TestICS04Packet:testAcknowledgementPacket() (gas: 2393006) -TestICS04Packet:testInvalidSendPacket() (gas: 2385887) -TestICS04Packet:testRecvPacket() (gas: 7941501) -TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 2411677) -TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 2421551) -TestICS04Packet:testSendPacket() (gas: 5160796) -TestICS04Packet:testTimeoutOnClose() (gas: 2654567) -TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 32899652) -TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 2648059) -TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 3322208) -TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 3402742) -TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 3312033) -TestICS04Upgrade:testUpgradeFull() (gas: 34308220) -TestICS04Upgrade:testUpgradeInit() (gas: 2362479) -TestICS04Upgrade:testUpgradeNoChanges() (gas: 1950920) -TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3051844) -TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 3325729) -TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 3522672) -TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 2743014) -TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 10509336) -TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 11912012) -TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 31027545) -TestICS04Upgrade:testUpgradeToOrdered() (gas: 36895593) -TestICS04Upgrade:testUpgradeToUnordered() (gas: 29370382) -TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 37604) -TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2034676) -TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 1859258) -TestICS20:testAddressToHex(address) (runs: 256, μ: 22676, ~: 22804) +TestICS04Handshake:testBindPort() (gas: 124350) +TestICS04Handshake:testChanClose() (gas: 12938668) +TestICS04Handshake:testChanOpenAck() (gas: 3459596) +TestICS04Handshake:testChanOpenConfirm() (gas: 3770909) +TestICS04Handshake:testChanOpenInit() (gas: 2543717) +TestICS04Handshake:testChanOpenTry() (gas: 3100002) +TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439814) +TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517403) +TestICS04Handshake:testInvalidChanOpenInit() (gas: 1758661) +TestICS04Handshake:testInvalidChanOpenTry() (gas: 1773244) +TestICS04Packet:testAcknowledgementPacket() (gas: 3351538) +TestICS04Packet:testInvalidSendPacket() (gas: 3551759) +TestICS04Packet:testRecvPacket() (gas: 10996525) +TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3260141) +TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3279291) +TestICS04Packet:testSendPacket() (gas: 6413300) +TestICS04Packet:testTimeoutOnClose() (gas: 3553791) +TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46694868) +TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455607) +TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5244036) +TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5213202) +TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405965) +TestICS04Upgrade:testUpgradeFull() (gas: 57590258) +TestICS04Upgrade:testUpgradeInit() (gas: 3068755) +TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471908) +TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3902216) +TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5215801) +TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5589764) +TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070972) +TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17679417) +TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21317049) +TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44126259) +TestICS04Upgrade:testUpgradeToOrdered() (gas: 56352929) +TestICS04Upgrade:testUpgradeToUnordered() (gas: 44985196) +TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61712) +TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565532) +TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473970) +TestICS20:testAddressToHex(address) (runs: 256, μ: 22726, ~: 22867) TestICS20:testHexToAddress(string) (runs: 256, μ: 4776, ~: 4734) TestICS20:testIsEscapedString() (gas: 48979) TestICS20:testMarshaling() (gas: 148517) -TestICS20:testParseAmount(uint256) (runs: 256, μ: 27026, ~: 21930) \ No newline at end of file +TestICS20:testParseAmount(uint256) (runs: 256, μ: 26449, ~: 24175) \ No newline at end of file diff --git a/contracts/clients/qbft/QBFTClient.sol b/contracts/clients/qbft/QBFTClient.sol index f9b74f53..87ad703f 100644 --- a/contracts/clients/qbft/QBFTClient.sol +++ b/contracts/clients/qbft/QBFTClient.sol @@ -58,6 +58,8 @@ contract QBFTClient is ILightClient, ILightClientErrors { error InsuffientUntrustedValidatorsSeals(uint256 actual, uint256 threshold); /// @param length length of the signature error InvalidECDSASignatureLength(uint256 length); + /// @dev An error indicating that the header is from the future + error HeaderFromFuture(); string internal constant HEADER_TYPE_URL = "/ibc.lightclients.qbft.v1.Header"; string internal constant CLIENT_STATE_TYPE_URL = "/ibc.lightclients.qbft.v1.ClientState"; @@ -208,6 +210,9 @@ contract QBFTClient is ILightClient, ILightClientErrors { ) { revert LightClientConsensusStateExpired(); } + if (block.timestamp + clientState.max_clock_drift < parsedHeader.time) { + revert HeaderFromFuture(); + } bytes[] memory validators = verify(trustedConsensusState.validators, parsedHeader); if (validators.length == 0) { diff --git a/contracts/proto/QBFT.sol b/contracts/proto/QBFT.sol index 6767b958..7309b878 100644 --- a/contracts/proto/QBFT.sol +++ b/contracts/proto/QBFT.sol @@ -13,6 +13,7 @@ library IbcLightclientsQbftV1ClientState { bytes ibc_store_address; Height.Data latest_height; uint64 trusting_period; + uint64 max_clock_drift; } // Decoder section @@ -72,6 +73,9 @@ library IbcLightclientsQbftV1ClientState { if (fieldId == 4) { pointer += _read_trusting_period(pointer, bs, r); } else + if (fieldId == 5) { + pointer += _read_max_clock_drift(pointer, bs, r); + } else { pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); } @@ -150,6 +154,23 @@ library IbcLightclientsQbftV1ClientState { 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_max_clock_drift( + uint256 p, + bytes memory bs, + Data memory r + ) internal pure returns (uint) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.max_clock_drift = x; + return sz; + } + // struct decoder /** * @dev The decoder for reading a inner struct field @@ -239,6 +260,15 @@ library IbcLightclientsQbftV1ClientState { ); pointer += ProtoBufRuntime._encode_uint64(r.trusting_period, pointer, bs); } + if (r.max_clock_drift != 0) { + pointer += ProtoBufRuntime._encode_key( + 5, + ProtoBufRuntime.WireType.Varint, + pointer, + bs + ); + pointer += ProtoBufRuntime._encode_uint64(r.max_clock_drift, pointer, bs); + } return pointer - offset; } // nested encoder @@ -286,6 +316,7 @@ library IbcLightclientsQbftV1ClientState { e += 1 + ProtoBufRuntime._sz_lendelim(r.ibc_store_address.length); e += 1 + ProtoBufRuntime._sz_lendelim(Height._estimate(r.latest_height)); e += 1 + ProtoBufRuntime._sz_uint64(r.trusting_period); + e += 1 + ProtoBufRuntime._sz_uint64(r.max_clock_drift); return e; } // empty checker @@ -306,6 +337,10 @@ library IbcLightclientsQbftV1ClientState { return false; } + if (r.max_clock_drift != 0) { + return false; + } + return true; } @@ -321,6 +356,7 @@ library IbcLightclientsQbftV1ClientState { output.ibc_store_address = input.ibc_store_address; Height.store(input.latest_height, output.latest_height); output.trusting_period = input.trusting_period; + output.max_clock_drift = input.max_clock_drift; } diff --git a/pkg/ibc/clients/qbft/QBFT.pb.go b/pkg/ibc/clients/qbft/QBFT.pb.go index 3e164aae..2102a5ac 100644 --- a/pkg/ibc/clients/qbft/QBFT.pb.go +++ b/pkg/ibc/clients/qbft/QBFT.pb.go @@ -29,7 +29,11 @@ type ClientState struct { ChainId []byte `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` IbcStoreAddress []byte `protobuf:"bytes,2,opt,name=ibc_store_address,json=ibcStoreAddress,proto3" json:"ibc_store_address,omitempty"` LatestHeight client.Height `protobuf:"bytes,3,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height"` - TrustingPeriod uint64 `protobuf:"varint,4,opt,name=trusting_period,json=trustingPeriod,proto3" json:"trusting_period,omitempty"` + // duration in seconds + // if this is set to 0, the client will not verify the header's timestamp is within the trusting period + TrustingPeriod uint64 `protobuf:"varint,4,opt,name=trusting_period,json=trustingPeriod,proto3" json:"trusting_period,omitempty"` + // duration in seconds + MaxClockDrift uint64 `protobuf:"varint,5,opt,name=max_clock_drift,json=maxClockDrift,proto3" json:"max_clock_drift,omitempty"` } func (m *ClientState) Reset() { *m = ClientState{} } @@ -105,6 +109,7 @@ func (m *ConsensusState) XXX_DiscardUnknown() { var xxx_messageInfo_ConsensusState proto.InternalMessageInfo type Header struct { + // RLP encoded header of Besu, which does not include the seals in the extra data BesuHeaderRlp []byte `protobuf:"bytes,1,opt,name=besu_header_rlp,json=besuHeaderRlp,proto3" json:"besu_header_rlp,omitempty"` Seals [][]byte `protobuf:"bytes,2,rep,name=seals,proto3" json:"seals,omitempty"` TrustedHeight client.Height `protobuf:"bytes,3,opt,name=trusted_height,json=trustedHeight,proto3" json:"trusted_height"` @@ -153,39 +158,40 @@ func init() { func init() { proto.RegisterFile("clients/qbft/QBFT.proto", fileDescriptor_ede64ec125899b5a) } var fileDescriptor_ede64ec125899b5a = []byte{ - // 502 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6e, 0xd3, 0x4e, - 0x10, 0xc6, 0xe3, 0x7f, 0xfc, 0x6f, 0x61, 0x9b, 0x34, 0xea, 0x52, 0x09, 0x53, 0x90, 0x89, 0x72, - 0x80, 0x08, 0xc9, 0x5e, 0x08, 0x7d, 0x00, 0x9a, 0x4a, 0xa8, 0xdc, 0x8a, 0xcb, 0x89, 0x8b, 0xb5, - 0xbb, 0xde, 0xd8, 0x2b, 0x1c, 0xaf, 0xd9, 0x1d, 0x57, 0xe4, 0xca, 0x13, 0x70, 0xe3, 0x25, 0xb8, - 0x70, 0xe0, 0x1d, 0x72, 0xec, 0x91, 0x13, 0x82, 0xe4, 0x45, 0x90, 0x77, 0x5d, 0xd1, 0x13, 0x9c, - 0xbc, 0xdf, 0x37, 0x3f, 0x8d, 0x67, 0x3e, 0x0d, 0xba, 0xcb, 0x4b, 0x29, 0x2a, 0x30, 0xe4, 0x3d, - 0x5b, 0x00, 0x79, 0x3d, 0x7f, 0xf9, 0x26, 0xae, 0xb5, 0x02, 0x85, 0x03, 0xc9, 0x78, 0x5c, 0xca, - 0xbc, 0x80, 0x8e, 0x88, 0x5b, 0x22, 0xbe, 0x7c, 0x76, 0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 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x26, 0x97, - 0x43, 0x9c, 0xf3, 0x02, 0x00, 0x00, + // 526 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x41, 0x6f, 0xd3, 0x3c, + 0x18, 0xc7, 0x9b, 0x77, 0xdd, 0xf6, 0xe2, 0xb5, 0x9b, 0x16, 0x26, 0x11, 0x06, 0x0a, 0x55, 0x0f, + 0x50, 0x21, 0x25, 0x81, 0xb2, 0x0f, 0xc0, 0x5a, 0x84, 0xc6, 0x6d, 0x64, 0x9c, 0xb8, 0x44, 0xb6, + 0xe3, 0x26, 0xd6, 0xdc, 0x38, 0xd8, 0x4f, 0xa6, 0xf6, 0xca, 0x27, 0xe0, 0xc6, 0x97, 0xe0, 0xca, + 0x77, 0xe8, 0x71, 0x47, 0xb8, 0x20, 0x68, 0xbf, 0x08, 0xb2, 0x9d, 0x89, 0x9d, 0xe0, 0x14, 0x3f, + 0xbf, 0xe7, 0xa7, 0x27, 0xf9, 0x3f, 0x72, 0xd0, 0x3d, 0x2a, 0x38, 0xab, 0x40, 0x27, 0x1f, 0xc8, + 0x0c, 0x92, 0xb7, 0x93, 0xd7, 0xef, 0xe2, 0x5a, 0x49, 0x90, 0x7e, 0xc0, 0x09, 0x8d, 0x05, 0x2f, + 0x4a, 0x68, 0x8d, 0xd8, 0x18, 0xf1, 0xd5, 0xf3, 0xe3, 0xa3, 0x42, 0x16, 0xd2, 0x4a, 0x89, 0x39, + 0x39, 0xff, 0x78, 0xa8, 0xa5, 0xe0, 0x39, 0x87, 0x65, 0x64, 0x6b, 0xd2, 0xcc, 0x22, 0xb6, 0x00, + 0x56, 0x69, 0x2e, 0x2b, 0xdd, 0x3a, 0x0f, 0xa8, 0x54, 0x2c, 0x79, 0x36, 0x8e, 0xdc, 0xc8, 0x64, + 0x6a, 0x1f, 0xae, 0x39, 0xfc, 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, 0xf0, 0x8b, 0x87, 0x76, + 0xce, 0x18, 0xce, 0x99, 0x32, 0x9f, 0x45, 0x98, 0x6e, 0xb2, 0xd2, 0x96, 0x99, 0x12, 0x75, 0xbb, + 0xc1, 0xbe, 0xc1, 0x4e, 0x4a, 0x45, 0xed, 0x1f, 0xa1, 0x6d, 0xcd, 0xb0, 0x30, 0xbb, 0x33, 0xd3, + 0x5c, 0xe1, 0x9f, 0x20, 0x17, 0x93, 0xe5, 0x7f, 0x5d, 0x59, 0xbf, 0x95, 0xda, 0x9d, 0xc5, 0xe8, + 0x2e, 0xa6, 0x54, 0x36, 0x15, 0x64, 0xda, 0x24, 0xcc, 0x6a, 0x25, 0xe5, 0xcc, 0xee, 0xad, 0x97, + 0x1e, 0xb6, 0x2d, 0x9b, 0xfd, 0xdc, 0x34, 0x26, 0x9f, 0xbd, 0x8f, 0x5f, 0x83, 0x13, 0x34, 0x7e, + 0x59, 0x2e, 0x6b, 0xa6, 0x04, 0xcb, 0x0b, 0xa6, 0x22, 0x81, 0x89, 0x4e, 0x96, 0x0d, 0x8f, 0x38, + 0xa1, 0xd1, 0xcd, 0x85, 0x4a, 0xa8, 0xac, 0x40, 0x61, 0x0a, 0x3a, 0xb1, 0x37, 0x65, 0xf5, 0x2b, + 0xec, 0xac, 0xd6, 0xa1, 0x77, 0xbd, 0x0e, 0xbd, 0x9f, 0xeb, 0xd0, 0xfb, 0xb4, 0x09, 0x3b, 0xd7, + 0x9b, 0xb0, 0xf3, 0x6d, 0x13, 0x76, 0xde, 0x9f, 0x16, 0x1c, 0xca, 0x86, 0xc4, 0x54, 0xce, 0x93, + 0x7f, 0x4f, 0xae, 0x2f, 0x8b, 0x84, 0x13, 0x9a, 0xdc, 0xfe, 0x09, 0xc8, 0x8e, 0x7d, 0xcb, 0x8b, + 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x76, 0x28, 0x74, 0x4a, 0x1b, 0x03, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { @@ -208,6 +214,11 @@ func (m *ClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxClockDrift != 0 { + i = encodeVarintQBFT(dAtA, i, uint64(m.MaxClockDrift)) + i-- + dAtA[i] = 0x28 + } if m.TrustingPeriod != 0 { i = encodeVarintQBFT(dAtA, i, uint64(m.TrustingPeriod)) i-- @@ -370,6 +381,9 @@ func (m *ClientState) Size() (n int) { if m.TrustingPeriod != 0 { n += 1 + sovQBFT(uint64(m.TrustingPeriod)) } + if m.MaxClockDrift != 0 { + n += 1 + sovQBFT(uint64(m.MaxClockDrift)) + } return n } @@ -575,6 +589,25 @@ func (m *ClientState) Unmarshal(dAtA []byte) error { break } } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxClockDrift", wireType) + } + m.MaxClockDrift = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQBFT + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxClockDrift |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQBFT(dAtA[iNdEx:]) diff --git a/pkg/testing/chains.go b/pkg/testing/chains.go index 469e98ab..f340666b 100644 --- a/pkg/testing/chains.go +++ b/pkg/testing/chains.go @@ -40,13 +40,10 @@ import ( ) const ( - ICS20Version = "ics20-1" - MockAppVersion = "mockapp-1" - BlockTime uint64 = 1000 * 1000 * 1000 // 1[sec] - DefaultDelayPeriod uint64 = 0 - DefaultPrefix = "ibc" - TransferPort = "transfer" - MockPort = "mock" + ICS20Version = "ics20-1" + MockAppVersion = "mockapp-1" + TransferPort = "transfer" + MockPort = "mock" RelayerKeyIndex uint32 = 0 @@ -55,6 +52,15 @@ const ( MockAsyncPacketData = "mock async packet data" ) +var ( + DefaultPrefix = "ibc" + + BlockTime uint64 = 1000 * 1000 * 1000 // 1[sec] + DefaultDelayPeriod uint64 = 0 // sec + DefaultTrustPeriod uint64 = 60 // sec + DefaultMaxClockDrift uint64 = 30 // sec +) + var ( abiIBCHandler abi.ABI abiSendPacket, @@ -302,6 +308,8 @@ func (chain *Chain) ConstructQBFTMsgCreateClient(counterparty *Chain) ibchandler ChainId: counterparty.ChainIDU256(), IbcStoreAddress: counterparty.ContractConfig.IBCHandlerAddress.Bytes(), LatestHeight: ibcclient.NewHeightFromBN(counterparty.LastHeader().Number), + TrustingPeriod: DefaultTrustPeriod, + MaxClockDrift: DefaultMaxClockDrift, } consensusState := qbftclienttypes.ConsensusState{ Timestamp: counterparty.LastHeader().Time, diff --git a/proto/clients/qbft/QBFT.proto b/proto/clients/qbft/QBFT.proto index 5d8b54c0..fa0d37f0 100644 --- a/proto/clients/qbft/QBFT.proto +++ b/proto/clients/qbft/QBFT.proto @@ -14,7 +14,11 @@ message ClientState { bytes chain_id = 1; bytes ibc_store_address = 2; Height latest_height = 3 [(gogoproto.nullable) = false]; + // duration in seconds + // if this is set to 0, the client will not verify the header's timestamp is within the trusting period uint64 trusting_period = 4; + // duration in seconds + uint64 max_clock_drift = 5; } message ConsensusState { @@ -24,6 +28,7 @@ message ConsensusState { } message Header { + // RLP encoded header of Besu, which does not include the seals in the extra data bytes besu_header_rlp = 1; repeated bytes seals = 2; Height trusted_height = 3 [(gogoproto.nullable) = false]; From da31c1f867b0c386d2e13f4ee55cb2f6a18faa86 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sun, 30 Jun 2024 23:38:16 +0900 Subject: [PATCH 2/3] fix healthcheck for containers Signed-off-by: Jun Kimura --- chains/compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chains/compose.yml b/chains/compose.yml index 0023d6ce..58f2e363 100644 --- a/chains/compose.yml +++ b/chains/compose.yml @@ -5,7 +5,7 @@ services: - 8645:8545 - 8646:8546 healthcheck: - test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || exit 1" ] + test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || grep \"00000000000000000000000000000000:2161 00000000000000000000000000000000:0000 0A\" /proc/net/tcp6 || exit 1" ] interval: 100ms timeout: 1s retries: 100 @@ -15,7 +15,7 @@ services: - 8745:8545 - 8746:8546 healthcheck: - test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || exit 1" ] + test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || grep \"00000000000000000000000000000000:2161 00000000000000000000000000000000:0000 0A\" /proc/net/tcp6 || exit 1" ] interval: 100ms timeout: 1s retries: 100 @@ -26,7 +26,7 @@ services: - 8645:8545 - 8646:8546 healthcheck: - test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || exit 1" ] + test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || grep \"00000000000000000000000000000000:2161 00000000000000000000000000000000:0000 0A\" /proc/net/tcp6 || exit 1" ] interval: 100ms timeout: 1s retries: 100 @@ -36,7 +36,7 @@ services: - 8745:8545 - 8746:8546 healthcheck: - test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || exit 1" ] + test: [ "CMD-SHELL", "grep \"00000000:2161 00000000:0000 0A\" /proc/net/tcp || grep \"00000000000000000000000000000000:2161 00000000000000000000000000000000:0000 0A\" /proc/net/tcp6 || exit 1" ] interval: 100ms timeout: 1s retries: 100 From 66f5fa352f0988be46d94846ad834c2923449c13 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 1 Jul 2024 00:12:39 +0900 Subject: [PATCH 3/3] increase trusting period Signed-off-by: Jun Kimura --- pkg/testing/chains.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testing/chains.go b/pkg/testing/chains.go index f340666b..86ce0885 100644 --- a/pkg/testing/chains.go +++ b/pkg/testing/chains.go @@ -57,7 +57,7 @@ var ( BlockTime uint64 = 1000 * 1000 * 1000 // 1[sec] DefaultDelayPeriod uint64 = 0 // sec - DefaultTrustPeriod uint64 = 60 // sec + DefaultTrustPeriod uint64 = 5 * 60 // sec DefaultMaxClockDrift uint64 = 30 // sec )