Skip to content

Commit

Permalink
Merge pull request #76 from gosh-sh/l2_fix_owerview
Browse files Browse the repository at this point in the history
fixed L2
  • Loading branch information
Oxydixi authored Oct 26, 2023
2 parents dea9021 + 9f71ab3 commit d8e363c
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 125 deletions.
128 changes: 75 additions & 53 deletions docs/ethereum-L2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,14 @@
GOSH is an asynchronous, highly scalable validity rollup which enables any asset on Ethereum blockchain to be transferred into GOSH and vice versa. All ZK Proofs (Zero-knowledge proofs) are prepared on the user side by a [**Proposer**](ethereum-L2.md#definitions " is an off-chain program which packages all necessary data to prove to GOSH chain that a particular transaction (let’s call them “L2 transactions”) on Ethereum Network took place and vise versa — to prove to Ethereum ELOCK smart contract (i.e. Ethereum validators) that an L2 transaction took place on the GOSH Blockchain").
It then submitted to Independent Collator which receives user input and executes them on GOSH.

<!-- TODO -->[remake]
Anyone can submit a resulting **L2 (GOSH Blokchain)** state root to **L1 (Etherium Blokchain)**.

<!-- TODO -->
Anyone can submit a resulting **L2 (GOSH Blockchain)** state root to **L1 (Ethereum Blockchain)**.
Randomly selected Verifiers run the state transition periodically and slash Collators in case of a fraud via decision by L1. Verifiers are slashed for false fraud alerts. If Collator is censoring users' transactions, it is possible to force the transaction via L1.

<!-- TODO -->[remake]
Anyone can publish L2 state root but only Collator can propose L2 state change.



**Constraints:**


* L1 can’t have the L2 entire state (L2 state is too large)
* There must be a mechanism to move funds from L2 even if: L2 is not moving; L2 has banned specific accounts
* EVM and TVM are different. TVM is a reference VM for the L2 chain. This means that even if L1 has a state it can’t execute transactions to verify correctness. But it can execute ZKP which will prove the correctness of operations in the particular circuit
Anyone can publish L2 state root but only Collator can propose L2 state change.
<!-- TODO -->


## **Proof Summary**
**Proof Summary**


| **What do we Prove** | **How do we Prove it** |
Expand All @@ -34,7 +23,7 @@ Anyone can publish L2 state root but only Collator can propose L2 state change.
| **`L2 Blocks are correct`** | Validator signatures + Verifiers Fraud Proofs |
| **`L1 transaction are within the correct blocks`** | Merkle tree proof from Transaction hash to L1 block hash |
| **`L2 transaction are within the correct blocks`** | Merkle tree proof from Transaction hash to L2 block hash |
| **`All L1 transactions are provided to L2 from block A to block B`** | Txn count in block a and Txn count in block B are known we can verify that total transaction count transferred to [GLOCK](ethereum-L2.md#definitions "is a special TIP-3 Token Root Contract on GOSH Blockchain") is correct and since we have hashes it's impossible to cheat
| **`All L1 transactions are provided to L2 from block A to block B`** | Txn count in block a and Txn count in block B are known we can verify that total transaction count transferred to [GLOCK](ethereum-L2.md#contracts "is a special TIP-3 Token Root Contract on GOSH Blockchain") is correct and since we have hashes it's impossible to cheat
| **`Transaction counts and Balances are correct for L1 Block transmitted to L2`** | Merkle tree of account states for a particular L1 block |
| **`All L2 Withdrawal Transactions are transferred to L1 from Block A to Block B`** | Txn count in block a and Txn count in block B are known we can verify that total transaction count transferred to ELOCK is correct and since we have hashes it's impossible to cheat
| **`TIP-3 Deposit/Transfer/Withdrawal Transaction Execution is correct`** | ZKP for TIP-3 Circuit |
Expand All @@ -44,28 +33,37 @@ Anyone can publish L2 state root but only Collator can propose L2 state change.



## **Roadmap**/**Development process**

## **Roadmap**


### **Stage 1: Trustless Bridge** (**In production**) ![](images/green%20tick3.jpg)

**Challenges:**

* L1 can’t have the L2 entire state (L2 state is too large)
* There must be a mechanism to move funds from L2 even if: L2 is not moving; L2 has banned specific accounts
* EVM and TVM are different. TVM is a reference VM for the L2 chain. This means that even if L1 has a state it can’t execute transactions to verify correctness. But it can execute ZKP which will prove the correctness of operations in the particular circuit


!!! info
At this stage we assume:
L2 fully trusts L1, it knows Validators (Committee) PubKeys and can always validate the chain of L1 blocks.
We do not validate the smart contract execution on L2. We protect against any malicious 3rd party except for L1 and L2 Validators.

As an example we will talk about ETH moving from Ethereum mainnet into WETH Asset on GOSH L2 Blockchain and back. In general any asset on Ethereum can be supported with necessary adjustments made to [ELOCK](ethereum-L2.md#definitions "is a GOSH L2 smart contract on Ethereum Blockchain") smart contract Deposit/Withdrawal functions.
As an example we will talk about ETH moving from Ethereum mainnet into WETH Asset on GOSH L2 Blockchain and back. In general any asset on Ethereum can be supported with necessary adjustments made to [ELOCK](ethereum-L2.md#contracts "is a GOSH L2 smart contract on Ethereum Blockchain") smart contract Deposit/Withdrawal functions.

Since GOSH uses ed25519 we use a double signature envelope scheme to prove signatures on GOSH to ELOCK Smart Contract on Ethereum (*we could use ZKP to prove the ed25519 or a precompile proposed EIP665 whenever either of those solutions will be production ready*).



<!--
![](images/etherium_stage1_pic_L1-L2.jpg)
The scheme for transferring assets from the Etherium to GOSH
The scheme for transferring assets from the Ethereum to GOSH
![](images/etherium_stage1_pic_L2-L1.jpg)
The scheme for transferring assets from the GOSH to Etherium

The scheme for transferring assets from the GOSH to Ethereum
-->


!!! info
Expand All @@ -77,14 +75,14 @@ The scheme for transferring assets from the GOSH to Etherium



### **Stage 2: Optimistic roll-up, kinda**
### **Stage 2: Optimistic roll-up**

!!! info
At this stage we add fraud and execution proofs for [TIP-3](ethereum-L2.md#definitions "is a distributed token smart contract standard on GOSH blockchain") сontracts.
At this stage we add fraud and execution proofs for [TIP-3](ethereum-L2.md#definitions "is a distributed token smart contract standard on GOSH blockchain") contracts.

The Proposer constructs the TIP-3 execution proof and sends it together with block proofs. If the execution is correctly proved the funds can be withdrawn immediately. If the Proposer does not wish to pay the gas fees for ZKP execution it can supply the withdrawal request without any proof but with a bond. In which case the withholding period will be activated (hence optimistic rollup). Another Proposer can verify the correctness of execution of the TIP-3 in the proposed batch and if found incorrect execution can supply the fraud proof (consisting of proof of the correct execution of the corrupted TIP-3 transaction and proof of block tree hashes which will be incompatible with hashes provided by the first Proposer) and collect the Proposer Bond.

At this stage we have added a mechanism of Fraud proof of L2 validators making the network effectively on par with security assumptions of other оptimistic rollups, but also providing a mechanism for immediate Validation of token contract execution on L2 network.
At this stage we have added a mechanism of Fraud proof of L2 validators making the network effectively on par with security assumptions of other optimistic rollups, but also providing a mechanism for immediate Validation of token contract execution on L2 network.

!!! info
*What we don’t cover at this Stage?*
Expand Down Expand Up @@ -149,7 +147,9 @@ Which is less of an a probability of successful attack on Bitcoin blockchain:

* **GLOCK** — is a set оf special contracts on GOSH Blockchain.
Aside from managing TIP-3 distributed token they also manages the deposits and withdrawals assets of users.
Contract `Checker.sol` receives external message from `Proposer` with Ethereum blockchain proofs signed by Ethereum Committee, checks total transaction count consistency, checks `Proposer` message Merkle proofs and deploys the contract `Proposal.sol` that validators check and vote for the Ethereum blocks in GOSH then receives a list of verified transactions and send a message to the root contract `RootTokenContract.cpp`
Contract `Checker.sol` receives external message from `Proposer` with Ethereum blockchain proofs signed by Ethereum Committee, checks the hash of the blocks lined up in the chain and deploys the contract `Proposal.sol` that validators check and vote for the Ethereum blocks in GOSH then receives a list of verified transactions and send a message to the root contract `RootTokenContract.cpp`

<!-- checks total transaction count consistency, checks `Proposer` message Merkle proofs -->

* **RootTokenContract** - is a smart contract on GOSH that manages user withdrawals. It receives TIP-3 transactions, verifies them and adds transactions to the counter index.
Also it deploys the contract TIP3 wallet contract (`TONTokenWallet.cpp`) and sends wrapped tokens there.
Expand Down Expand Up @@ -190,48 +190,74 @@ Also it deploys the contract TIP3 wallet contract (`TONTokenWallet.cpp`) and sen
## **Commission**


**for transfers to GOSH**
### **for transfers to GOSH**

When transferring assets to GOSH, `checker.sol` sends the transfer amount and coefficients `a` and `b` to the `RootTokenContract.cpp` and it calculates the commission amount. Then mints the wrapped tokens to the user TIP3-wallet minus the commission. And the commission is sent to the wallet by the commission in GOSH.

When transferring assets to GOSH, checker.sol calculates the commission, and root mint the wrapped tokens to the user TIP3-wallet minus the commission.

calculated as:

$\frac{a * x}{10 000} + b$

**for withdraw to Ethereum**
where:

The commission is calculated in the ELOCK contract.
**a** - commission percentage = 10 (0.1%)

It consists of 2 parts:
**b** - permanent commission (does not depend on the transfer amount, now = 0)

**Part 1** - the cost of the transaction for the transfer of `WETH` to the recipient
**х** - amount of tokens to transfer

calculated as:

the amount of gas for the transfer transaction (21000) * the current cost of gas at the time of transfer
<!--
grantbatch(uint32 _answer_id, TransactionBatch[] transactions, uint128 a, uint128 b)
**Part 2**
void grant(
address dest, ///< Token wallet address
uint128 tokens, ///< Amount of tokens to be granted.
uint128 evers, ///< Amount of evers to be attached to message.
///< If the method called by internal message, will be ignored
///< (rest attached evers will be transmitted).
opt<cell> notify ///< Payload (arbitrary cell) - if specified, will be transmitted into dest owner's notification.
) = 14;
calculated as:
[[internal, external, answer_id]]
void grantBatch(
dict_array<TransactionBatch> transactions, ///< Amount of tokens to be granted.
uint128 a,
uint128 b
) = 1014; -->

amount of validators' expenses / quantity of transfers to withdraw `WETH` in the current proposal

<!--
вычисляется: 21 000 (количество газа для транзакции трансфера) * текущую стоимость газа в данный момент (контракт ELOCK запрашивает ее у сети Ethertum на момент трансфера (функция в ELOCK `gasPrice()` ))

2 часть - (сумма затрат валидаторов/ количество трансферов в выводов в текущем пропозле) = операционная стоимость затрат валидаторов на вывод деленная на количество транзакций переводов-->
### **for withdraw to Ethereum**

Then it is sent to the commission wallet.
The commission is calculated in the ELOCK contract.

It consists of 2 parts:

* *Part 1* - the cost of the transaction for the transfer of `WETH` to the recipient

calculated as:

$ 21000 * gasprice$

where:

**gasprice** - gas price during withdraw transaction

* *Part 2*

calculated as:

amount of validators' expenses / quantity of transfers to withdraw `WETH` in the current proposal

<!--
вычисляется: 21 000 (количество газа для транзакции трансфера) * текущую стоимость газа в данный момент (контракт ELOCK запрашивает ее у сети Ethertum на момент трансфера (функция в ELOCK `gasPrice()` ))
2 часть - (сумма затрат валидаторов/ количество трансферов в выводов в текущем пропозле) = операционная стоимость затрат валидаторов на вывод деленная на количество транзакций переводов-->

Then it is sent to the commission wallet.

<!-- (???)
**RootTokenContract.cpp** Compiles into two contract versions: RootTokenContract.tvc (for external wallets) and FlexTokenRoot.tvc (for internal wallets).
Expand All @@ -248,7 +274,7 @@ Any DAO on GOSH can become Ethereum Layer 2 with a click of a button.
This is only possible in the GOSH version at least 6.1.0

### how to transfer ETH to GOSH
To make a transfer between wallets, go to the **Etherium** tab:
To make a transfer between wallets, go to the **Ethereum** tab:

![](images/etherium_usage_begin2.jpg)

Expand All @@ -258,7 +284,7 @@ or select the this section by clicking on your profile in the right corner:

Now we can test the ETH transfer in the alpha version.

Сlick on:
Click on:

![](images/etherium_usage_begin3.jpg)

Expand Down Expand Up @@ -288,15 +314,16 @@ After you make a deposit to the GOSH contract in Ethereum, the corresponding amo

![](images/etherium_usage_transfer_comleted.jpg)

### how to transfer WETH to Ethereum

<!-- TODO WITHDRAWAL -->

<!-- DAO members can choose to have their token available in Ethereum, effectively making any project its own L2. And because GOSH L2 supports ERC-20 Tokenization, we offer easy ecosystem integration for any project............... -->

<!--
### how to transfer WETH to Ethereum
### how to transfer WETH into GOSH
-->

## **Integration with GOSH L2**

More information about integration with GOSH L2 can be found [here](integrations/l2.md)


## **Definitions**
Expand All @@ -321,8 +348,3 @@ Proposer will always accumulate all transactions that are currently not applied
<!-- **WETH TIP-3 Wallet** — is a custom TIP-3 contract that runs in GOSH Masterchain and in addition to standard functions has `burnTokens` method. `burnTokens` is called when WETH needs to be transferred to Ethereum Blockchain. Burn is proved to ELOCK contract in order to allow for ETH native token withdrawals. -->

<!-- **VAULT** — is GOSH Shardchain smart contract that Wraps WETH TIP-3 tokens into tradable assets on GOSH Network -->


## **Integration with GOSH L2**

More information about integration with GOSH L2 can be found [here](integrations/l2.md)
Loading

0 comments on commit d8e363c

Please sign in to comment.