Skip to content

Commit

Permalink
Merge PR cosmos#105: Compile Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Jun 29, 2019
1 parent 6f138ea commit 07009cc
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
<<: *linux_defaults
steps:
- checkout
- run: sudo make setup_dependencies check_dependencies
- run: sudo pip install matplotlib networkx
- run: make check_dependencies

check_links:
<<: *linux_defaults
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ $(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)

setup_dependencies:
pip install matplotlib networkx

check: check_links check_dependencies check_syntax check_sections

check_links:
Expand All @@ -17,9 +14,9 @@ check_dependencies:
python ./scripts/check_dependencies.py

check_syntax:
bash ./scripts/check_syntax.sh
python ./scripts/check_syntax.py

check_sections:
python ./scripts/check_sections.py

.PHONY: $(TOPTARGETS) $(SUBDIRS) setup_dependencies check check_links check_dependencies check_syntax check_sections
.PHONY: $(TOPTARGETS) $(SUBDIRS) check check_links check_dependencies check_syntax check_sections
4 changes: 2 additions & 2 deletions deps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions scripts/check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
else:
print('Found cycles!')
print(cycles)
sys.exit(1)

print('Drawing dependency graph...')

Expand Down
49 changes: 49 additions & 0 deletions scripts/check_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python

import re, os, sys, subprocess, glob

specs = [f.path for f in os.scandir('./spec') if f.is_dir()]
files = [f.path for spec in specs for f in os.scandir(spec) if f.is_file() and f.path[-3:] == '.md']

requires_regex = re.compile('requires: (.*)\n')

def temp_filename():
return subprocess.check_output(['mktemp'])[:-1] + bytes('.ts', 'utf-8')

def extract_typescript(spec):
temp = temp_filename()
subprocess.check_output(['/bin/bash', '-c', b'cat ' + bytes(spec, 'utf-8') + b' | codedown typescript > ' + temp])
return temp

for fn in files:
print('Checking syntax in {}'.format(fn))
temp = extract_typescript(fn)

print('Running tslint...')
output = subprocess.check_output(['tslint', '-c', './scripts/tslint.json', temp])
if output != b'':
sys.exit(1)

print('Reading dependencies of {}'.format(fn))
data = open(fn).read()
requires = [int(num) for line in requires_regex.findall(data) for num in line.split(', ')]

print('Dependencies: {}'.format(requires))
final = temp_filename()

for dep in requires:
spec = glob.glob('./spec/ics-' + str(dep).zfill(3) + '-*')[0] + '/README.md'
newTemp = extract_typescript(spec)
print('Concatenating dependency on ICS {}'.format(dep))
subprocess.check_call(['/bin/bash', '-c', b'cat ' + newTemp + b' >> ' + final])
subprocess.check_call(['/bin/bash', '-c', b'echo -e "\n" >> ' + final])

subprocess.check_call(['/bin/bash', '-c', b'cat ' + temp + b' >> ' + final])

res = subprocess.run(['tsc', '--lib', 'es6', '--downlevelIteration', final])

if res.returncode != 0:
print(res)
# sys.exit(1)

subprocess.check_call(['rm', temp])
14 changes: 0 additions & 14 deletions scripts/check_syntax.sh

This file was deleted.

2 changes: 1 addition & 1 deletion spec/ics-002-consensus-verification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Consensus Verification
stage: draft
category: ibc-core
requires: 23, 24
required-by: 3, 24
required-by: 3
author: Juwoon Yun <joon@tendermint.com>, Christopher Goes <cwgoes@tendermint.com>
created: 2019-02-25
modified: 2019-05-28
Expand Down
4 changes: 2 additions & 2 deletions spec/ics-018-relayer-algorithms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function relay(C: Set<Chain>) {
for (const chain of C)
for (const counterparty of C)
if (counterparty !== chain) {
const datagrams = pendingDatagrams(chain, counterparty)
const datagrams = chain.pendingDatagrams(counterparty)
for (const datagram of datagrams)
submitDatagram(counterparty, datagram)
counterparty.submitDatagram(datagram)
}
}
```
Expand Down
35 changes: 25 additions & 10 deletions spec/ics-023-vector-commitments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ type CommitmentProof = object
### Required functions
An commitment construction MUST provide the following functions:
An commitment construction MUST provide the following functions, defined over keys and values as byte arrays:
```typescript
type Key = string

type Value = string
```
#### Initialization
Expand Down Expand Up @@ -120,13 +126,13 @@ type createNonMembershipProof = (state: CommitmentState, key: Key) => Commitment
The `verifyMembership` function verifies a proof that a key has been set to a particular value in an commitment.
```typescript
type verifyMembership = (root: CommitmentRoot, proof: CommitmentProof, key: Key, value: Value) => bool
type verifyMembership = (root: CommitmentRoot, proof: CommitmentProof, key: Key, value: Value) => boolean
```
The `verifyNonMembership` function verifies a proof that a key has not been set to any value in an commitment.
```typescript
type verifyNonMembership = (root: CommitmentRoot, proof: CommitmentProof, key: Key) => bool
type verifyNonMembership = (root: CommitmentRoot, proof: CommitmentProof, key: Key) => boolean
```
### Optional functions
Expand All @@ -136,25 +142,25 @@ An commitment construction MAY provide the following functions:
The `batchVerifyMembership` function verifies a proof that many keys have been set to specific values in an commitment.
```typescript
type batchVerifyMembership = (root: CommitmentRoot, proof: CommitmentProof, items: Map<Key, Value>) => bool
type batchVerifyMembership = (root: CommitmentRoot, proof: CommitmentProof, items: Map<Key, Value>) => boolean
```
The `batchVerifyNonMembership` function verifies a proof that many keys have not been set to any value in an commitment.
```typescript
type batchVerifyNonMembership = (root: CommitmentRoot, proof: CommitmentProof, keys: Set<Key>) => bool
type batchVerifyNonMembership = (root: CommitmentRoot, proof: CommitmentProof, keys: Set<Key>) => boolean
```
If defined, these functions MUST be computationally equivalent to the conjunctive union of `verifyMembership` and `verifyNonMembership` respectively (`proof` may vary):
```typescript
batchVerifyMembership(root, proof, items) ===
all(verifyMembership(root, proof, item) for item in items)
all(items.map((item) => verifyMembership(root, proof, item)))
```
```typescript
batchVerifyNonMembership(root, proof, keys) ===
all(verifyNonMembership(root, proof, key) for key in keys)
all(items.map((item) => verifyNonMembership(root, proof, key)))
```
If batch verification is possible and more efficient than individual verification of one proof per element, an commitment construction SHOULD define batch verification functions.
Expand All @@ -172,6 +178,9 @@ For any key `key` last set to a value `value` in the commitment `acc`,
```typescript
root = getRoot(acc)
proof = createMembershipProof(acc, key, value)
```
```
Pr(verifyMembership(root, proof, key, value) === false) negligible in λ
```
Expand All @@ -180,6 +189,9 @@ For any key `key` not set in the commitment `acc`, for all values of `proof` and
```typescript
root = getRoot(acc)
proof = createNonMembershipProof(acc, key)
```
```
Pr(verifyNonMembership(root, proof, key) === false) negligible in λ
```
Expand All @@ -189,13 +201,13 @@ Commitment proofs MUST be *sound*: key => value mappings which have not been add
For any key `key` last set to a value `value` in the commitment `acc`, for all values of `proof`,
```typescript
```
Pr(verifyNonMembership(root, proof, key) === true) negligible in λ
```
For any key `key` not set in the commitment `acc`, for all values of `proof` and all values of `value`,
```typescript
```
Pr(verifyMembership(root, proof, key, value) === true) negligible in λ
```
Expand All @@ -208,12 +220,15 @@ For any key `key` set in the commitment `acc`, there is one `value` for which:
```typescript
root = getRoot(acc)
proof = createMembershipProof(acc, key, value)
```
```
Pr(verifyMembership(root, proof, key, value) === false) negligible in λ
```
For all other values `otherValue` where `value /= otherValue`, for all values of `proof`,
```typescript
```
Pr(verifyMembership(root, proof, key, otherValue) === true) negligible in λ
```
Expand Down
31 changes: 25 additions & 6 deletions spec/ics-024-host-requirements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ics: 24
title: Host State Machine Requirements
stage: draft
category: ibc-core
requires: 2
required-by: 2, 3, 4, 18
author: Christopher Goes <cwgoes@tendermint.com>
created: 2019-04-16
Expand All @@ -20,8 +19,6 @@ IBC is designed to be a common standard which will be hosted by a variety of blo

### Definitions

`ConsensusState` is as defined in [ICS 2](../ics-002-consensus-verification).

### Desired Properties

IBC should require as simple an interface from the underlying state machine as possible to maximize the ease of correct implementation.
Expand Down Expand Up @@ -59,7 +56,7 @@ type set = (key: Key, value: Value) => void
```
```typescript
type delete = (key: Key) => void
type del = (key: Key) => void
```
`Key` is as defined above. `Value` is an arbitrary bytestring encoding of a particular data structure. Encoding details are left to separate ICSs.
Expand All @@ -68,6 +65,12 @@ These functions MUST be permissioned to the IBC handler module (the implementati
### Consensus State Introspection
Host chains MUST define a unique `ConsensusState` type fulfilling the requirements of [ICS 2](../ics-002-consensus-verification):
```typescript
type ConsensusState object
```

Host chains MUST provide the ability to introspect their own consensus state, with `getConsensusState`:

```typescript
Expand All @@ -92,14 +95,30 @@ Modules which wish to make use of particular IBC features MAY implement certain

### Datagram submission

Host chains MAY define a unique `submitDatagram` function to submit [datagrams](../../docs/ibc/2_IBC_TERMINOLOGY.md) directly:
Host chains MAY define a unique `Datagram` type & `submitDatagram` function to submit [datagrams](../../docs/ibc/2_IBC_TERMINOLOGY.md) directly to the relayer module:

```typescript
type submitDatagram = (datagram: Datagram) => void
type Datagram object
// fields defined per datagram type, and possible additional fields defined per chain
type SubmitDatagram = (datagram: Datagram) => void
```

`submitDatagram` allows relayers to relay IBC datagrams directly to the host chain. Host chains MAY require that the relayer submitting the datagram has an account to pay transaction fees, signs over the datagram in a larger transaction structure, etc - `submitDatagram` MUST define any such packaging required.

Host chains MAY also define a `pendingDatagrams` function to scan the pending datagrams to be sent to another counterparty chain:

```typescript
type PendingDatagrams = (counterparty: Chain) => Set<Datagram>
```

```typescript
interface Chain {
submitDatagram: SubmitDatagram
pendingDatagrams: PendingDatagrams
}
```

### Data availability

For safety (e.g. exactly-once packet delivery), host chains MUST have eventual data availability, such that any key-value pairs in state can be eventually retrieved by relayers.
Expand Down

0 comments on commit 07009cc

Please sign in to comment.