Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
fix rollup-client
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Jun 9, 2020
1 parent f657f0b commit a6f9055
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 194 deletions.
79 changes: 45 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# zkRollup <img style="float: right;" src="https://i.imgur.com/dGCTo2B.png" width="100">
# zkRollup 2.0 <img style="float: right;" src="https://i.imgur.com/dGCTo2B.png" width="100">

## Table of Contents

Expand All @@ -15,7 +15,8 @@
2.8. [Initiliaze withdrawal off-chain](#2_8)<br>
2.9. [Find exit transaction](#2_9)<br>
2.10. [Complete withdrawal on-chain](#2_10)<br>
2.11. [Resources](#2_11)<br>
2.11. [Bonus: create rollup account with an off-chain transaction](#2_11)<br>
2.12. [Resources](#2_12)<br>

## 1. Description<a id="1"></a>
In a nutshell, zkRollup is a layer 2 construction  -- similar to Plasma  --  which uses the ethereum blockchain for data storage instead of computation.
Expand All @@ -35,8 +36,8 @@ For more on zkRollup checkout our docs [here](https://docs.iden3.io/#/rollup/rol
### Testnet details
We've currently deployed an operator and the relevant contracts to the Goerli Testnet:

1. **[Rollup.sol](https://github.com/iden3/rollup/blob/testnet/contracts/Rollup.sol)** manages the rollup itself: https://goerli.etherscan.io/address/0xE0C17C3a4f06b859124Df351Ca83864e6de46AB2.
2. **[RollupPoS.sol](https://github.com/iden3/rollup/blob/testnet/contracts/RollupPoS.sol)** manages the consensus mechanism; in this case PoS: https://goerli.etherscan.io/address/0x60B6b593c381E5D31EC9a7b74a4cc1F2C5235EeB
1. **[Rollup.sol](https://github.com/iden3/rollup/blob/testnet/contracts/Rollup.sol)** manages the rollup itself: https://goerli.etherscan.io/address/0xXXXXXX
2. **[RollupPoS.sol](https://github.com/iden3/rollup/blob/testnet/contracts/RollupPoS.sol)** manages the consensus mechanism; in this case PoS: https://goerli.etherscan.io/address/0xXXXXXX

This testnet is purely for transfers (not arbitrary smart contracts), and fully supports ERC20 tokens.

Expand Down Expand Up @@ -110,21 +111,20 @@ node cli.js printkeys --configpath config-example.json
You should see a message with the following stucture:

```bash=
The following keys have been found:
Ethereum key:
Address:
Babyjub Key:
Public Key:
Ethereum public key:
Address:
Rollup public key:
Compressed:
Points:
Ax:
Ay:
Public Key Compressed:
```

Before we interact with the rollup contract, you’ll need to make sure you have some ether stored in this `Address` (this is to pay for the network transaction fees in the next step). The best way to do this is by using the goerli faucet.

Copy your ethereum address and visit the [faucet](https://goerli-faucet.slock.it/) to request test ether.

One you've done this, visit https://goerli.etherscan.io/address/ and input your address. You should see that your balance has been updated.
One you've done this, visit [https://goerli.etherscan.io](https://goerli.etherscan.io/) and input your address. You should see that your balance has been updated.


### 2.4. Get tokens<a id="2_4"></a>
Expand Down Expand Up @@ -158,9 +158,9 @@ Note that deposits may take 2 minutes to be forged.

As before, you should see a transaction hash. You can use the this hash to [track its progress](https://goerli.etherscan.io/).

### 2.6. Get your rollup ID<a id="2_6"></a>
### 2.6. Get your rollup account status<a id="2_6"></a>

Rollup addresses are simply Merkle tree leaf IDs. To find out what your rollup id is, use either one of the following commands:
To find out what your rollup account status is, use either one of the following commands:

```bash=
node cli.js info --type accounts --filter ethereum -c config-example.json
Expand Down Expand Up @@ -189,27 +189,25 @@ Accounts found:
]
```

You'll find your rollup id under the field `idx`.

With this id, you can do things like check your balance. Either by executing the following command:
Note that information retrieved prints all possible tokens attached to rollup account. If it is wanted to get information account for specific token, you can filter by token too:

```
node cli.js info --type accounts --filter id --id <rollup ID> -c config-example.json
node cli.js info --type accounts --filter tokenid --tokenid <token ID> -c config-example.json
```

Or by visiting the following link:
Also you could visit the following link to check your account state:

[https://zkrollup.iden3.net/accounts/](https://zkrollup.iden3.net/accounts/1){your rollup id}
https://zkrollup.iden3.net/accounts/:ax/:ay/:tokenid

### 2.7. Send a rollup transaction to an operator<a id="2_7"></a>
Now that you've created your rollup account and found your account id, it's time to send your first rollup transaction!
Now that you've created your rollup account, it's time to send your first rollup transaction!

To do this, execute the following command:

> You'll need to replace the first `<rollup ID>` with your id and the second with the id of the intended recipient (for example `1`). You'll also need to replace `<amount>` with the amount you wish to send, and `<fee>` with an appropriate fee (at least 1 wei).
> You'll need to replace the first `<rollup address>` with the rollup public key compressed of the intended recipient. You'll also need to replace `<amount>` with the amount you wish to send, and `<fee>` with an appropriate fee (`50%` as an example).
```bash=
node cli.js offchaintx --type send --sender <rollup ID> --recipient <rollup ID> --amount <amount> --fee <fee> --tokenid 0 -c config-example.json
node cli.js offchaintx --type send --recipient <rollup address> --amount <amount> --fee <fee> --tokenid 0 -c config-example.json
```

Congratulations on executing your first off-chain transaction! 🚀
Expand All @@ -224,12 +222,11 @@ To avoid paying an on-chain withdrawal fee, you need to initialise your withdraw
To do this, execute the following command:

> As before, you’ll need to replace `<rollup ID>` with your id, `<amount>` with the amount you wish to send, and `<fee>` with an appropriate fee (at least 1 wei).
> As before, you’ll need to replace `<amount>` with the amount you wish to send, and `<fee>` with an appropriate fee (`50%` as an example).

```bash=
node cli.js offchaintx --type withdrawoffchain --sender <rollup ID> --amount <amount> --fee <fee> --tokenid 0 -c config-example.json
node cli.js offchaintx --type withdrawoffchain --amount <amount> --fee <fee> --tokenid 0 -c config-example.json
```

This effectively transfers tokens to the **exit tree** -- a Merkle tree dedicated to keeping track of withdrawals. From there, they can be withdrawn using the on-chain contract.
Expand All @@ -238,10 +235,8 @@ This effectively transfers tokens to the **exit tree** -- a Merkle tree dedicate

Once the previous transaction has been forged, a new entry in the exit tree is created. You can check for this entry by executing the following command:

> Remember to replace `<rollup ID>` with your id.
```bash=
node cli.js info --type exits --id <rollup ID> -c config-example.json
node cli.js info --type exits --tokenid 0 -c config-example.json
```

You'll receive a response that looks like this:
Expand All @@ -259,22 +254,38 @@ We're now ready to withdraw the tokens from the rollup chain to our wallet.

To do this, execute the following command:

> Remember to replace `<rollup ID>` with your id, and `<numexitbatch>` with the batch number you obtained in the previous step.
> Remember to replace `<numexitbatch>` with the batch number you obtained in the previous step.
```bash=
node cli.js onchaintx --type withdraw --id <rollup ID> --numexitbatch <numexitbatch> -c config-example.json
node cli.js onchaintx --type withdraw --tokenid 0 --numexitbatch <numexitbatch> -c config-example.json
```

Wait a couple of minutes and then visit [etherscan](https://goerli.etherscan.io/) to check that your transaction has gone through.

And voila! That's all there is to it :)

### 2.11. Resources<a id="2_11"></a>
### 2.11. Bonus: create rollup account with an off-chain transaction<a id="2_11"></a>

- Checkout our github repository [here](https://github.com/iden3/rollup).
We are going to creare a rollup account which does not exist on rollup ledger and send some funds to it. This means that a rollup account could be created without going on-chain and does not then does not require any ether.

Get a valid rollup account from client or ask for rollup public key to some friend :)
```bash=
node cli.js createkeys
```

Take `Rollup public key compressed` and perform the off-chain deposit:
```bash=
node cli.js offchaintx --type depositoffchain --amount <amountToSend> --tokenid 0 --fee <feeToPay%> --ethereumaddress <address new rollup account> -r <rollup public key>
```

> In order to perform this deposit off-chain transaction, the operator must pay for an on-chain transaction and the creation of the rollup account. Transaction needs to cover this costs, otherwise operator will automatically reject the transaction. Current testnet implementation defines a `deposit fee = 0.0001 ether`. Taking into account that we consider `WEENUS token = 1$`, that would mean that, assuming ether value is 230$, deposit fee would cost 0.023 $. Therefore, to perform a deposit off-user, rollup user must pay fees that covers this deposit fees.
- For more on how the rollup client works, see [here](https://github.com/iden3/rollup/blob/testnet/rollup-cli/README.md).

- If you’d like to offer feedback, come across any problems, or have any questions at all, please feel free to reach out to us in our [telegram group](https://t.me/joinchat/G89XThj_TdahM0HASZEHwg).

### 2.12. Resources<a id="2_12"></a>

- Checkout our github repository [here](https://github.com/iden3/rollup).

- For more on how the rollup client works, see [here](https://github.com/iden3/rollup/blob/testnet/rollup-cli/README.md).

- If you’d like to offer feedback, come across any problems, or have any questions at all, please feel free to reach out to us in our [telegram group](https://t.me/joinchat/G89XThj_TdahM0HASZEHwg).
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"test:coverage": "npx truffle run coverage --file='./test/contracts/*.test.js'",
"build:webapp": "browserify rollup-cli/index.js -s rollup > simple-webapp/src/utils/bundle-cli.js && browserify rollup-operator/index.js -s operator > simple-webapp/src/utils/bundle-op.js && simple-webapp/src/utils/disable-eslint.sh",
"test:all": "npm run test:rollup && cd rollup-cli && npm run test:all && cd ../rollup-operator && npm run test:all && cd ../cli-pob && npm run test:all"

},
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion rollup-cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ getIden3.sh
node_modules
/test/resources/
/wallet.json
/config.json
/config.json
/*.test.json
Loading

0 comments on commit a6f9055

Please sign in to comment.