From c564a411ed89a201a1418bd4e0f077f81c4f2ac4 Mon Sep 17 00:00:00 2001 From: jjy Date: Tue, 13 Dec 2022 14:43:44 +0800 Subject: [PATCH 01/13] refactor: move `gw-types` and `gw-common` to `gwos` folder --- Cargo.toml | 8 +- crates/benches/Cargo.toml | 4 +- crates/block-producer/Cargo.toml | 4 +- crates/block-producer/src/block_producer.rs | 6 +- crates/block-producer/src/stake.rs | 4 +- crates/block-producer/src/utils.rs | 5 +- crates/chain/Cargo.toml | 4 +- crates/challenge/Cargo.toml | 4 +- crates/generator/Cargo.toml | 4 +- crates/godwoken-bin/Cargo.toml | 4 +- crates/jsonrpc-types/Cargo.toml | 4 +- crates/mem-pool/Cargo.toml | 4 +- crates/mem-pool/src/withdrawal.rs | 6 +- crates/metrics/Cargo.toml | 4 +- crates/p2p-network/Cargo.toml | 2 +- crates/polyjuice-sender-recover/Cargo.toml | 4 +- crates/replay-chain/Cargo.toml | 4 +- crates/rpc-client/Cargo.toml | 4 +- crates/rpc-server/Cargo.toml | 4 +- crates/store/Cargo.toml | 4 +- crates/tests/Cargo.toml | 4 +- crates/tools/Cargo.toml | 4 +- crates/traits/Cargo.toml | 4 +- crates/tx-filter/Cargo.toml | 4 +- crates/utils/Cargo.toml | 4 +- crates/utils/src/calc_finalizing_range.rs | 4 +- crates/utils/src/lib.rs | 2 +- crates/utils/src/timepoint.rs | 2 +- gwos/Cargo.lock | 12 +- gwos/Cargo.toml | 14 - gwos/c-uint256-tests/src/bindings.rs | 168 ---- gwos/c/Makefile | 9 +- gwos/c/account_lock_lib/secp256k1.c | 53 -- gwos/c/blake2b_def.h | 11 + gwos/c/blockchain.mol | 120 --- gwos/c/godwoken.mol | 411 --------- gwos/c/rust-binding/smt_wrapper.h | 2 +- gwos/capsule.toml | 8 +- gwos/contracts/Cargo.lock | 136 +-- gwos/contracts/Cargo.toml | 2 - gwos/contracts/always-success/Cargo.toml | 2 +- gwos/contracts/always-success/src/main.rs | 3 +- gwos/contracts/challenge-lock/Cargo.toml | 2 +- gwos/contracts/challenge-lock/src/main.rs | 3 +- gwos/contracts/ckb-smt/build.rs | 2 + gwos/contracts/custodian-lock/src/main.rs | 3 +- gwos/contracts/deposit-lock/src/main.rs | 3 +- gwos/contracts/eth-account-lock/Cargo.toml | 3 +- gwos/contracts/eth-account-lock/src/entry.rs | 113 +-- .../eth-account-lock/src/eth_signature.rs | 71 -- gwos/contracts/eth-account-lock/src/main.rs | 4 +- gwos/contracts/gw-utils/Cargo.toml | 6 +- gwos/contracts/gw-utils/src/finality.rs | 2 +- gwos/contracts/secp256k1-utils/Cargo.toml | 12 - gwos/contracts/secp256k1-utils/build.rs | 50 -- gwos/contracts/secp256k1-utils/src/lib.rs | 4 - .../secp256k1-utils/src/secp256k1_utils.rs | 24 - gwos/contracts/stake-lock/src/main.rs | 3 +- gwos/contracts/state-validator/src/main.rs | 8 +- gwos/contracts/state-validator/src/types.rs | 2 +- .../src/verifications/revert.rs | 2 +- .../src/verifications/submit_block.rs | 26 +- gwos/contracts/tron-account-lock/Cargo.toml | 11 - gwos/contracts/tron-account-lock/src/entry.rs | 118 --- gwos/contracts/tron-account-lock/src/main.rs | 32 - .../tron-account-lock/src/tron_signature.rs | 76 -- gwos/contracts/withdrawal-lock/src/main.rs | 3 +- gwos/{ => crates}/c-uint256-tests/Cargo.toml | 0 gwos/{ => crates}/c-uint256-tests/build.rs | 2 +- .../c-uint256-tests/loop_proptest | 0 gwos/crates/c-uint256-tests/src/bindings.rs | 844 ++++++++++++++++++ gwos/{ => crates}/c-uint256-tests/src/lib.rs | 0 {crates => gwos/crates}/common/Cargo.toml | 2 +- .../crates}/common/src/builtins.rs | 0 .../crates}/common/src/ckb_decimal.rs | 0 {crates => gwos/crates}/common/src/error.rs | 0 .../crates}/common/src/h256_ext.rs | 0 {crates => gwos/crates}/common/src/lib.rs | 0 .../crates}/common/src/merkle_utils.rs | 0 .../crates}/common/src/registry/context.rs | 0 .../common/src/registry/eth_registry.rs | 0 .../crates}/common/src/registry/mod.rs | 0 {crates => gwos/crates}/common/src/smt.rs | 0 {crates => gwos/crates}/common/src/state.rs | 0 .../crates}/common/src/test_traits.rs | 0 {crates => gwos/crates}/hash/Cargo.toml | 0 {crates => gwos/crates}/hash/src/blake2b.rs | 0 {crates => gwos/crates}/hash/src/lib.rs | 0 {crates => gwos/crates}/types/Cargo.toml | 0 {crates => gwos/crates}/types/build.rs | 0 .../crates}/types/schemas/block_sync.mol | 0 .../crates}/types/schemas/blockchain.mol | 0 .../crates}/types/schemas/deprecated.mol | 0 .../crates}/types/schemas/exported_block.mol | 0 .../crates}/types/schemas/godwoken.mol | 0 .../crates}/types/schemas/mem_block.mol | 0 .../crates}/types/schemas/omni_lock.mol | 0 .../crates}/types/schemas/store.mol | 0 .../crates}/types/schemas/xudt_rce.mol | 0 .../types/src/conversion/blockchain.rs | 0 .../crates}/types/src/conversion/ckb_h256.rs | 0 .../types/src/conversion/exported_block.rs | 0 .../crates}/types/src/conversion/godwoken.rs | 0 .../crates}/types/src/conversion/mem_block.rs | 0 .../crates}/types/src/conversion/mod.rs | 1 + .../crates}/types/src/conversion/primitive.rs | 0 .../crates}/types/src/conversion/smt_h256.rs | 0 .../crates}/types/src/conversion/store.rs | 0 .../crates}/types/src/conversion/utilities.rs | 0 {crates => gwos/crates}/types/src/core.rs | 0 .../crates}/types/src/extension.rs | 0 {crates => gwos/crates}/types/src/finality.rs | 0 .../crates}/types/src/generated/block_sync.rs | 0 .../crates}/types/src/generated/blockchain.rs | 0 .../crates}/types/src/generated/deprecated.rs | 0 .../types/src/generated/exported_block.rs | 0 .../crates}/types/src/generated/godwoken.rs | 0 .../crates}/types/src/generated/mem_block.rs | 0 .../crates}/types/src/generated/mod.rs | 0 .../crates}/types/src/generated/omni_lock.rs | 0 .../crates}/types/src/generated/poa.rs | 0 .../crates}/types/src/generated/store.rs | 0 .../crates}/types/src/generated/xudt_rce.rs | 0 {crates => gwos/crates}/types/src/lib.rs | 0 .../compatible_finalized_timepoint.rs | 0 .../types/src/offchain/error_receipt.rs | 0 .../types/src/offchain/exported_block.rs | 0 .../crates}/types/src/offchain/extension.rs | 0 .../crates}/types/src/offchain/generator.rs | 0 .../crates}/types/src/offchain/mem_block.rs | 0 .../crates}/types/src/offchain/mod.rs | 0 .../crates}/types/src/offchain/pool.rs | 0 .../crates}/types/src/offchain/rpc.rs | 0 .../crates}/types/src/offchain/run_result.rs | 0 .../crates}/types/src/offchain/store.rs | 0 {crates => gwos/crates}/types/src/prelude.rs | 0 .../crates}/types/src/registry_address.rs | 0 .../crates}/types/src/signature_message.rs | 0 .../crates}/types/src/std_traits.rs | 0 gwos/rust-toolchain | 2 +- 140 files changed, 1007 insertions(+), 1493 deletions(-) delete mode 100644 gwos/Cargo.toml delete mode 100644 gwos/c-uint256-tests/src/bindings.rs delete mode 100644 gwos/c/account_lock_lib/secp256k1.c create mode 100644 gwos/c/blake2b_def.h delete mode 100644 gwos/c/blockchain.mol delete mode 100644 gwos/c/godwoken.mol delete mode 100644 gwos/contracts/eth-account-lock/src/eth_signature.rs delete mode 100644 gwos/contracts/secp256k1-utils/Cargo.toml delete mode 100644 gwos/contracts/secp256k1-utils/build.rs delete mode 100644 gwos/contracts/secp256k1-utils/src/lib.rs delete mode 100644 gwos/contracts/secp256k1-utils/src/secp256k1_utils.rs delete mode 100644 gwos/contracts/tron-account-lock/Cargo.toml delete mode 100644 gwos/contracts/tron-account-lock/src/entry.rs delete mode 100644 gwos/contracts/tron-account-lock/src/main.rs delete mode 100644 gwos/contracts/tron-account-lock/src/tron_signature.rs rename gwos/{ => crates}/c-uint256-tests/Cargo.toml (100%) rename gwos/{ => crates}/c-uint256-tests/build.rs (89%) rename gwos/{ => crates}/c-uint256-tests/loop_proptest (100%) create mode 100644 gwos/crates/c-uint256-tests/src/bindings.rs rename gwos/{ => crates}/c-uint256-tests/src/lib.rs (100%) rename {crates => gwos/crates}/common/Cargo.toml (91%) rename {crates => gwos/crates}/common/src/builtins.rs (100%) rename {crates => gwos/crates}/common/src/ckb_decimal.rs (100%) rename {crates => gwos/crates}/common/src/error.rs (100%) rename {crates => gwos/crates}/common/src/h256_ext.rs (100%) rename {crates => gwos/crates}/common/src/lib.rs (100%) rename {crates => gwos/crates}/common/src/merkle_utils.rs (100%) rename {crates => gwos/crates}/common/src/registry/context.rs (100%) rename {crates => gwos/crates}/common/src/registry/eth_registry.rs (100%) rename {crates => gwos/crates}/common/src/registry/mod.rs (100%) rename {crates => gwos/crates}/common/src/smt.rs (100%) rename {crates => gwos/crates}/common/src/state.rs (100%) rename {crates => gwos/crates}/common/src/test_traits.rs (100%) rename {crates => gwos/crates}/hash/Cargo.toml (100%) rename {crates => gwos/crates}/hash/src/blake2b.rs (100%) rename {crates => gwos/crates}/hash/src/lib.rs (100%) rename {crates => gwos/crates}/types/Cargo.toml (100%) rename {crates => gwos/crates}/types/build.rs (100%) rename {crates => gwos/crates}/types/schemas/block_sync.mol (100%) rename {crates => gwos/crates}/types/schemas/blockchain.mol (100%) rename {crates => gwos/crates}/types/schemas/deprecated.mol (100%) rename {crates => gwos/crates}/types/schemas/exported_block.mol (100%) rename {crates => gwos/crates}/types/schemas/godwoken.mol (100%) rename {crates => gwos/crates}/types/schemas/mem_block.mol (100%) rename {crates => gwos/crates}/types/schemas/omni_lock.mol (100%) rename {crates => gwos/crates}/types/schemas/store.mol (100%) rename {crates => gwos/crates}/types/schemas/xudt_rce.mol (100%) rename {crates => gwos/crates}/types/src/conversion/blockchain.rs (100%) rename {crates => gwos/crates}/types/src/conversion/ckb_h256.rs (100%) rename {crates => gwos/crates}/types/src/conversion/exported_block.rs (100%) rename {crates => gwos/crates}/types/src/conversion/godwoken.rs (100%) rename {crates => gwos/crates}/types/src/conversion/mem_block.rs (100%) rename {crates => gwos/crates}/types/src/conversion/mod.rs (81%) rename {crates => gwos/crates}/types/src/conversion/primitive.rs (100%) rename {crates => gwos/crates}/types/src/conversion/smt_h256.rs (100%) rename {crates => gwos/crates}/types/src/conversion/store.rs (100%) rename {crates => gwos/crates}/types/src/conversion/utilities.rs (100%) rename {crates => gwos/crates}/types/src/core.rs (100%) rename {crates => gwos/crates}/types/src/extension.rs (100%) rename {crates => gwos/crates}/types/src/finality.rs (100%) rename {crates => gwos/crates}/types/src/generated/block_sync.rs (100%) rename {crates => gwos/crates}/types/src/generated/blockchain.rs (100%) rename {crates => gwos/crates}/types/src/generated/deprecated.rs (100%) rename {crates => gwos/crates}/types/src/generated/exported_block.rs (100%) rename {crates => gwos/crates}/types/src/generated/godwoken.rs (100%) rename {crates => gwos/crates}/types/src/generated/mem_block.rs (100%) rename {crates => gwos/crates}/types/src/generated/mod.rs (100%) rename {crates => gwos/crates}/types/src/generated/omni_lock.rs (100%) rename {crates => gwos/crates}/types/src/generated/poa.rs (100%) rename {crates => gwos/crates}/types/src/generated/store.rs (100%) rename {crates => gwos/crates}/types/src/generated/xudt_rce.rs (100%) rename {crates => gwos/crates}/types/src/lib.rs (100%) rename {crates => gwos/crates}/types/src/offchain/compatible_finalized_timepoint.rs (100%) rename {crates => gwos/crates}/types/src/offchain/error_receipt.rs (100%) rename {crates => gwos/crates}/types/src/offchain/exported_block.rs (100%) rename {crates => gwos/crates}/types/src/offchain/extension.rs (100%) rename {crates => gwos/crates}/types/src/offchain/generator.rs (100%) rename {crates => gwos/crates}/types/src/offchain/mem_block.rs (100%) rename {crates => gwos/crates}/types/src/offchain/mod.rs (100%) rename {crates => gwos/crates}/types/src/offchain/pool.rs (100%) rename {crates => gwos/crates}/types/src/offchain/rpc.rs (100%) rename {crates => gwos/crates}/types/src/offchain/run_result.rs (100%) rename {crates => gwos/crates}/types/src/offchain/store.rs (100%) rename {crates => gwos/crates}/types/src/prelude.rs (100%) rename {crates => gwos/crates}/types/src/registry_address.rs (100%) rename {crates => gwos/crates}/types/src/signature_message.rs (100%) rename {crates => gwos/crates}/types/src/std_traits.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index d5f6c066f..ef9bfca07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [workspace] members = [ + "gwos/crates/types", + "gwos/crates/common", "crates/challenge", "crates/chain", "crates/config", - "crates/common", "crates/mem-pool", "crates/generator", "crates/traits", "crates/db", "crates/store", - "crates/types", "crates/block-producer", "crates/jsonrpc-types", "crates/rpc-server", @@ -30,7 +30,9 @@ members = [ ] exclude = [ - "gwos-evm/polyjuice-tests" + "gwos-evm/polyjuice-tests", + "gwos/c-uint256-tests", + "gwos/contracts", ] [profile.release] diff --git a/crates/benches/Cargo.toml b/crates/benches/Cargo.toml index 7003ed885..3b0b1a8b1 100644 --- a/crates/benches/Cargo.toml +++ b/crates/benches/Cargo.toml @@ -14,10 +14,10 @@ anyhow = "1.0.66" criterion = { version = "0.3", features = ["html_reports"] } pprof = { version = "0.6", features = ["flamegraph", "criterion"] } gw-store = { path = "../store" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-mem-pool = { path = "../mem-pool" } gw-generator = { path = "../generator" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-traits = { path = "../traits" } gw-db = { path = "../db" } gw-config = { path = "../config" } diff --git a/crates/block-producer/Cargo.toml b/crates/block-producer/Cargo.toml index b9f7986f7..0e54dc184 100644 --- a/crates/block-producer/Cargo.toml +++ b/crates/block-producer/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" [dependencies] gw-challenge = { path = "../challenge" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-chain = { path = "../chain" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-db = { path = "../db" } gw-store = { path = "../store" } gw-generator = { path = "../generator" } diff --git a/crates/block-producer/src/block_producer.rs b/crates/block-producer/src/block_producer.rs index aabc871fb..a6af507cc 100644 --- a/crates/block-producer/src/block_producer.rs +++ b/crates/block-producer/src/block_producer.rs @@ -33,7 +33,7 @@ use gw_types::{ prelude::*, }; use gw_utils::{ - block_timepoint, fee::fill_tx_fee_with_local, genesis_info::CKBGenesisInfo, + fee::fill_tx_fee_with_local, finalized_timepoint, genesis_info::CKBGenesisInfo, local_cells::LocalCellsManager, query_rollup_cell, since::Since, transaction_skeleton::TransactionSkeleton, wallet::Wallet, RollupContext, }; @@ -60,14 +60,14 @@ fn generate_custodian_cells( deposit_cells: &[DepositInfo], ) -> Vec<(CellOutput, Bytes)> { let block_hash: H256 = block.hash().into(); - let block_timepoint = block_timepoint( + let finalized_timepoint = finalized_timepoint( &rollup_context.rollup_config, &rollup_context.fork_config, block.raw().number().unpack(), block.raw().timestamp().unpack(), ); let to_custodian = |deposit| -> _ { - to_custodian_cell(rollup_context, &block_hash, &block_timepoint, deposit) + to_custodian_cell(rollup_context, &block_hash, &finalized_timepoint, deposit) .expect("sanitized deposit") }; diff --git a/crates/block-producer/src/stake.rs b/crates/block-producer/src/stake.rs index 69111c73d..c5092ad45 100644 --- a/crates/block-producer/src/stake.rs +++ b/crates/block-producer/src/stake.rs @@ -20,7 +20,7 @@ use gw_types::{ use gw_utils::local_cells::{ collect_local_and_indexer_cells, CollectLocalAndIndexerCursor, LocalCellsManager, }; -use gw_utils::{block_timepoint, RollupContext}; +use gw_utils::{finalized_timepoint, RollupContext}; pub struct GeneratedStake { pub deps: Vec, @@ -39,7 +39,7 @@ pub async fn generate( local_cells_manager: &LocalCellsManager, ) -> Result { let owner_lock_hash = lock_script.hash(); - let stake_block_timepoint = block_timepoint( + let stake_block_timepoint = finalized_timepoint( &rollup_context.rollup_config, &rollup_context.fork_config, block.raw().number().unpack(), diff --git a/crates/block-producer/src/utils.rs b/crates/block-producer/src/utils.rs index b9a0d6fcc..1f3f339aa 100644 --- a/crates/block-producer/src/utils.rs +++ b/crates/block-producer/src/utils.rs @@ -20,9 +20,6 @@ pub async fn dump_transaction>(dir: P, rpc_client: &RPCClient, tx pub fn global_state_last_finalized_timepoint_to_since(global_state: &GlobalState) -> u64 { match Timepoint::from_full_value(global_state.last_finalized_timepoint().unpack()) { Timepoint::BlockNumber(_) => 0, - Timepoint::Timestamp(time_ms) => { - // ATTENTION: I am not sure if I am do right. Please review intensively. - Since::new_timestamp_seconds(time_ms.saturating_div(1000).saturating_sub(1)).as_u64() - } + Timepoint::Timestamp(time_ms) => Since::new_timestamp_seconds(time_ms / 1000).as_u64(), } } diff --git a/crates/chain/Cargo.toml b/crates/chain/Cargo.toml index 17579302b..3c377a779 100644 --- a/crates/chain/Cargo.toml +++ b/crates/chain/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" [dependencies] gw-challenge = { path = "../challenge" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-generator = { path = "../generator" } gw-mem-pool = { path = "../mem-pool" } gw-store = { path = "../store" } diff --git a/crates/challenge/Cargo.toml b/crates/challenge/Cargo.toml index f90d163de..9cde240d6 100644 --- a/crates/challenge/Cargo.toml +++ b/crates/challenge/Cargo.toml @@ -7,9 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } -gw-types = { path = "../types" } gw-db = { path = "../db" } gw-store = { path = "../store" } gw-generator = { path = "../generator" } diff --git a/crates/generator/Cargo.toml b/crates/generator/Cargo.toml index dba46a154..1178100de 100644 --- a/crates/generator/Cargo.toml +++ b/crates/generator/Cargo.toml @@ -12,8 +12,8 @@ detect-asm = ["ckb-vm/detect-asm", "ckb-vm-aot"] enable-always-success-lock = [] [dependencies] -gw-types = { path = "../types" } -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-store = { path = "../store" } gw-traits = { path = "../traits" } diff --git a/crates/godwoken-bin/Cargo.toml b/crates/godwoken-bin/Cargo.toml index 198a46928..2ad593264 100644 --- a/crates/godwoken-bin/Cargo.toml +++ b/crates/godwoken-bin/Cargo.toml @@ -14,14 +14,14 @@ indicatif = "0.16" gw-block-producer = { path = "../block-producer" } gw-chain = { path = "../chain" } gw-challenge = { path = "../challenge" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-db = { path = "../db" } gw-generator = { path = "../generator" } gw-jsonrpc-types = { path = "../jsonrpc-types" } gw-telemetry = { path = "../telemetry" } gw-store = { path = "../store" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-utils = { path = "../utils" } gw-version = { path = "../version" } gw-metrics = { path = "../metrics" } diff --git a/crates/jsonrpc-types/Cargo.toml b/crates/jsonrpc-types/Cargo.toml index 301f8ba46..beae8b1e9 100644 --- a/crates/jsonrpc-types/Cargo.toml +++ b/crates/jsonrpc-types/Cargo.toml @@ -9,8 +9,8 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"] } faster-hex = "0.4" -gw-types = { path = "../types" } -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types" } +gw-common = { path = "../../gwos/crates/common" } ckb-jsonrpc-types = "0.105.1" ckb-fixed-hash = "0.105.1" anyhow = "1.0" diff --git a/crates/mem-pool/Cargo.toml b/crates/mem-pool/Cargo.toml index e65c2402d..0ba4ee965 100644 --- a/crates/mem-pool/Cargo.toml +++ b/crates/mem-pool/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-types = { path = "../types" } -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types" } +gw-common = { path = "../../gwos/crates/common" } gw-challenge = { path = "../challenge" } gw-generator = { path = "../generator" } gw-store = { path = "../store" } diff --git a/crates/mem-pool/src/withdrawal.rs b/crates/mem-pool/src/withdrawal.rs index bd6261477..0944deae3 100644 --- a/crates/mem-pool/src/withdrawal.rs +++ b/crates/mem-pool/src/withdrawal.rs @@ -7,7 +7,7 @@ use gw_types::{ packed::{CellOutput, L2Block, Script, WithdrawalRequest, WithdrawalRequestExtra}, prelude::*, }; -use gw_utils::{block_timepoint, RollupContext}; +use gw_utils::{finalized_timepoint, RollupContext}; use std::collections::HashMap; use crate::custodian::{ @@ -116,7 +116,7 @@ impl<'a> Generator<'a> { sudt_custodian.map(|sudt| sudt.script.to_owned()) }; let block_hash: H256 = block.hash().into(); - let block_timepoint = block_timepoint( + let finalized_timepoint = finalized_timepoint( &self.rollup_context.rollup_config, &self.rollup_context.fork_config, block.raw().number().unpack(), @@ -126,7 +126,7 @@ impl<'a> Generator<'a> { self.rollup_context, req_extra, &block_hash, - &block_timepoint, + &finalized_timepoint, sudt_script, ) { Ok(output) => output, diff --git a/crates/metrics/Cargo.toml b/crates/metrics/Cargo.toml index 7e67987a0..ae6a45826 100644 --- a/crates/metrics/Cargo.toml +++ b/crates/metrics/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-store = { path = "../store" } gw-telemetry = { path = "../telemetry" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } arc-swap = "1.5" diff --git a/crates/p2p-network/Cargo.toml b/crates/p2p-network/Cargo.toml index 43e1ded12..3efcf71db 100644 --- a/crates/p2p-network/Cargo.toml +++ b/crates/p2p-network/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } gw-utils = { path = "../utils" } tokio = "1" diff --git a/crates/polyjuice-sender-recover/Cargo.toml b/crates/polyjuice-sender-recover/Cargo.toml index 62b49a431..714e66729 100644 --- a/crates/polyjuice-sender-recover/Cargo.toml +++ b/crates/polyjuice-sender-recover/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" [dependencies] anyhow = "1.0" -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-generator = { path = "../generator" } gw-traits = { path = "../traits" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-utils = { path = "../utils" } gw-store = { path = "../store" } log = "0.4" diff --git a/crates/replay-chain/Cargo.toml b/crates/replay-chain/Cargo.toml index b8c0da019..878f838a6 100644 --- a/crates/replay-chain/Cargo.toml +++ b/crates/replay-chain/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" [dependencies] gw-chain = { path = "../chain" } gw-challenge = { path = "../challenge" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-generator = { path = "../generator" } gw-mem-pool = { path = "../mem-pool" } gw-store = { path = "../store" } diff --git a/crates/rpc-client/Cargo.toml b/crates/rpc-client/Cargo.toml index 089f27a86..7a04c5f7c 100644 --- a/crates/rpc-client/Cargo.toml +++ b/crates/rpc-client/Cargo.toml @@ -7,9 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-jsonrpc-types = { path = "../jsonrpc-types" } faster-hex = "0.4" ckb-crypto = "0.105.1" diff --git a/crates/rpc-server/Cargo.toml b/crates/rpc-server/Cargo.toml index b96cc1f6c..371de863a 100644 --- a/crates/rpc-server/Cargo.toml +++ b/crates/rpc-server/Cargo.toml @@ -8,11 +8,11 @@ edition = "2018" [dependencies] gw-challenge = { path = "../challenge" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-chain = { path = "../chain" } gw-db = { path = "../db" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-store = { path = "../store" } gw-traits = { path = "../traits" } gw-generator = { path = "../generator" } diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml index af7c64f7c..d6fd2844d 100644 --- a/crates/store/Cargo.toml +++ b/crates/store/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" [dependencies] gw-db = { path = "../db" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-traits = { path = "../traits" } anyhow = "1.0" arc-swap = "1.5.0" diff --git a/crates/tests/Cargo.toml b/crates/tests/Cargo.toml index ab6a683ef..acbfdbbc7 100644 --- a/crates/tests/Cargo.toml +++ b/crates/tests/Cargo.toml @@ -10,8 +10,8 @@ edition = "2018" scripts = [] [dependencies] -gw-types = { path = "../types", features = ["std", "deprecated"] } -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types", features = ["std", "deprecated"] } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-db = { path = "../db" } gw-store = { path = "../store" } diff --git a/crates/tools/Cargo.toml b/crates/tools/Cargo.toml index 2b19de7e5..cbcdc4b19 100644 --- a/crates/tools/Cargo.toml +++ b/crates/tools/Cargo.toml @@ -28,9 +28,9 @@ ckb-crypto = "0.105.1" ckb-traits = "0.105.1" ckb-dao-utils = "0.105.1" gw-db = { path = "../db" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-generator = { path = "../generator" } gw-jsonrpc-types = { path = "../jsonrpc-types" } gw-utils = { path = "../utils" } diff --git a/crates/traits/Cargo.toml b/crates/traits/Cargo.toml index f8c4f418f..15e74ab7a 100644 --- a/crates/traits/Cargo.toml +++ b/crates/traits/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-types = { path = "../types" } -gw-common = { path = "../common" } +gw-types = { path = "../../gwos/crates/types" } +gw-common = { path = "../../gwos/crates/common" } gw-db = { path = "../db" } anyhow = "1.0.66" diff --git a/crates/tx-filter/Cargo.toml b/crates/tx-filter/Cargo.toml index bcf0c6681..1a171c881 100644 --- a/crates/tx-filter/Cargo.toml +++ b/crates/tx-filter/Cargo.toml @@ -7,10 +7,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-config = { path = "../config" } gw-traits = { path = "../traits" } -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } thiserror = "1.0" log = "0.4" hex = "0.4" diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 13e16ba94..835a5bc24 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -6,9 +6,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gw-types = { path = "../types" } +gw-types = { path = "../../gwos/crates/types" } gw-config = { path = "../config" } -gw-common = { path = "../common" } +gw-common = { path = "../../gwos/crates/common" } gw-rpc-client = { path = "../rpc-client" } gw-jsonrpc-types = { path = "../jsonrpc-types" } gw-store = { path = "../store" } diff --git a/crates/utils/src/calc_finalizing_range.rs b/crates/utils/src/calc_finalizing_range.rs index e64324651..04d0ec2a6 100644 --- a/crates/utils/src/calc_finalizing_range.rs +++ b/crates/utils/src/calc_finalizing_range.rs @@ -1,4 +1,4 @@ -use crate::block_timepoint; +use crate::finalized_timepoint; use anyhow::{Context, Result}; use gw_config::ForkConfig; use gw_store::traits::chain_store::ChainStore; @@ -23,7 +23,7 @@ fn is_older_block_finalized( let older_block = db .get_block(&older_block_hash)? .context("get older block")?; - let older_block_timepoint = block_timepoint( + let older_block_timepoint = finalized_timepoint( rollup_config, fork_config, older_block_number, diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 655d864d1..18391b4ad 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -21,4 +21,4 @@ pub mod withdrawal; pub use calc_finalizing_range::calc_finalizing_range; pub use query_rollup_cell::query_rollup_cell; pub use rollup_context::RollupContext; -pub use timepoint::{block_timepoint, global_state_finalized_timepoint}; +pub use timepoint::{finalized_timepoint, global_state_finalized_timepoint}; diff --git a/crates/utils/src/timepoint.rs b/crates/utils/src/timepoint.rs index 93ee31cba..4c9eba9c5 100644 --- a/crates/utils/src/timepoint.rs +++ b/crates/utils/src/timepoint.rs @@ -3,7 +3,7 @@ use gw_types::core::Timepoint; use gw_types::packed::RollupConfig; use gw_types::prelude::*; -pub fn block_timepoint( +pub fn finalized_timepoint( rollup_config: &RollupConfig, fork_config: &ForkConfig, block_number: u64, diff --git a/gwos/Cargo.lock b/gwos/Cargo.lock index 69eb75a79..c7cad7255 100644 --- a/gwos/Cargo.lock +++ b/gwos/Cargo.lock @@ -86,9 +86,9 @@ dependencies = [ [[package]] name = "fixed-hash" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "static_assertions", ] @@ -127,9 +127,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" dependencies = [ "serde", ] @@ -172,9 +172,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "primitive-types" -version = "0.10.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" +checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" dependencies = [ "fixed-hash", "impl-rlp", diff --git a/gwos/Cargo.toml b/gwos/Cargo.toml deleted file mode 100644 index 38a998129..000000000 --- a/gwos/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[workspace] -members = [ - "c-uint256-tests", -] - -[profile.release] -overflow-checks = true - -[profile.release.build-override] -opt-level = 3 - -[profile.bench.build-override] -opt-level = 3 - diff --git a/gwos/c-uint256-tests/src/bindings.rs b/gwos/c-uint256-tests/src/bindings.rs deleted file mode 100644 index 68fd6f90e..000000000 --- a/gwos/c-uint256-tests/src/bindings.rs +++ /dev/null @@ -1,168 +0,0 @@ -/* automatically generated by rust-bindgen 0.59.2 */ - -pub const true_: u32 = 1; -pub const false_: u32 = 0; -pub const INT8_MIN: i32 = -128; -pub const INT16_MIN: i32 = -32768; -pub const INT32_MIN: i32 = -2147483648; -pub const INT64_MIN: i64 = -9223372036854775808; -pub const INT8_MAX: u32 = 127; -pub const INT16_MAX: u32 = 32767; -pub const INT32_MAX: u32 = 2147483647; -pub const INT64_MAX: u64 = 9223372036854775807; -pub const UINT8_MAX: u32 = 255; -pub const UINT16_MAX: u32 = 65535; -pub const UINT32_MAX: u32 = 4294967295; -pub const UINT64_MAX: i32 = -1; -pub const SIZE_MAX: i32 = -1; -pub type size_t = ::std::os::raw::c_ulong; -pub type ssize_t = ::std::os::raw::c_long; -extern "C" { - pub fn memset( - dest: *mut ::std::os::raw::c_void, - c: ::std::os::raw::c_int, - n: ::std::os::raw::c_ulong, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn memcpy( - dest: *mut ::std::os::raw::c_void, - src: *const ::std::os::raw::c_void, - n: ::std::os::raw::c_ulong, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn memcmp( - vl: *const ::std::os::raw::c_void, - vr: *const ::std::os::raw::c_void, - n: ::std::os::raw::c_ulong, - ) -> ::std::os::raw::c_int; -} -pub type WT = size_t; -extern "C" { - pub fn memmove( - dest: *mut ::std::os::raw::c_void, - src: *const ::std::os::raw::c_void, - n: ::std::os::raw::c_ulong, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn strcpy( - d: *mut ::std::os::raw::c_char, - s: *const ::std::os::raw::c_char, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - pub fn strlen(s: *const ::std::os::raw::c_char) -> ::std::os::raw::c_ulong; -} -extern "C" { - pub fn strcmp( - l: *const ::std::os::raw::c_char, - r: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn malloc(size: ::std::os::raw::c_ulong) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn free(ptr: *mut ::std::os::raw::c_void); -} -extern "C" { - pub fn calloc( - nmemb: ::std::os::raw::c_ulong, - size: ::std::os::raw::c_ulong, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn realloc( - ptr: *mut ::std::os::raw::c_void, - size: ::std::os::raw::c_ulong, - ) -> *mut ::std::os::raw::c_void; -} -pub type cmpfun = ::std::option::Option< - unsafe extern "C" fn( - arg1: *const ::std::os::raw::c_void, - arg2: *const ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, ->; -extern "C" { - pub fn qsort(base: *mut ::std::os::raw::c_void, nel: size_t, width: size_t, cmp: cmpfun); -} -extern "C" { - pub fn bsearch( - key: *const ::std::os::raw::c_void, - base: *const ::std::os::raw::c_void, - nel: size_t, - width: size_t, - cmp: ::std::option::Option< - unsafe extern "C" fn( - arg1: *const ::std::os::raw::c_void, - arg2: *const ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn printf(format: *const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn _start(); -} -#[repr(C)] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct uint256_t { - pub array: [u32; 8usize], -} -#[test] -fn bindgen_test_layout_uint256_t() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(uint256_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(uint256_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).array as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(uint256_t), - "::", - stringify!(array) - ) - ); -} -extern "C" { - pub fn gw_uint256_zero(num: *mut uint256_t); -} -extern "C" { - pub fn gw_uint256_one(num: *mut uint256_t); -} -extern "C" { - pub fn gw_uint256_max(num: *mut uint256_t); -} -extern "C" { - pub fn gw_uint256_overflow_add( - a: uint256_t, - b: uint256_t, - sum: *mut uint256_t, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn gw_uint256_underflow_sub( - a: uint256_t, - b: uint256_t, - rem: *mut uint256_t, - ) -> ::std::os::raw::c_int; -} -pub const GW_UINT256_SMALLER: ::std::os::raw::c_int = -1; -pub const GW_UINT256_EQUAL: ::std::os::raw::c_int = 0; -pub const GW_UINT256_LARGER: ::std::os::raw::c_int = 1; -pub type _bindgen_ty_1 = ::std::os::raw::c_int; -extern "C" { - pub fn gw_uint256_cmp(a: uint256_t, b: uint256_t) -> ::std::os::raw::c_int; -} diff --git a/gwos/c/Makefile b/gwos/c/Makefile index 72b380ab2..2953db46b 100644 --- a/gwos/c/Makefile +++ b/gwos/c/Makefile @@ -10,8 +10,6 @@ VALIDATOR_FLAGS := -DGW_VALIDATOR LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections MOLC := moleculec MOLC_VERSION := 0.7.2 -PROTOCOL_VERSION := bf76c19c43e4e59cfaba871e722681bf7d3d6948 -PROTOCOL_SCHEMA_URL := https://raw.githubusercontent.com/nervosnetwork/godwoken/${PROTOCOL_VERSION}/crates/types/schemas # docker pull nervos/ckb-riscv-gnu-toolchain:gnu-bionic-20191012 BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:aae8a3f79705f67d505d1f1d5ddc694a4fd537ed1c7e9622420a470d59ba2ec3 @@ -130,13 +128,10 @@ fmt: check-moleculec-version: test "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" = ${MOLC_VERSION} -%.mol: - curl -L -o $@ ${PROTOCOL_SCHEMA_URL}/$@ - -build/blockchain.h: blockchain.mol +build/blockchain.h: ../crates/types/schemas/blockchain.mol ${MOLC} --language c --schema-file $< > $@ -build/godwoken.h: godwoken.mol +build/godwoken.h: ../crates/types/schemas/godwoken.mol ${MOLC} --language c --schema-file $< > $@ install-tools: diff --git a/gwos/c/account_lock_lib/secp256k1.c b/gwos/c/account_lock_lib/secp256k1.c deleted file mode 100644 index 96a6eb86c..000000000 --- a/gwos/c/account_lock_lib/secp256k1.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "blake2b.h" -#include "secp256k1_helper.h" - -/* constants */ -#define SIGNATURE_SIZE 65 -#define PUBKEY_SIZE 65 -#define RECID_INDEX 64 - -/* errors */ -#define ERROR_SECP_SERIALIZE_PUBKEY 140 -#define ERROR_SECP_RECOVER_PUBKEY 141 -#define ERROR_SECP_PARSE_SIGNATURE 142 - -int recover_secp256k1_uncompressed_key(uint8_t message[32], - uint8_t signature[SIGNATURE_SIZE], - uint8_t output_uncompressed_pubkey[65]) { - - // Setup secp256k1 data - secp256k1_context context; - uint8_t secp_data[CKB_SECP256K1_DATA_SIZE]; - int ret = ckb_secp256k1_custom_verify_only_initialize(&context, secp_data); - if (ret != 0) { - printf("Error occured when initializing secp256k1"); - return ret; - } - - secp256k1_ecdsa_recoverable_signature recoverable_signature; - if (secp256k1_ecdsa_recoverable_signature_parse_compact( - &context, &recoverable_signature, signature, - signature[RECID_INDEX]) == 0) { - printf("Error occured when parsing recoverable signature"); - return ERROR_SECP_PARSE_SIGNATURE; - } - - // Recover pubkey - secp256k1_pubkey pubkey; - if (secp256k1_ecdsa_recover(&context, &pubkey, &recoverable_signature, - message) != 1) { - printf("Error occured when recovering pubkey"); - return ERROR_SECP_RECOVER_PUBKEY; - } - - // Check pubkey hash - size_t pubkey_size = PUBKEY_SIZE; - if (secp256k1_ec_pubkey_serialize(&context, output_uncompressed_pubkey, - &pubkey_size, &pubkey, - SECP256K1_EC_UNCOMPRESSED) != 1) { - printf("Error occued when serializing pubkey"); - return ERROR_SECP_SERIALIZE_PUBKEY; - } - - return CKB_SUCCESS; -} diff --git a/gwos/c/blake2b_def.h b/gwos/c/blake2b_def.h new file mode 100644 index 000000000..eb1c16808 --- /dev/null +++ b/gwos/c/blake2b_def.h @@ -0,0 +1,11 @@ +/* To avoid duplication of blake2 symbols, we only declare blake2b + gw-hash crate provides the implementation of symbols */ + +#ifndef BLAKE2_H +#define BLAKE2_IMPL_H +#define BLAKE2_REF_C + +#include "blake2b.h" + +#endif +/* end of blake2b declaration */ diff --git a/gwos/c/blockchain.mol b/gwos/c/blockchain.mol deleted file mode 100644 index 835e15558..000000000 --- a/gwos/c/blockchain.mol +++ /dev/null @@ -1,120 +0,0 @@ -/* ckb v0.100.0-rc2 */ -/* Basic Types */ - -// The `UintN` is used to store a `N` bits unsigned integer -// as a byte array in little endian. -array Uint16 [byte; 2]; -array Uint32 [byte; 4]; -array Uint64 [byte; 8]; -array Uint128 [byte; 16]; -array Byte32 [byte; 32]; -array Uint256 [byte; 32]; - -vector Bytes ; -option BytesOpt (Bytes); - -vector BytesVec ; -vector Byte32Vec ; - -/* Types for Chain */ - -option ScriptOpt (Script); - -array ProposalShortId [byte; 10]; - -vector UncleBlockVec ; -vector TransactionVec ; -vector ProposalShortIdVec ; -vector CellDepVec ; -vector CellInputVec ; -vector CellOutputVec ; - -table Script { - code_hash: Byte32, - hash_type: byte, - args: Bytes, -} - -struct OutPoint { - tx_hash: Byte32, - index: Uint32, -} - -struct CellInput { - since: Uint64, - previous_output: OutPoint, -} - -table CellOutput { - capacity: Uint64, - lock: Script, - type_: ScriptOpt, -} - -struct CellDep { - out_point: OutPoint, - dep_type: byte, -} - -table RawTransaction { - version: Uint32, - cell_deps: CellDepVec, - header_deps: Byte32Vec, - inputs: CellInputVec, - outputs: CellOutputVec, - outputs_data: BytesVec, -} - -table Transaction { - raw: RawTransaction, - witnesses: BytesVec, -} - -struct RawHeader { - version: Uint32, - compact_target: Uint32, - timestamp: Uint64, - number: Uint64, - epoch: Uint64, - parent_hash: Byte32, - transactions_root: Byte32, - proposals_hash: Byte32, - extra_hash: Byte32, - dao: Byte32, -} - -struct Header { - raw: RawHeader, - nonce: Uint128, -} - -table UncleBlock { - header: Header, - proposals: ProposalShortIdVec, -} - -table Block { - header: Header, - uncles: UncleBlockVec, - transactions: TransactionVec, - proposals: ProposalShortIdVec, -} - -table BlockV1 { - header: Header, - uncles: UncleBlockVec, - transactions: TransactionVec, - proposals: ProposalShortIdVec, - extension: Bytes, -} - -table CellbaseWitness { - lock: Script, - message: Bytes, -} - -table WitnessArgs { - lock: BytesOpt, // Lock args - input_type: BytesOpt, // Type args for input - output_type: BytesOpt, // Type args for output -} diff --git a/gwos/c/godwoken.mol b/gwos/c/godwoken.mol deleted file mode 100644 index f14481033..000000000 --- a/gwos/c/godwoken.mol +++ /dev/null @@ -1,411 +0,0 @@ -import blockchain; - -vector Uint32Vec ; - -struct BlockMerkleState { - merkle_root: Byte32, - count: Uint64, -} - -struct AccountMerkleState { - merkle_root: Byte32, - count: Uint32, -} - -struct GlobalStateV0 { - rollup_config_hash: Byte32, - account: AccountMerkleState, - block: BlockMerkleState, - reverted_block_root: Byte32, - tip_block_hash: Byte32, - last_finalized_block_number: Uint64, - // 0: running, 1: halting - status: byte, -} - -struct GlobalState { - rollup_config_hash: Byte32, - account: AccountMerkleState, - block: BlockMerkleState, - reverted_block_root: Byte32, - tip_block_hash: Byte32, - tip_block_timestamp: Uint64, - last_finalized_block_number: Uint64, - // 0: running, 1: halting - status: byte, - version: byte, -} - -struct AllowedTypeHash { - type_: byte, - hash: Byte32, -} - -vector AllowedTypeHashVec ; - -// allowed eoa: -// 0: unknown, 1: eth, 2: tron -// -// allowed contract: -// 0: unknown, 1: meta, 2: sudt, 3: polyjuice, 4: eth addr reg -table RollupConfig { - l1_sudt_script_type_hash: Byte32, - custodian_script_type_hash: Byte32, - deposit_script_type_hash: Byte32, - withdrawal_script_type_hash: Byte32, - challenge_script_type_hash: Byte32, - stake_script_type_hash: Byte32, - l2_sudt_validator_script_type_hash: Byte32, - burn_lock_hash: Byte32, - required_staking_capacity: Uint64, - challenge_maturity_blocks: Uint64, - finality_blocks: Uint64, - reward_burn_rate: byte, // * reward_burn_rate / 100 - chain_id: Uint64, // chain id - allowed_eoa_type_hashes: AllowedTypeHashVec, // list of script code_hash allowed an EOA(external owned account) to use - allowed_contract_type_hashes: AllowedTypeHashVec, // list of script code_hash allowed a contract account to use -} - -table RawL2Transaction { - // chain id - chain_id: Uint64, - from_id: Uint32, - to_id: Uint32, - nonce: Uint32, - args: Bytes, -} - -table L2Transaction { - raw: RawL2Transaction, - signature: Bytes, -} - -vector L2TransactionVec ; - -struct SubmitTransactions { - tx_witness_root: Byte32, - tx_count: Uint32, - // hash(account_root | account_count) before apply all txs - prev_state_checkpoint: Byte32, -} - -struct SubmitWithdrawals { - withdrawal_witness_root: Byte32, - withdrawal_count: Uint32, -} - -table RawL2Block { - number: Uint64, - // In registry address format: registry_id (4 bytes) | address len (4 bytes) | address (n bytes) - block_producer: Bytes, - parent_block_hash: Byte32, - stake_cell_owner_lock_hash: Byte32, - timestamp: Uint64, - prev_account: AccountMerkleState, - post_account: AccountMerkleState, - // hash(account_root | account_count) of each withdrawals & transactions - state_checkpoint_list: Byte32Vec, - submit_withdrawals: SubmitWithdrawals, - submit_transactions: SubmitTransactions, -} - -vector RawL2BlockVec ; - -table L2Block { - raw: RawL2Block, - kv_state: KVPairVec, - kv_state_proof: Bytes, - transactions: L2TransactionVec, - block_proof: Bytes, - withdrawals: WithdrawalRequestVec, -} - -table DepositRequest { - // CKB amount - capacity: Uint64, - // SUDT amount - amount: Uint128, - sudt_script_hash: Byte32, - script: Script, - // Deposit to a Godwoken registry - registry_id: Uint32, -} - -vector DepositRequestVec ; - -struct RawWithdrawalRequest { - nonce: Uint32, - // chain id - chain_id: Uint64, - // CKB amount - capacity: Uint64, - // SUDT amount - amount: Uint128, - sudt_script_hash: Byte32, - // layer2 account_script_hash - account_script_hash: Byte32, - // withdrawal registry ID - registry_id: Uint32, - // layer1 lock to withdraw after challenge period - owner_lock_hash: Byte32, - // withdrawal fee, paid to block producer - fee: Uint128, -} - -vector WithdrawalRequestVec ; - -table WithdrawalRequest { - raw: RawWithdrawalRequest, - signature: Bytes, -} - -// --- contract execution --- - -struct KVPair { k: Byte32, v: Byte32, } -vector KVPairVec ; - -table BlockInfo { - block_producer: Bytes, - number: Uint64, - timestamp: Uint64, -} - -// --- end of contract execution --- - -// --- deposit lock --- -// a rollup_type_hash exists before this args, to make args friendly to prefix search -table DepositLockArgs { - // layer1 lock hash - owner_lock_hash: Byte32, - layer2_lock: Script, - cancel_timeout: Uint64, - registry_id: Uint32, -} -// --- end of deposit lock --- - -// --- custodian lock --- -// a rollup_type_hash exists before this args, to make args friendly to prefix search -table CustodianLockArgs { - deposit_block_hash: Byte32, - deposit_block_timepoint: Uint64, - // used for revert this cell to deposit request cell - // after finalize, this lock is meaningless - deposit_lock_args: DepositLockArgs, -} - -struct UnlockCustodianViaRevertWitness { - deposit_lock_hash: Byte32, -} - -// --- end of custodian lock --- - -// --- withdrawal lock --- -// a rollup_type_hash exists before this args, to make args friendly to prefix search -struct WithdrawalLockArgs { - withdrawal_block_hash: Byte32, - withdrawal_block_timepoint: Uint64, - account_script_hash: Byte32, - // layer1 lock to withdraw after challenge period - owner_lock_hash: Byte32, -} - -union UnlockWithdrawalWitness { - UnlockWithdrawalViaFinalize, - UnlockWithdrawalViaRevert, -} -table UnlockWithdrawalViaFinalize { -} -struct UnlockWithdrawalViaRevert { - custodian_lock_hash: Byte32, -} -// --- end of withdrawal lock --- - -// --- stake lock --- -// a rollup_type_hash exists before this args, to make args friendly to prefix search -struct StakeLockArgs { - owner_lock_hash: Byte32, - stake_block_timepoint: Uint64, -} -// --- end of stake lock --- - -// --- builtin Meta contract --- -union MetaContractArgs { - CreateAccount, - BatchCreateEthAccounts, -} - -struct Fee { - // registry id - registry_id: Uint32, - // amount in CKB - amount: Uint128, -} - -table CreateAccount { - script: Script, - fee: Fee, -} - -table BatchCreateEthAccounts { - scripts: ScriptVec, - fee: Fee, -} -// --- end of Meta contract - -// --- layer2 SUDT --- -union SUDTArgs { - SUDTQuery, - SUDTTransfer, -} - -table SUDTQuery { - // Godwoken registry address: (registry_id (4 bytes) | address len(4 bytes) | address) - address: Bytes, -} - -table SUDTTransfer { - // Godwoken registry address: (registry_id (4 bytes) | address len(4 bytes) | address) - to_address: Bytes, - amount: Uint256, - // paid fee(ckb) - fee: Fee, -} -// --- end of layer2 SUDT --- - -// --- challenge --- - -struct ChallengeTarget { - block_hash: Byte32, - // index of the challenge target - target_index: Uint32, - // 0: tx execution, 1: tx signature, 2: withdrawal signature - target_type: byte, -} - -// a rollup_type_hash exists before this args, to make args friendly to prefix search -table ChallengeLockArgs { - target: ChallengeTarget, - // layer1 lock to receive the rewards - rewards_receiver_lock: Script, -} - -// witness to prove the validity of challenge -table ChallengeWitness { - raw_l2block: RawL2Block, - block_proof: Bytes, // block proof -} - -vector ScriptVec