Skip to content

Commit 4b4f8a0

Browse files
authored
Merge pull request #23 from statechannels/geoknee-patch-1
Update README.md
2 parents 29a6bf9 + a979e05 commit 4b4f8a0

File tree

1 file changed

+80
-4
lines changed

1 file changed

+80
-4
lines changed

README.md

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,84 @@
44

55
**Standard Exit Format for L2s built on EVM chains**
66

7-
An exit format allows calldata to specify how assets locked up and redistributed in an L2 should be paid out in L1. We present a general standard for such a format, along with coders written in Typescript and Cairo, which will aid L2 interoperability and support arbitrary tokens
7+
We present a general standard for such a format, along with coders written in Typescript, which will aid L2 interoperability and support arbitrary tokens.
88

9-
Ethereum is a multi-asset blockchain.
10-
Many applications require multiple assets to be frozen and liquidated in a smart contract, possibly atomically.
11-
Having a standard for this will make interoperability much easier. In the statechannels.org project, we have an existing format for exits (which is currently called an 'outcome'), expressed both in solidity and typescript. As well as coders, we require functions that transform the exit according to set rules: for example to execute a part of the exit, paying out one party and generating a new exit with that party removed. We will explore the use of zero knowledge methods to update exits stored on chain more efficiently. We will improve and generalize our existing format in order to save gas, reduce complexity and handle custom exit logic. We will present a standard exit format which other state channel and rollup protocols can conform with.
9+
The idea behind this library is to standardise the data structures used in exiting a layer 2 system: whether that is a [Connext](https://connext.network/) state channel or a rollup such as [Arbitrum](https://offchainlabs.com/) or [Optimism](https://optimism.io/). An exit format allows one to specify how assets locked up and redistributed in an L2 should be paid out in L1. Our hope is that as many layer 2 projects as possible can contribute to this repo and consider adopting the format in their system. If that happens, it should enable greater interoperability between these layer 2s, which otherwise are a little bit silo-ed.
10+
11+
We have concentrated so far on a format that works for [Nitro state channels](https://medium.com/magmo/nitro-protocol-c49b50f59df7). While working on the hack we realised that the new format actually enables us to streamline our virtual channel construction: leading to much greater simplicity and lowering the gas costs for channel disputes. The nitro specific code can be found in `/nitro-src` and is not currently exported from the npm package.
12+
13+
As another bonus, we have also built the beginnings of a zero-knowledge proof mechanism, which will allow Nitro state channels to scale even farther beyond their current limit and bring gas costs down even further. This work-in-progress currently takes the form of some [Cairo](https://www.cairo-lang.org/) code in the `/cairo` directory, and is alo not currently exported from the npm package. There's another readme in that folder that explains more.
14+
15+
**How to install this package**
16+
```shell
17+
yarn add @statechannels/exit-format
18+
```
19+
20+
**Example usage**
21+
22+
```solidity
23+
// SPDX-License-Identifier: MIT
24+
pragma solidity 0.8.4;
25+
26+
import "@statechannels/exit-format/contracts/ExitFormat.sol";
27+
28+
contract MyLayer2 {
29+
bytes32 exitHash;
30+
31+
function storeExitHash(ExitFormat.SingleAssetExit[] memory exit) public {
32+
if (msg.sender == 0x0737369d5F8525D039038Da1EdBAC4C4f161b949) {
33+
exitHash = keccak256(ExitFormat.encodeExit(exit));
34+
}
35+
}
36+
37+
function payout(ExitFormat.SingleAssetExit[] memory exit) public {
38+
if (keccak256(ExitFormat.encodeExit(exit)) == exitHash) {
39+
ExitFormat.executeExit(exit);
40+
}
41+
}
42+
}
43+
```
44+
45+
```typescript
46+
import { Exit, SingleAssetExit } from "@statechannels/exit-format";
47+
48+
const ethExit: SingleAssetExit = {
49+
asset: "0x0000000000000000000000000000000000000000", // this implies an ETH token
50+
data: "0x",
51+
allocations: [
52+
{
53+
destination: "0x96f7123E3A80C9813eF50213ADEd0e4511CB820f", // Alice
54+
amount: "0x05",
55+
callTo: "0x0000000000000000000000000000000000000000", // a regular ETH transfer
56+
data: "0x",
57+
},
58+
{
59+
destination: "0x0737369d5F8525D039038Da1EdBAC4C4f161b949", // Bob
60+
amount: "0x05",
61+
callTo: "0x96f7123E3A80C9813eF50213ADEd0e4511CB820f", // this implies "call a WithdrawHelper"
62+
data: "0x0123", /// ... with this calldata
63+
},
64+
],
65+
};
66+
67+
const daiExit: SingleAssetExit = {
68+
asset: "0x6b175474e89094c44da98b954eedeac495271d0f ", // this implies DAI (an ERC20 token)
69+
data: "0x",
70+
allocations: [
71+
{
72+
destination: "0x96f7123E3A80C9813eF50213ADEd0e4511CB820f", // Alice
73+
amount: "0x05",
74+
callTo: "0x0000000000000000000000000000000000000000", // a regular ERC20.transfer
75+
data: "0x",
76+
},
77+
{
78+
destination: "0x96f7123E3A80C9813eF50213ADEd0e4511CB820f", // Bob
79+
amount: "0x05",
80+
callTo: "0x0000000000000000000000000000000000000000", // a regular ERC20.transfer
81+
data: "0x",
82+
},
83+
],
84+
};
85+
86+
const exit: Exit = [ethExit, daiExit];
87+
```

0 commit comments

Comments
 (0)