Skip to content

Commit

Permalink
Merge PR #284: 1.0.0-rc5 work
Browse files Browse the repository at this point in the history
* Bump version in spec PDF
* Succinct is now 'O(poly(log n))'
* Start Go test shim
* Fix 'timeoutOnClose'
* Fix connection version negotiation
* Add file describing encoding
* Update proto3 files; rebuild
  • Loading branch information
cwgoes authored Oct 16, 2019
1 parent e992711 commit 4c1116a
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 186 deletions.
46 changes: 46 additions & 0 deletions compliance/shims/go/shim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

type Arg string

type Value string

type Test struct {
Name string `json:"name"`
Function string `json:"function"`
Args []Arg `json:"args"`
Result Value `json:"result"`
}

func run(t Test) error {
fmt.Printf("Ran test %s\n", t.Name)
return nil
}

func main() {
fh, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
bytes, err := ioutil.ReadAll(fh)
if err != nil {
panic(err)
}
var tests []Test
err = json.Unmarshal(bytes, &tests)
if err != nil {
panic(err)
}
for _, test := range tests {
err = run(test)
if err != nil {
panic(err)
}
}
}
2 changes: 1 addition & 1 deletion ibc/1_IBC_TERMINOLOGY.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ All equivocations are misbehaviours.

### Succinct

*Succinct*, when referring to space or time complexity, means `O(log n)` or better.
*Succinct*, when referring to space or time complexity, means `O(poly(log n))` or better.
27 changes: 27 additions & 0 deletions ibc/CANONICAL_ENCODING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This document defines a canonical encoding algorithm for data structures which must be encoded in a known fashion for cross-chain verification in the IBC protocol.

The encoding function maps a typed value into a byte array.

### Primitive types

If a value has a primitive type, it is encoded without tags.

#### Numbers

The protocol deals only with unsigned integers.

`uint32` and `uint64` types are encoded as fixed-size little-endian, with no sign bit.

#### Booleans

Boolean values are encoded as single bits: `0x00` (false) and `0x01` (true).

#### Bytes

Byte arrays are encoded as-is with no length prefix or tag.

### Structured types

Structured types with fields are encoded as proto3 `message`s with the appropriate fields.

Canonical `.proto` files are provided with the specification.
4 changes: 3 additions & 1 deletion misc/aspell_dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 453
personal_ws-1.1 en 455
unescrow
onChanCloseConfirm
clientKey
Expand Down Expand Up @@ -120,6 +120,7 @@ tokenize
interchain
Ethereum
PacketTimeout
endian
Zcash
subprotocol
verifyNonMembership
Expand Down Expand Up @@ -350,6 +351,7 @@ rootKey
Privkey
acknowledgePacket
interoperability
Booleans
Betazoid
callingModuleIdentifier
LogStore
Expand Down
6 changes: 5 additions & 1 deletion spec.pdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ toc-own-page: true
mainfont: DejaVuSerifCondensed
fontsize: 8pt
author: IBC Specification Team
date: \today \ — \textbf{1.0.0-rc4}
date: \today \ — \textbf{1.0.0-rc5}
urlcolor: cyan
header-includes:
- \usepackage{graphicx}
Expand Down Expand Up @@ -104,3 +104,7 @@ header-includes:
# Appendix B: Design Patterns

!include ibc/5_IBC_DESIGN_PATTERNS.md.xfm

# Appendix C: Canonical Encoding

!include ibc/CANONICAL_ENCODING.md.xfm
Binary file modified spec.pdf
Binary file not shown.
37 changes: 10 additions & 27 deletions spec/ics-003-connection-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,6 @@ function verifyNonMembership(
}
```


### Versioning

During the handshake process, two ends of a connection come to agreement on a version bytestring associated
with that connection. At the moment, the contents of this version bytestring are opaque to the IBC core protocol.
In the future, it might be used to indicate what kinds of channels can utilise the connection in question, or
what encoding formats channel-related datagrams will use. At present, host state machine MAY utilise the version data
to negotiate encodings, priorities, or connection-specific metadata related to custom logic on top of IBC.

Host state machines MAY also safely ignore the version data or specify an empty string.

`checkVersion` is an opaque function defined by the host state machine which determines if two versions are compatible, returning a boolean:

```typescript
function checkVersion(
version: string,
counterpartyVersion: string): boolean {
// defined by host state machine
}
```

Future versions of this specification may also define this function.

### Sub-protocols

This ICS defines the opening handshake subprotocol. Once opened, connections cannot be closed and identifiers cannot be reallocated (this prevents packet replay or authorisation confusion).
Expand All @@ -204,13 +181,21 @@ If not provided, the default `validateConnectionIdentifier` function will always
#### Versioning
An implementation must define a function `getCompatibleVersions` which returns the list of versions it supports, ranked by descending preference order.
During the handshake process, two ends of a connection come to agreement on a version bytestring associated
with that connection. At the moment, the contents of this version bytestring are opaque to the IBC core protocol.
In the future, it might be used to indicate what kinds of channels can utilise the connection in question, or
what encoding formats channel-related datagrams will use. At present, host state machine MAY utilise the version data
to negotiate encodings, priorities, or connection-specific metadata related to custom logic on top of IBC.
Host state machines MAY also safely ignore the version data or specify an empty string.
An implementation MUST define a function `getCompatibleVersions` which returns the list of versions it supports, ranked by descending preference order.
```typescript
type getCompatibleVersions = () => []string
```
An implementation must define a function `pickVersion` to choose a version from a list of versions proposed by a counterparty.
An implementation MUST define a function `pickVersion` to choose a version from a list of versions proposed by a counterparty.
```typescript
type pickVersion = ([]string) => string
Expand Down Expand Up @@ -288,7 +273,6 @@ function connOpenTry(
consensusStatePath(counterpartyClientIdentifier),
expectedConsensusState))
abortTransactionUnless(provableStore.get(connectionPath(desiredIdentifier)) === null)
abortTransactionUnless(checkVersion(version, counterpartyVersion))
identifier = desiredIdentifier
state = TRYOPEN
provableStore.set(connectionPath(identifier), connection)
Expand All @@ -308,7 +292,6 @@ function connOpenAck(
abortTransactionUnless(consensusHeight <= getCurrentHeight())
connection = provableStore.get(connectionPath(identifier))
abortTransactionUnless(connection.state === INIT)
abortTransactionUnless(checkVersion(connection.version, version))
expectedConsensusState = getConsensusState(consensusHeight)
expected = ConnectionEnd{TRYOPEN, identifier, getCommitmentPrefix(),
connection.counterpartyClientIdentifier, connection.clientIdentifier,
Expand Down
7 changes: 4 additions & 3 deletions spec/ics-003-connection-semantics/data-structures.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ enum ConnectionState {
message ConnectionEnd {
ConnectionState state = 1;
string counterpartyConnectionIdentifier = 2;
string clientIdentifier = 3;
string counterpartyClientIdentifier = 4;
uint64 nextTimeoutHeight = 5;
string counterpartyPrefix = 3;
string clientIdentifier = 4;
string counterpartyClientIdentifier = 5;
string version = 6;
}
30 changes: 20 additions & 10 deletions spec/ics-004-channel-and-packet-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This specification only concerns itself with *bidirectional* channels. *Unidirec
An end of a channel is a data structure on one chain storing channel metadata:

```typescript
interface Channel {
interface ChannelEnd {
state: ChannelState
ordering: ChannelOrder
counterpartyPortIdentifier: Identifier
Expand Down Expand Up @@ -96,7 +96,7 @@ enum ChannelState {
- A channel end in `OPEN` state has completed the handshake and is ready to send and receive packets.
- A channel end in `CLOSED` state has been closed and can no longer be used to send or receive packets.

A `Packet`, in the interblockchain communication protocol, is a particular data structure defined as follows:
A `Packet`, in the interblockchain communication protocol, is a particular interface defined as follows:

```typescript
interface Packet {
Expand Down Expand Up @@ -721,9 +721,10 @@ to which an unreceived packet was addressed has been closed, so the packet will
```typescript
function timeoutOnClose(
packet: Packet,
proofNonMembership: CommitmentProof,
proof: CommitmentProof,
proofClosed: CommitmentProof,
proofHeight: uint64) {
proofHeight: uint64,
nextSequenceRecv: Maybe<uint64>): Packet {

channel = provableStore.get(channelPath(packet.sourcePort, packet.sourceChannel))
// note: the channel may have been closed
Expand All @@ -748,12 +749,21 @@ function timeoutOnClose(
expected
))

// verify absence of acknowledgement at packet index
abortTransactionUnless(connection.verifyNonMembership(
proofHeight,
proofNonMembership,
packetAcknowledgementPath(packet.sourcePort, packet.sourceChannel, packet.sequence)
))
if channel.order === ORDERED
// ordered channel: check that the recv sequence is as claimed
abortTransactionUnless(connection.verifyMembership(
proofHeight,
proof,
nextSequenceRecvPath(packet.destPort, packet.destChannel),
nextSequenceRecv
))
else
// unordered channel: verify absence of acknowledgement at packet index
abortTransactionUnless(connection.verifyNonMembership(
proofHeight,
proof,
packetAcknowledgementPath(packet.sourcePort, packet.sourceChannel, packet.sequence)
))

// all assertions passed, we can alter state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ message ChannelEnd {
string counterpartyPortIdentifier = 3;
string counterpartyChannelIdentifier = 4;
repeated string connectionHops = 5;
uint64 nextTimeoutHeight = 6;
string version = 6;
}
3 changes: 2 additions & 1 deletion spec/ics-020-fungible-token-transfer/packets.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ syntax = 'proto3';

message FungibleTokenPacketData {
string denomination = 1;
uint64 amount = 2; // TODO
bytes amount = 2; // serialised uint256
string sender = 3;
string receiver = 4;
bool source = 5;
}
1 change: 0 additions & 1 deletion spec/ics-026-routing-module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ build:
clean:

check_proto:
/bin/bash -c 'TEMP=$$(mktemp); protoc datagrams.proto -o $$TEMP; rm -f $$TEMP'

.PHONY: typecheck build clean check_proto
Loading

0 comments on commit 4c1116a

Please sign in to comment.