@@ -151,19 +151,19 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
151
151
/// @param proofHeight The height of the proof.
152
152
/// @param path The path of the key-value pair.
153
153
/// @param value The value of the key-value pair.
154
- /// @return timestamp The timestamp of the trusted consensus state.
154
+ /// @return The timestamp of the trusted consensus state in unix seconds .
155
155
function _membership (
156
156
bytes calldata proof ,
157
157
IICS02ClientMsgs.Height calldata proofHeight ,
158
158
bytes [] calldata path ,
159
159
bytes memory value
160
160
)
161
161
private
162
- returns (uint256 timestamp )
162
+ returns (uint256 )
163
163
{
164
164
if (proof.length == 0 ) {
165
165
// cached proof
166
- return _getCachedKvPair (proofHeight.revisionHeight, IMembershipMsgs.KVPair (path, value));
166
+ return _nanosToSeconds ( _getCachedKvPair (proofHeight.revisionHeight, IMembershipMsgs.KVPair (path, value) ));
167
167
}
168
168
169
169
IMembershipMsgs.MembershipProof memory membershipProof = abi.decode (proof, (IMembershipMsgs.MembershipProof));
@@ -261,7 +261,7 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
261
261
if (output.kvPairs.length > 1 ) {
262
262
_cacheKvPairs (proofHeight.revisionHeight, output.kvPairs, proof.trustedConsensusState.timestamp);
263
263
}
264
- return proof.trustedConsensusState.timestamp ;
264
+ return _getTimestampInSeconds ( proof.trustedConsensusState) ;
265
265
}
266
266
267
267
/// @notice The entrypoint for handling the `SP1MembershipAndUpdateClientProof` proof type.
@@ -360,7 +360,7 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
360
360
proofHeight.revisionHeight, output.kvPairs, output.updateClientOutput.newConsensusState.timestamp
361
361
);
362
362
}
363
- return output.updateClientOutput.newConsensusState.timestamp ;
363
+ return _getTimestampInSeconds ( output.updateClientOutput.newConsensusState) ;
364
364
}
365
365
366
366
/// @notice Validates the MembershipOutput public values.
@@ -428,16 +428,19 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
428
428
/// @notice Validates the client state and time.
429
429
/// @dev This function does not check the equality of the latest height and isFrozen.
430
430
/// @param publicClientState The public client state.
431
- /// @param time The time.
431
+ /// @param time The time in unix nanoseconds .
432
432
function _validateClientStateAndTime (
433
433
IICS07TendermintMsgs.ClientState memory publicClientState ,
434
- uint64 time
434
+ uint128 time
435
435
)
436
436
private
437
437
view
438
438
{
439
- require (time <= block .timestamp , ProofIsInTheFuture (block .timestamp , time));
440
- require (block .timestamp - time <= ALLOWED_SP1_CLOCK_DRIFT, ProofIsTooOld (block .timestamp , time));
439
+ require (_nanosToSeconds (time) <= block .timestamp , ProofIsInTheFuture (block .timestamp , _nanosToSeconds (time)));
440
+ require (
441
+ block .timestamp - _nanosToSeconds (time) <= ALLOWED_SP1_CLOCK_DRIFT,
442
+ ProofIsTooOld (block .timestamp , _nanosToSeconds (time))
443
+ );
441
444
442
445
// Check client state equality
443
446
// NOTE: We do not check the equality of latest height and isFrozen, this is because:
@@ -508,7 +511,7 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
508
511
/// @notice Caches the key-value pairs to the transient storage with the timestamp.
509
512
/// @param proofHeight The height of the proof.
510
513
/// @param kvPairs The key-value pairs.
511
- /// @param timestamp The timestamp of the trusted consensus state.
514
+ /// @param timestamp The timestamp of the trusted consensus state in unix nanoseconds .
512
515
/// @dev WARNING: Transient store is not reverted even if a message within a transaction reverts.
513
516
/// @dev WARNING: This function must be called after all proof and validation checks.
514
517
function _cacheKvPairs (uint64 proofHeight , IMembershipMsgs.KVPair[] memory kvPairs , uint256 timestamp ) private {
@@ -521,7 +524,7 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
521
524
/// @notice Gets the timestamp of the cached key-value pair from the transient storage.
522
525
/// @param proofHeight The height of the proof.
523
526
/// @param kvPair The key-value pair.
524
- /// @return The timestamp of the cached key-value pair.
527
+ /// @return The timestamp of the cached key-value pair in unix nanoseconds .
525
528
function _getCachedKvPair (
526
529
uint64 proofHeight ,
527
530
IMembershipMsgs.KVPair memory kvPair
@@ -536,6 +539,24 @@ contract SP1ICS07Tendermint is ISP1ICS07TendermintErrors, ISP1ICS07Tendermint, I
536
539
return timestamp;
537
540
}
538
541
542
+ /// @notice Returns the timestamp of the trusted consensus state in unix seconds.
543
+ /// @param consensusState The consensus state.
544
+ /// @return The timestamp of the trusted consensus state in unix seconds.
545
+ function _getTimestampInSeconds (IICS07TendermintMsgs.ConsensusState memory consensusState )
546
+ private
547
+ pure
548
+ returns (uint256 )
549
+ {
550
+ return _nanosToSeconds (consensusState.timestamp);
551
+ }
552
+
553
+ /// @notice Converts nanoseconds to seconds.
554
+ /// @param nanos The nanoseconds.
555
+ /// @return The seconds.
556
+ function _nanosToSeconds (uint256 nanos ) private pure returns (uint256 ) {
557
+ return nanos / 1e9 ;
558
+ }
559
+
539
560
/// @notice Modifier to check if the client is not frozen.
540
561
modifier notFrozen () {
541
562
require (! clientState.isFrozen, FrozenClientState ());
0 commit comments