forked from hyperledger-labs/yui-ibc-solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ILightClient.sol
117 lines (105 loc) · 4.47 KB
/
ILightClient.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
import "../../proto/Client.sol";
/**
* @dev This defines an interface for Light Client contract can be integrated with ibc-solidity.
* You can register the Light Client contract that implements this through `registerClient` on IBCHandler.
*/
interface ILightClient {
/**
* @dev createClient creates a new client with the given state.
* If succeeded, it returns a commitment for the initial state.
*/
function createClient(string calldata clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes)
external
returns (bytes32 clientStateCommitment, ConsensusStateUpdate memory update, bool ok);
/**
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
* The timestamp is nanoseconds since unix epoch.
*/
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
external
view
returns (uint64, bool);
/**
* @dev getLatestHeight returns the latest height of the client state corresponding to `clientId`.
*/
function getLatestHeight(string calldata clientId) external view returns (Height.Data memory, bool);
/**
* @dev getStatus returns the status of the client corresponding to `clientId`.
*/
function getStatus(string calldata clientId) external view returns (ClientStatus);
/**
* @dev updateClient updates the client corresponding to `clientId`.
* If succeeded, it returns a commitment for the updated state.
* If there is no update for client state, this function should returns bytes32(0) as `clientStateCommitment`
* If there are no updates for consensus state, this function should returns an empty array as `updates`.
*
* NOTE: updateClient is intended to perform the followings:
* 1. verify a given client message(e.g. header)
* 2. check misbehaviour such like duplicate block height
* 3. if misbehaviour is found, update state accordingly and return
* 4. update state(s) with the client message
* 5. persist the state(s) on the host
*/
function updateClient(string calldata clientId, bytes calldata clientMessageBytes)
external
returns (bytes32 clientStateCommitment, ConsensusStateUpdate[] memory updates, bool ok);
/**
* @dev verifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height.
* The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24).
*/
function verifyMembership(
string calldata clientId,
Height.Data calldata height,
uint64 delayTimePeriod,
uint64 delayBlockPeriod,
bytes calldata proof,
bytes calldata prefix,
bytes calldata path,
bytes calldata value
) external returns (bool);
/**
* @dev verifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height.
* The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24).
*/
function verifyNonMembership(
string calldata clientId,
Height.Data calldata height,
uint64 delayTimePeriod,
uint64 delayBlockPeriod,
bytes calldata proof,
bytes calldata prefix,
bytes calldata path
) external returns (bool);
/**
* @dev getClientState returns the clientState corresponding to `clientId`.
* If it's not found, the function returns false.
*/
function getClientState(string calldata clientId) external view returns (bytes memory, bool);
/**
* @dev getConsensusState returns the consensusState corresponding to `clientId` and `height`.
* If it's not found, the function returns false.
*/
function getConsensusState(string calldata clientId, Height.Data calldata height)
external
view
returns (bytes memory, bool);
}
/**
* @dev ConsensusStateUpdate represents a consensus state update.
*/
struct ConsensusStateUpdate {
// commitment for updated consensusState
bytes32 consensusStateCommitment;
// updated height
Height.Data height;
}
/**
* @dev ClientStatus represents the status of a client.
*/
enum ClientStatus {
Active,
Expired,
Frozen
}