Skip to content

Commit 3cd1408

Browse files
committed
add hostTimestamp to IBCHost
* fix upgrade timeout unit to nanosecond * fix overflow check for host timestamp Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent d60289f commit 3cd1408

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

contracts/core/04-channel/IBCChannelPacketSendRecv.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ contract IBCChannelPacketSendRecv is
133133
{
134134
revert IBCChannelTimeoutPacketHeight(block.number, msg_.packet.timeoutHeight.revision_height);
135135
}
136-
if (msg_.packet.timeoutTimestamp != 0 && block.timestamp * 1e9 >= msg_.packet.timeoutTimestamp) {
137-
revert IBCChannelTimeoutPacketTimestamp(block.timestamp * 1e9, msg_.packet.timeoutTimestamp);
136+
if (msg_.packet.timeoutTimestamp != 0 && hostTimestamp() >= msg_.packet.timeoutTimestamp) {
137+
revert IBCChannelTimeoutPacketTimestamp(hostTimestamp(), msg_.packet.timeoutTimestamp);
138138
}
139139

140140
verifyPacketCommitment(

contracts/core/04-channel/IBCChannelUpgrade.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ contract IBCChannelUpgradeInitTryAck is IBCChannelUpgradeBase, IIBCChannelUpgrad
549549
Timeout.Data calldata timeout = msg_.counterpartyUpgrade.timeout;
550550
if (
551551
(timeout.height.revision_height != 0 && block.number >= timeout.height.revision_height)
552-
|| (timeout.timestamp != 0 && block.timestamp >= timeout.timestamp)
552+
|| (timeout.timestamp != 0 && hostTimestamp() >= timeout.timestamp)
553553
) {
554554
restoreChannel(msg_.portId, msg_.channelId, UpgradeHandshakeError.Timeout);
555555
return false;
@@ -620,7 +620,7 @@ contract IBCChannelUpgradeConfirmTimeoutCancel is IBCChannelUpgradeBase, IIBCCha
620620
Timeout.Data calldata timeout = msg_.counterpartyUpgrade.timeout;
621621
if (
622622
(timeout.height.revision_height != 0 && block.number >= timeout.height.revision_height)
623-
|| (timeout.timestamp != 0 && block.timestamp >= timeout.timestamp)
623+
|| (timeout.timestamp != 0 && hostTimestamp() >= timeout.timestamp)
624624
) {
625625
restoreChannel(msg_.portId, msg_.channelId, UpgradeHandshakeError.Timeout);
626626
return false;

contracts/core/24-host/IBCHost.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ contract IBCHost is IIBCHostErrors, IBCStore {
1010
// In ibc-solidity, the prefix is not required, but for compatibility with ibc-go this must be a non-empty value.
1111
bytes internal constant DEFAULT_COMMITMENT_PREFIX = bytes("ibc");
1212

13+
/**
14+
* @dev hostTimestamp returns the current timestamp(Unix time in nanoseconds) of the host chain.
15+
*/
16+
function hostTimestamp() internal view virtual returns (uint64) {
17+
return uint64(block.timestamp) * 1e9;
18+
}
19+
1320
/**
1421
* @dev _getCommitmentPrefix returns the prefix of the commitment proof.
1522
*/

0 commit comments

Comments
 (0)