Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ICS 2, 3, 7 for hybrid delay period #552

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions spec/client/ics-007-tendermint-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function checkValidityAndUpdateState(
consensusState = ConsensusState{header.timestamp, header.validatorSet, header.commitmentRoot}
set("clients/{identifier}/consensusStates/{header.height}", consensusState)
set("clients/{identifier}/processedTimes/{header.height}", currentTimestamp())
set("clients/{identifier}/processedHeights/{header.height}", currentHeight())
// save the client
set("clients/{identifier}", clientState)
}
Expand Down Expand Up @@ -348,7 +349,8 @@ function verifyChannelState(
function verifyPacketData(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -362,8 +364,12 @@ function verifyPacketData(
assert(clientState.frozenHeight === null || clientState.frozenHeight > height)
// fetch the processed time
processedTime = get("clients/{identifier}/processedTimes/{height}")
// fetch the processed height
processedHeight = get("clients/{identifier}/processedHeights/{height}")
// assert that enough time has elapsed
assert(currentTimestamp() >= processedTime + delayPeriod)
assert(currentTimestamp() >= processedTime + delayPeriodTime)
// assert that enough blocks have elapsed
assert(currentHeight() >= processedHeight + delayPeriodBlocks)
// fetch the previously verified commitment root & verify membership
root = get("clients/{identifier}/consensusStates/{height}")
// verify that the provided commitment has been stored
Expand All @@ -373,7 +379,8 @@ function verifyPacketData(
function verifyPacketAcknowledgement(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -387,8 +394,12 @@ function verifyPacketAcknowledgement(
assert(clientState.frozenHeight === null || clientState.frozenHeight > height)
// fetch the processed time
processedTime = get("clients/{identifier}/processedTimes/{height}")
// fetch the processed height
processedHeight = get("clients/{identifier}/processedHeights/{height}")
// assert that enough time has elapsed
assert(currentTimestamp() >= processedTime + delayPeriod)
assert(currentTimestamp() >= processedTime + delayPeriodTime)
// assert that enough blocks have elapsed
assert(currentHeight() >= processedHeight + delayPeriodBlocks)
// fetch the previously verified commitment root & verify membership
root = get("clients/{identifier}/consensusStates/{height}")
// verify that the provided acknowledgement has been stored
Expand All @@ -398,7 +409,8 @@ function verifyPacketAcknowledgement(
function verifyPacketReceiptAbsence(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -411,8 +423,12 @@ function verifyPacketReceiptAbsence(
assert(clientState.frozenHeight === null || clientState.frozenHeight > height)
// fetch the processed time
processedTime = get("clients/{identifier}/processedTimes/{height}")
// fetch the processed height
processedHeight = get("clients/{identifier}/processedHeights/{height}")
// assert that enough time has elapsed
assert(currentTimestamp() >= processedTime + delayPeriod)
assert(currentTimestamp() >= processedTime + delayPeriodTime)
// assert that enough blocks have elapsed
assert(currentHeight() >= processedHeight + delayPeriodBlocks)
// fetch the previously verified commitment root & verify membership
root = get("clients/{identifier}/consensusStates/{height}")
// verify that no acknowledgement has been stored
Expand All @@ -422,7 +438,8 @@ function verifyPacketReceiptAbsence(
function verifyNextSequenceRecv(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -435,8 +452,12 @@ function verifyNextSequenceRecv(
assert(clientState.frozenHeight === null || clientState.frozenHeight > height)
// fetch the processed time
processedTime = get("clients/{identifier}/processedTimes/{height}")
// fetch the processed height
processedHeight = get("clients/{identifier}/processedHeights/{height}")
// assert that enough time has elapsed
assert(currentTimestamp() >= processedTime + delayPeriod)
assert(currentTimestamp() >= processedTime + delayPeriodTime)
// assert that enough blocks have elapsed
assert(currentHeight() >= processedHeight + delayPeriodBlocks)
// fetch the previously verified commitment root & verify membership
root = get("clients/{identifier}/consensusStates/{height}")
// verify that the nextSequenceRecv is as claimed
Expand Down
27 changes: 18 additions & 9 deletions spec/core/ics-002-client-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ at a particular finalised height (necessarily associated with a particular commi
Client types must define functions to authenticate internal state of the state machine which the client tracks.
Internal implementation details may differ (for example, a loopback client could simply read directly from the state and require no proofs).

- The `delayPeriod` is passed to packet-related verification functions in order to allow packets to specify a period which must pass after a header is verified before the packet is allowed to be processed.
- The `delayPeriodTime` is passed to packet-related verification functions in order to allow packets to specify a period of time which must pass after a header is verified before the packet is allowed to be processed.
- The `delayPeriodBlocks` is passed to packet-related verification functions in order to allow packets to specify a period of blocks which must pass after a header is verified before the packet is allowed to be processed.

##### Required functions

Expand Down Expand Up @@ -368,7 +369,8 @@ type verifyChannelState = (
type verifyPacketData = (
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -384,7 +386,8 @@ type verifyPacketData = (
type verifyPacketAcknowledgement = (
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -400,7 +403,8 @@ type verifyPacketAcknowledgement = (
type verifyPacketReceiptAbsence = (
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -415,7 +419,8 @@ type verifyPacketReceiptAbsence = (
type verifyNextSequenceRecv = (
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand Down Expand Up @@ -776,7 +781,8 @@ function verifyChannelState(
function verifyPacketData(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -791,7 +797,8 @@ function verifyPacketData(
function verifyPacketAcknowledgement(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand All @@ -807,7 +814,8 @@ function verifyPacketReceiptAbsence(
clientState: ClientState,
height: Height,
prefix: CommitmentPrefix,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
proof: CommitmentProof,
portIdentifier: Identifier,
channelIdentifier: Identifier,
Expand All @@ -820,7 +828,8 @@ function verifyPacketReceiptAbsence(
function verifyNextSequenceRecv(
clientState: ClientState,
height: Height,
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
prefix: CommitmentPrefix,
proof: CommitmentProof,
portIdentifier: Identifier,
Expand Down
33 changes: 19 additions & 14 deletions spec/core/ics-003-connection-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ interface ConnectionEnd {
clientIdentifier: Identifier
counterpartyClientIdentifier: Identifier
version: string | []string
delayPeriod: uint64
delayPeriodTime: uint64
delayPeriodBlocks: uint64
}
```

Expand All @@ -95,7 +96,8 @@ interface ConnectionEnd {
- The `counterpartyClientIdentifier` field identifies the client on the counterparty chain associated with this connection.
- The `version` field is an opaque string which can be utilised to determine encodings or protocols for channels or packets utilising this connection.
If not specified, a default `version` of `""` should be used.
- The `delayPeriod` indicates a period that must elapse after validation of a header before a packet, acknowledgement, proof of receipt, or timeout can be processed.
- The `delayPeriodTime` indicates a period in time that must elapse after validation of a header before a packet, acknowledgement, proof of receipt, or timeout can be processed.
- The `delayPeriodBlocks` indicates a period in blocks that must elapse after validation of a header before a packet, acknowledgement, proof of receipt, or timeout can be processed.

### Store paths

Expand Down Expand Up @@ -175,7 +177,7 @@ function verifyPacketData(
sequence: Height,
data: bytes) {
client = queryClient(connection.clientIdentifier)
return client.verifyPacketData(connection, height, connection.delayPeriod, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, data)
return client.verifyPacketData(connection, height, connection.delayPeriodTime, connection.delayPeriodBlocks, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, data)
}

function verifyPacketAcknowledgement(
Expand All @@ -187,7 +189,7 @@ function verifyPacketAcknowledgement(
sequence: uint64,
acknowledgement: bytes) {
client = queryClient(connection.clientIdentifier)
return client.verifyPacketAcknowledgement(connection, height, connection.delayPeriod, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, acknowledgement)
return client.verifyPacketAcknowledgement(connection, height, connection.delayPeriodTime, connection.delayPeriodBlocks, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, acknowledgement)
}

function verifyPacketReceiptAbsence(
Expand All @@ -198,7 +200,7 @@ function verifyPacketReceiptAbsence(
channelIdentifier: Identifier,
sequence: uint64) {
client = queryClient(connection.clientIdentifier)
return client.verifyPacketReceiptAbsence(connection, height, connection.delayPeriod, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier)
return client.verifyPacketReceiptAbsence(connection, height, connection.delayPeriodTime, connection.delayPeriodBlocks, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier)
}

function verifyNextSequenceRecv(
Expand All @@ -209,7 +211,7 @@ function verifyNextSequenceRecv(
channelIdentifier: Identifier,
nextSequenceRecv: uint64) {
client = queryClient(connection.clientIdentifier)
return client.verifyNextSequenceRecv(connection, height, connection.delayPeriod, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, nextSequenceRecv)
return client.verifyNextSequenceRecv(connection, height, connection.delayPeriodTime, connection.delayPeriodBlocks, connection.counterpartyPrefix, proof, portIdentifier, channelIdentifier, nextSequenceRecv)
}

function getTimestampAtHeight(
Expand Down Expand Up @@ -299,7 +301,8 @@ function connOpenInit(
clientIdentifier: Identifier,
counterpartyClientIdentifier: Identifier,
version: string,
delayPeriod: uint64) {
delayPeriodTime: uint64,
delayPeriodBlocks: uint64) {
identifier = generateIdentifier()
abortTransactionUnless(provableStore.get(connectionPath(identifier)) == null)
state = INIT
Expand All @@ -311,7 +314,7 @@ function connOpenInit(
versions = getCompatibleVersions()
}
connection = ConnectionEnd{state, "", counterpartyPrefix,
clientIdentifier, counterpartyClientIdentifier, versions, delayPeriod}
clientIdentifier, counterpartyClientIdentifier, versions, delayPeriodTime, delayPeriodBlocks}
provableStore.set(connectionPath(identifier), connection)
addConnectionToClient(clientIdentifier, identifier)
}
Expand All @@ -327,7 +330,8 @@ function connOpenTry(
counterpartyClientIdentifier: Identifier,
clientIdentifier: Identifier,
counterpartyVersions: string[],
delayPeriod: uint64,
delayPeriodTime: uint64,
delayPeriodBlocks: uint64,
proofInit: CommitmentProof,
proofConsensus: CommitmentProof,
proofHeight: Height,
Expand All @@ -341,7 +345,8 @@ function connOpenTry(
previous.counterpartyPrefix === counterpartyPrefix &&
previous.clientIdentifier === clientIdentifier &&
previous.counterpartyClientIdentifier === counterpartyClientIdentifier &&
previous.delayPeriod === delayPeriod))
previous.delayPeriodTime === delayPeriodTime
previous.delayPeriodBlocks === delayPeriodBlocks))
identifier = previousIdentifier
} else {
// generate a new identifier if the passed identifier was the sentinel empty-string
Expand All @@ -350,11 +355,11 @@ function connOpenTry(
abortTransactionUnless(consensusHeight < getCurrentHeight())
expectedConsensusState = getConsensusState(consensusHeight)
expected = ConnectionEnd{INIT, "", getCommitmentPrefix(), counterpartyClientIdentifier,
clientIdentifier, counterpartyVersions, delayPeriod}
clientIdentifier, counterpartyVersions, delayPeriodTime, delayPeriodBlocks}
versionsIntersection = intersection(counterpartyVersions, previous !== null ? previous.version : getCompatibleVersions())
version = pickVersion(versionsIntersection) // throws if there is no intersection
connection = ConnectionEnd{TRYOPEN, counterpartyConnectionIdentifier, counterpartyPrefix,
clientIdentifier, counterpartyClientIdentifier, version, delayPeriod}
clientIdentifier, counterpartyClientIdentifier, version, delayPeriodTime, delayPeriodBlocks}
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofInit, counterpartyConnectionIdentifier, expected))
abortTransactionUnless(connection.verifyClientConsensusState(
proofHeight, proofConsensus, counterpartyClientIdentifier, consensusHeight, expectedConsensusState))
Expand Down Expand Up @@ -382,7 +387,7 @@ function connOpenAck(
expectedConsensusState = getConsensusState(consensusHeight)
expected = ConnectionEnd{TRYOPEN, identifier, getCommitmentPrefix(),
connection.counterpartyClientIdentifier, connection.clientIdentifier,
version, connection.delayPeriod}
version, connection.delayPeriodTime, connection.delayPeriodBlocks}
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofTry, counterpartyIdentifier, expected))
abortTransactionUnless(connection.verifyClientConsensusState(
proofHeight, proofConsensus, connection.counterpartyClientIdentifier, consensusHeight, expectedConsensusState))
Expand All @@ -403,7 +408,7 @@ function connOpenConfirm(
connection = provableStore.get(connectionPath(identifier))
abortTransactionUnless(connection.state === TRYOPEN)
expected = ConnectionEnd{OPEN, identifier, getCommitmentPrefix(), connection.counterpartyClientIdentifier,
connection.clientIdentifier, connection.version, connection.delayPeriod}
connection.clientIdentifier, connection.version, connection.delayPeriodTime, connection.delayPeriodBlocks}
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofAck, connection.counterpartyConnectionIdentifier, expected))
connection.state = OPEN
provableStore.set(connectionPath(identifier), connection)
Expand Down