Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
docs: update some links and rename pETH to pCKB (#141)
Browse files Browse the repository at this point in the history
* docs: update some links

* docs: rename pETH to pCKB

Ref:
- godwokenrises/godwoken#630
  • Loading branch information
Flouse committed Apr 14, 2022
1 parent 74acf6b commit d230446
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Godwoken Polyjuice
An Ethereum compatible backend for [Godwoken](https://github.com/nervosnetwork/godwoken) rollup framework. It includes [generator](./c/generator.c) and [validator](./c/validator.c) implementations.
An Ethereum compatible backend for [Godwoken](https://github.com/nervosnetwork/godwoken) (a generic optimistic rollup framework). It includes [generator](./c/generator.c) and [validator](./c/validator.c) implementations.

Polyjuice provides an [Ethereum](https://ethereum.org/en/) compatible layer on [Nervos CKB](https://github.com/nervosnetwork/ckb). It leverages account model as well as scalability provided by [Godwoken](https://github.com/nervosnetwork/godwoken/blob/9de340c/docs/life_of_a_godwoken_transaction.md), then integrates [evmone](https://github.com/ethereum/evmone) as an EVM engine for running Ethereum smart contracts.
Polyjuice provides an [Ethereum](https://ethereum.org/en/) compatible layer on [Nervos CKB](https://github.com/nervosnetwork/ckb). It leverages account model as well as scalability provided by [Godwoken](https://github.com/nervosnetwork/godwoken/blob/v1.0.0-rc1/docs/life_of_a_godwoken_transaction.md), then integrates [evmone](https://github.com/ethereum/evmone) as an EVM engine for running Ethereum smart contracts.

Polyjuice aims at 100% EVM compatibility as a goal, meaning we plan to support all smart contracts supported by the latest Ethereum hardfork version. See [EVM-compatible.md](docs/EVM-compatible.md) and [Addition-Features.md](docs/Addition-Features.md) for more details.

Expand Down Expand Up @@ -37,7 +37,7 @@ input_size : u32 (little endian)
input_data : [u8; input_size] (input data)
```

Every Polyjuice argument fields must been serialized one by one and put into godwoken [`RawL2Transaction.args`][rawl2tx-args] for polyjuice to read. If the `input_data` have 56 bytes, then the serialized data size is `8 + 8 + 16 + 16 + 4 + 56 = 108` bytes.
Every Polyjuice argument fields must been serialized one by one and put into Godwoken [`RawL2Transaction.args`][rawl2tx-args] for Polyjuice to read. If the `input_data` have 56 bytes, then the serialized data size is `8 + 8 + 16 + 16 + 4 + 56 = 108` bytes.


### Creator account script
Expand All @@ -50,7 +50,7 @@ args:
eth_addr_reg_id : u32 (little endian, the ETH_Address_Registry Contract id)
```

Polyjuice creator account is a godwoken account for creating Polyjuice contract account. This account can only be created by [meta contract][meta-contract], and the account id is used as the chain id in Polyjuice. The `sudt_id` field in script args is the sUDT token current Polyjuice instance bind to as [`pETH`](https://github.com/nervosnetwork/godwoken/blob/master/docs/life_of_a_polyjuice_transaction.md#peth). The `eth_addr_reg_id` field in script args is the id of `ETH Address Registry` layer2 contract which provides two-ways mappings between `eth_address` and `gw_script_hash`.
Polyjuice creator account is a Godwoken account for creating Polyjuice contract account. This account can only be created by [meta contract][meta-contract], and the account id is used as the chain id in Polyjuice. The `sudt_id` field in script args is the sUDT token current Polyjuice instance bind to as [`pCKB`](https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md#pCKB). The `eth_addr_reg_id` field in script args is the id of `ETH Address Registry` layer2 contract which provides two-ways mappings between `eth_address` and `gw_script_hash`.

### Contract account script

Expand Down Expand Up @@ -94,10 +94,10 @@ short_godwoken_account_script_hash = blake2b(script.as_slice())[0..20]


[rawl2tx-args]: https://github.com/nervosnetwork/godwoken/blob/9a3d921/crates/types/schemas/godwoken.mol#L60
[meta-contract]: https://github.com/nervosnetwork/godwoken-scripts/blob/028dbc4/c/contracts/meta_contract.c
[meta-contract]: https://github.com/nervosnetwork/godwoken-scripts/blob/86b299f/c/contracts/meta_contract.c

## More docs
* [EVM compatible](docs/EVM-compatible.md)
* [Addition Features](docs/Addition-Features.md)
* [Life of a Polyjuice Transaction](https://github.com/nervosnetwork/godwoken/blob/master/docs/life_of_a_polyjuice_transaction.md)
* [Life of a Godwoken Transaction](https://github.com/nervosnetwork/godwoken/blob/master/docs/life_of_a_godwoken_transaction.md)
* [Life of a Polyjuice Transaction](https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md)
* [Life of a Godwoken Transaction](https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_godwoken_transaction.md)
2 changes: 1 addition & 1 deletion c/polyjuice_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static uint32_t g_created_id = UINT32_MAX;
static uint32_t g_compatible_chain_id = UINT32_MAX;
/**
* creator_account, known as root account
* @see https://github.com/nervosnetwork/godwoken/blob/5735d8f/docs/life_of_a_polyjuice_transaction.md#root-account--deployment
* @see https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md#root-account--deployment
*/
static uint32_t g_creator_account_id = UINT32_MAX;
/**
Expand Down
20 changes: 11 additions & 9 deletions docs/EVM-compatible.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ The maximum EVM revision supported is `EVMC_BERLIN`.
- [ ] support EVMC_LONDON
- [ ] support EVMC_SHANGHAI

## pETH
## pCKB

**pETH** is a new concept introduced by Polyjuice.
[pCKB](https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md#pckb) is a new concept introduced by Polyjuice.

Recall that in Ethereum, the gas of each smart contract is calculated. The transaction fee is calculated then by multiplying gas with specified gas price. In Polyjuice, **pETH** is used as the unit for calculating transaction fees. This means while the gas price in Ethereum is ETH/gas(which is denominated in wei, which is 1e-18 ether), in Polyjuice gas price is measured in pETH/gas. When executing a transaction, Polyjuice will deduct transaction fees using tokens in the layer2 [sUDT](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0025-simple-udt/0025-simple-udt.md) type denoted by **pETH**.
Recall that in Ethereum, the gas of each smart contract is calculated. The transaction fee is calculated then by multiplying gas with specified gas price. In Polyjuice, **pCKB** is used as the unit for calculating transaction fees. This means while the gas price in Ethereum is ETH/gas(which is denominated in wei, which is 1e-18 ether), in Polyjuice gas price is measured in pCKB/gas. When executing a transaction, Polyjuice will deduct transaction fee using the layer2 [sUDT](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0025-simple-udt/0025-simple-udt.md) type denoted by **pCKB**.

Note in Ethereum, one can also send some ETH to a smart contract for certain behavior. In Polyjuice, this feature is also performed by sending pETH.
Note when sending a transaction to a smart contract for certain behavior, the `value` of the transaction is `pCKB`.

## Account Abstraction

Expand All @@ -29,7 +29,7 @@ Whether you use a native CKB or any sUDT token type, they will all be represente

A Polyjuice transaction is essentially just a Godwoken transaction.

When you send an Ethereum transaction, the transaction is converted to Godwoken [RawL2Transaction](https://github.com/nervosnetwork/godwoken/blob/9a3d92/crates/types/schemas/godwoken.mol#L56-L61) type which is automatically handled by [Godwoken Web3](https://github.com/nervosnetwork/godwoken-web3/tree/6e78293).
When you send an Ethereum transaction, the transaction is converted to Godwoken [RawL2Transaction](https://github.com/nervosnetwork/godwoken/blob/v1.0.0-rc1/crates/types/schemas/godwoken.mol#L69-L74) type which is automatically handled by [Godwoken Web3](https://github.com/nervosnetwork/godwoken-web3/tree/v1.0.0-rc1).

## Behavioral differences of some opcodes

Expand All @@ -43,16 +43,18 @@ When you send an Ethereum transaction, the transaction is converted to Godwoken

* Transaction context
* `chain_id` consists up of two parts: [**compatible_chain_id(u32) | [creator_account_id]()(u32)**]
- `compatible_chain_id` is defined in Godwoken [RollupConfig](https://github.com/nervosnetwork/godwoken/blob/acc6614/crates/types/schemas/godwoken.mol#L64).
- `creator_account` is known as [the root account of Polyjuice](https://github.com/nervosnetwork/godwoken/blob/5735d8f/docs/life_of_a_polyjuice_transaction.md#root-account--deployment).
- `compatible_chain_id` is defined in Godwoken [RollupConfig](https://github.com/nervosnetwork/godwoken/blob/v1.0.0-rc1/crates/types/schemas/godwoken.mol#L64).
- `creator_account` is known as [the root account of Polyjuice](https://github.com/nervosnetwork/godwoken/blob/v1.0.0-rc1/docs/life_of_a_polyjuice_transaction.md#root-account--deployment).
* the block difficulty is always `2500000000000000`
* the gas limit for each block is 12500000; it is not a transaction-level limit. Any transaction can reach the gas limit
* the size limit for contract's return data is [`25600B`](https://github.com/nervosnetwork/godwoken-scripts/blob/31293d1/c/gw_def.h#L21-L22)
* the size limit for contract's storage is [`25600B`](https://github.com/nervosnetwork/godwoken-scripts/blob/31293d1/c/gw_def.h#L21-L22)


* Value (pETH) transfer from EOA to EOA directly is not supported.
> Workaround: pETH (CKB) is represented as an ERC 20 token on layer2, it could be transfer through the [sUDT_ERC20_Proxy](https://github.com/nervosnetwork/godwoken-polyjuice/blob/3f1ad5b/solidity/erc20/README.md) contract's `transfer function`.
* `transaction.to` MUST be a Contract Address

Value (pCKB) transfer from EOA to EOA directly is not supported.
> Workaround: pCKB (CKB) is represented as an ERC20 token on layer2, it could be transfer through the [sUDT_ERC20_Proxy](https://github.com/nervosnetwork/godwoken-polyjuice/blob/3f1ad5b/solidity/erc20/README.md) contract's `transfer function`.
* The `transfer value` can not exceed uint128:MAX

* Pre-compiled contract
Expand Down
2 changes: 1 addition & 1 deletion polyjuice-tests/src/test_cases/metamask_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn test_transfer_by_metamask() {
// ```
//
// if tx.data is null && to_address is EoA or notExistEoA,
// then handle it as a simple pETH transfer, using ERC20_Proxy(sUDT_ID = 1)
// then handle it as a simple pCKB transfer, using ERC20_Proxy(sUDT_ID = 1)
//
// The RawL2Transaction from Web3 RPC to Godwoken RPC:
// {
Expand Down

0 comments on commit d230446

Please sign in to comment.