From d6656ec626348175e498caa0be655b5f6b2a45e0 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Fri, 8 Dec 2023 17:00:28 +0800 Subject: [PATCH 01/26] Fix bug: When using dynamic linking, auth will be loaded repeatedly. --- c/ckb_auth.h | 15 ++++++++++----- tests/auth-c-lock/auth_c_lock.c | 11 +++++++++-- .../contracts/auth-rust-demo/src/entry.rs | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index 325e623..a42711a 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -120,19 +120,24 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id, uint32_t pubkey_hash_size); static uint8_t g_code_buff[300 * 1024] __attribute__((aligned(RISCV_PGSIZE))); +static void* g_code_handle; int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, uint32_t signature_size, const uint8_t *message32) { int err = 0; if (entry->entry_category == EntryCategoryDynamicLinking) { - void *handle = NULL; size_t consumed_size = 0; - err = ckb_dlopen2(entry->code_hash, entry->hash_type, g_code_buff, - sizeof(g_code_buff), &handle, &consumed_size); - if (err != 0) return err; + + if (!g_code_handle) { + err = ckb_dlopen2(entry->code_hash, entry->hash_type, g_code_buff, + sizeof(g_code_buff), &g_code_handle, &consumed_size); + if (err != 0) { + return err; + } + } ckb_auth_validate_t func = - (ckb_auth_validate_t)ckb_dlsym(handle, "ckb_auth_validate"); + (ckb_auth_validate_t)ckb_dlsym(g_code_handle, "ckb_auth_validate"); if (func == 0) { return CKB_INVALID_DATA; } diff --git a/tests/auth-c-lock/auth_c_lock.c b/tests/auth-c-lock/auth_c_lock.c index fd5d864..fa09113 100644 --- a/tests/auth-c-lock/auth_c_lock.c +++ b/tests/auth-c-lock/auth_c_lock.c @@ -221,6 +221,13 @@ int main() { break; } - return ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, - msg32); + ret = ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, msg32); + if (ret) { + return ret; + } + ret = ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, msg32); + if (ret) { + return ret; + } + return 0; } diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs index 46d5283..6668774 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs @@ -72,6 +72,7 @@ pub fn main() -> Result<(), Error> { .unwrap(), }; + ckb_auth(&entry, &id, &signature, &message)?; ckb_auth(&entry, &id, &signature, &message)?; Ok(()) From 8f5ee084f1f955e67e36b1dc18af63be31ea8d3c Mon Sep 17 00:00:00 2001 From: joii2020 Date: Thu, 7 Dec 2023 16:12:25 +0800 Subject: [PATCH 02/26] Update Readme --- tests/README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/README.md b/tests/README.md index 08bcc61..a3306ce 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,4 +1,4 @@ -This directory contains all the test code of ckb-auth +This directory encompasses all the testing code for `ckb-auth` ## Directory Structure @@ -12,20 +12,20 @@ This directory contains all the test code of ckb-auth └── bin ``` -* The `ckb-auth` is just a library for other contracts to call. For testing purposes, here is a complete contract implemented for testing `auth-c-lock` and `auth-rust-lock`. -* In `auth-rust-lock` there exists a simple test for testing `ckb-auth-rs`. -* `auth-c-tests` tests the ckb-auth library, including various scenarios. -* `auth-spawn-tests` uses ckb-debugger to test some typical scenarios, including tests for cardano and ripple. -* `bin` is not in the repositorie. It is a temporary directory created after calling `make install-all`. -* The tools are installed in the `bin`, because the specified version needs to be used here to prevent conflicts. -* Take the above, after installation, there will be two files: `.crates.toml` and `.crates2.json`. These two were created by cargo. +* `ckb-auth` functions as a library for other contracts to invoke. For testing purposes, a comprehensive contract has been implemented to test `auth-c-lock` and `auth-rust-lock`. +* In `auth-rust-lock`, a straightforward test exists to assess `ckb-auth-rs`. +* `auth-c-tests` tests the ckb-auth library, encompassing various scenarios. +* `auth-spawn-tests` utilizes ckb-debugger to conduct tests on typical scenarios, including those for cardano and ripple. +* The `bin` directory is not part of the repository. It is a temporary directory created post the `make install-all` command. +* Tools are installed in the `bin` directory, as a specific version is required here to avoid conflicts. +* Post-installation, two files, namely `.crates.toml` and `.crates2.json`, are generated by cargo. | Directory | Description | | ----------------- | ----------------------------------------- | | auth-c-lock | C language contract | | auth-rust-lock | Rust contract | -| auth-c-tests | test ckb-auth | -| auth-spawn-tests | test uses ckb-debugger | -| bin | Tools needed for testing and chain | +| auth-c-tests | Test ckb-auth | +| auth-spawn-tests | Test utilizing ckb-debugger | +| bin | Tools necessary for testing and chain | From 2c63cf0c63fd94cb66ade0331e7e696997ca164c Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 12 Dec 2023 17:54:56 +0800 Subject: [PATCH 03/26] test support auth-rust-lock --- tests/Makefile | 4 +- tests/auth-c-tests/src/lib.rs | 48 ++++++++++++++----- tests/auth-c-tests/src/tests/mod.rs | 6 ++- .../contracts/auth-rust-demo/src/entry.rs | 10 +++- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index f332a4e..b4e89c4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -24,8 +24,8 @@ all_tests: build-auth-rust-lock: export PATH=$(shell pwd)/bin/:"$(PATH)" && \ cd auth-rust-lock && \ - capsule build && \ - cp build/debug/auth-rust-demo ../../build + capsule build --release && \ + cp build/release/auth-rust-demo ../../build build-auth-lock: build-auth-rust-lock cd .. && make -f tests/auth-c-lock/Makefile all-via-docker diff --git a/tests/auth-c-tests/src/lib.rs b/tests/auth-c-tests/src/lib.rs index 207195d..1ba1dff 100644 --- a/tests/auth-c-tests/src/lib.rs +++ b/tests/auth-c-tests/src/lib.rs @@ -49,7 +49,10 @@ lazy_static! { Bytes::from(&include_bytes!("../../../build/auth")[..]); pub static ref LIBECC_AUTH_PROGRAM: Bytes = Bytes::from(&include_bytes!("../../../build/auth_libecc")[..]); - pub static ref AUTH_C_LOCK: Bytes = Bytes::from(&include_bytes!("../../../build/auth_c_lock")[..]); + pub static ref AUTH_C_LOCK: Bytes = + Bytes::from(&include_bytes!("../../../build/auth_c_lock")[..]); + pub static ref AUTH_RUST_LOCK: Bytes = + Bytes::from(&include_bytes!("../../../build/auth-rust-demo")[..]); pub static ref SECP256K1_DATA_BIN: Bytes = Bytes::from(&include_bytes!("../../../build/secp256k1_data_20210801")[..]); pub static ref ALWAYS_SUCCESS: Bytes = @@ -394,10 +397,10 @@ fn append_cells_deps( let sighash_all_out_point = append_cell_deps( dummy, rng, - if config.auth_bin.is_some() { - config.auth_bin.as_ref().unwrap() - } else { - &AUTH_C_LOCK + match &config.auth_lock_type { + TestConfigAuthLockType::C => &AUTH_C_LOCK, + TestConfigAuthLockType::Rust => &AUTH_RUST_LOCK, + TestConfigAuthLockType::Rand(auth_bin) => auth_bin, }, ); let sighash_dl_out_point = append_cell_deps(dummy, rng, &auth_program::get_auth_program()); @@ -478,12 +481,18 @@ pub fn gen_tx_with_grouped_args( ) -> TransactionView { let (dummy_capacity, mut tx_builder) = append_cells_deps(dummy, config, rng); - let sighash_all_cell_data_hash = CellOutput::calc_data_hash(if config.auth_bin.is_some() { - config.auth_bin.as_ref().unwrap() - } else { - &AUTH_C_LOCK + let sighash_all_cell_data_hash = CellOutput::calc_data_hash(match &config.auth_lock_type { + TestConfigAuthLockType::C => &AUTH_C_LOCK, + TestConfigAuthLockType::Rust => &AUTH_RUST_LOCK, + TestConfigAuthLockType::Rand(auth_bin) => auth_bin, }); + let sighash_all_cell_hash_type = if config.auth_lock_type == TestConfigAuthLockType::Rust { + ScriptHashType::Data2 + } else { + ScriptHashType::Data2 + }; + for (args, inputs_size) in grouped_args { // setup dummy input unlock script for _ in 0..inputs_size { @@ -496,7 +505,7 @@ pub fn gen_tx_with_grouped_args( let script = Script::new_builder() .args(args.pack()) .code_hash(sighash_all_cell_data_hash.clone()) - .hash_type(ScriptHashType::Data2.into()) + .hash_type(sighash_all_cell_hash_type.into()) .build(); let previous_output_cell = CellOutput::new_builder() .capacity(dummy_capacity.pack()) @@ -535,6 +544,13 @@ pub enum TestConfigIncorrectSing { Smaller, } +#[derive(PartialEq, Eq)] +pub enum TestConfigAuthLockType { + C, + Rust, + Rand(Bytes), +} + pub struct TestConfig { pub auth: Box, pub entry_category_type: EntryCategoryType, @@ -546,7 +562,8 @@ pub struct TestConfig { pub incorrect_sign: bool, pub incorrect_sign_size: TestConfigIncorrectSing, - pub auth_bin: Option, + pub auth_lock_type: TestConfigAuthLockType, + // pub auth_bin: Option, pub script_hash_type: Option, } @@ -565,7 +582,7 @@ impl TestConfig { incorrect_msg: false, incorrect_sign: false, incorrect_sign_size: TestConfigIncorrectSing::None, - auth_bin: None, + auth_lock_type: TestConfigAuthLockType::C, script_hash_type: None, } } @@ -591,7 +608,12 @@ pub fn do_gen_args(config: &TestConfig, pub_key_hash: Option>) -> Bytes let hash_type: u8 = match &config.script_hash_type { Some(t) => t.clone(), - None => ScriptHashType::Data2.into(), + None => if config.auth_lock_type == TestConfigAuthLockType::Rust { + ScriptHashType::Data2 + } else { + ScriptHashType::Data2 + } + .into(), }; let mut entry_type = EntryType { diff --git a/tests/auth-c-tests/src/tests/mod.rs b/tests/auth-c-tests/src/tests/mod.rs index 488131d..f09f5be 100644 --- a/tests/auth-c-tests/src/tests/mod.rs +++ b/tests/auth-c-tests/src/tests/mod.rs @@ -22,7 +22,7 @@ use crate::{ gen_args, gen_tx, gen_tx_scripts_verifier, gen_tx_with_grouped_args, sign_tx, Auth, AuthAlgorithmIdType, AuthErrorCodeType, BitcoinAuth, BitcoinSignVType, CKbAuth, CkbMultisigAuth, DogecoinAuth, DummyDataLoader, EosAuth, EthereumAuth, LitecoinAuth, - SchnorrAuth, TestConfig, TronAuth, MAX_CYCLES, + SchnorrAuth, TestConfig, TestConfigAuthLockType, TronAuth, MAX_CYCLES, }; fn verify_unit(config: &TestConfig) -> Result { @@ -64,7 +64,9 @@ fn assert_result_error(res: Result, des: &str, err_codes: } fn unit_test_success(auth: &Box, run_type: EntryCategoryType) { - let config = TestConfig::new(auth, run_type, 1); + let mut config = TestConfig::new(auth, run_type, 1); + assert_result_ok(verify_unit(&config), ""); + config.auth_lock_type = TestConfigAuthLockType::Rust; assert_result_ok(verify_unit(&config), ""); } diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs index 6668774..9adb73e 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs @@ -44,6 +44,7 @@ pub fn main() -> Result<(), Error> { 0 => ScriptHashType::Data, 1 => ScriptHashType::Type, 2 => ScriptHashType::Data1, + 4 => ScriptHashType::Data1, // TODO ckb-std 0.14.3 does not support Data2 yet _ => { return Err(Error::ArgsError); } @@ -52,6 +53,13 @@ pub fn main() -> Result<(), Error> { let witness_args = load_witness_args(0, Source::GroupInput).map_err(|_| Error::WitnessError)?; + + ckb_std::debug!( + "-- ckb-auth, entry_category({}), hash_type({}) ", + entry_type, + args[53] + ); + witness_args .lock() .to_opt() @@ -73,7 +81,7 @@ pub fn main() -> Result<(), Error> { }; ckb_auth(&entry, &id, &signature, &message)?; - ckb_auth(&entry, &id, &signature, &message)?; + // ckb_auth(&entry, &id, &signature, &message)?; Ok(()) } From c571024a7e1a8f52dccad15fbdc3557f6113ce19 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 12 Dec 2023 17:56:10 +0800 Subject: [PATCH 04/26] ckb-auth-rs dl context in static memory --- ckb-auth-rs/Cargo.toml | 4 ++++ ckb-auth-rs/src/ckb_auth.rs | 18 +++++++++++++----- tests/auth-c-tests/Cargo.lock | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ckb-auth-rs/Cargo.toml b/ckb-auth-rs/Cargo.toml index d431681..d96d48c 100644 --- a/ckb-auth-rs/Cargo.toml +++ b/ckb-auth-rs/Cargo.toml @@ -8,9 +8,13 @@ edition = "2021" [features] default = [] ckb2023 = ["ckb-std/ckb2023"] +dynamic-library-memory = [] +dynamic-library-memory2 = [] +dynamic-library-memory3 = [] [dependencies] ckb-std = "0.14.3" +lazy_static = { version = "1.4.0", features = ["spin_no_std"] } [target.'cfg(target_arch = "riscv64")'.dependencies] hex = { version = "0.4.3", default-features = false, features = ["alloc"]} diff --git a/ckb-auth-rs/src/ckb_auth.rs b/ckb-auth-rs/src/ckb_auth.rs index 36c742b..62ffb0f 100644 --- a/ckb-auth-rs/src/ckb_auth.rs +++ b/ckb-auth-rs/src/ckb_auth.rs @@ -1,6 +1,7 @@ extern crate alloc; use crate::{CkbAuthError, CkbAuthType, CkbEntryType, EntryCategoryType}; +use alloc::boxed::Box; use alloc::collections::BTreeMap; use alloc::ffi::CString; use alloc::format; @@ -12,7 +13,7 @@ use ckb_std::{ ckb_types::core::ScriptHashType, dynamic_loading_c_impl::{CKBDLContext, Library, Symbol}, }; -use core::mem::size_of_val; +use core::mem::size_of; use hex::encode; pub fn ckb_auth( @@ -74,7 +75,7 @@ fn ckb_auth_exec( Ok(()) } -type DLContext = CKBDLContext<[u8; 512 * 1024]>; +type DLContext = CKBDLContext<[u8; 256 * 1024]>; type CkbAuthValidate = unsafe extern "C" fn( auth_algorithm_id: u8, signature: *const u8, @@ -88,11 +89,15 @@ type CkbAuthValidate = unsafe extern "C" fn( const EXPORTED_FUNC_NAME: &str = "ckb_auth_validate"; struct CKBDLLoader { - pub context: DLContext, + pub context: Box, pub context_used: usize, pub loaded_lib: BTreeMap<[u8; 33], Library>, } +lazy_static::lazy_static! { + static ref G_DL_CONTEXT: DLContext = unsafe { DLContext::new() }; +} + static mut G_CKB_DL_LOADER: Option = None; impl CKBDLLoader { pub fn get() -> &'static mut Self { @@ -109,7 +114,10 @@ impl CKBDLLoader { fn new() -> Self { Self { - context: unsafe { DLContext::new() }, + context: unsafe { + let dl_ctx: &DLContext = &G_DL_CONTEXT; + Box::from_raw(dl_ctx as *const DLContext as *mut DLContext) + }, context_used: 0, loaded_lib: BTreeMap::new(), } @@ -130,7 +138,7 @@ impl CKBDLLoader { }; if !has_lib { - let size = size_of_val(&self.context); + let size = size_of::(); let lib = self .context .load_with_offset(code_hash, hash_type, self.context_used, size) diff --git a/tests/auth-c-tests/Cargo.lock b/tests/auth-c-tests/Cargo.lock index e45465d..a92d7e1 100644 --- a/tests/auth-c-tests/Cargo.lock +++ b/tests/auth-c-tests/Cargo.lock @@ -815,6 +815,7 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", + "lazy_static", ] [[package]] @@ -2469,6 +2470,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "libc" From b5083c6273a552fc1690eaa0d746862042574f55 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 12 Dec 2023 18:32:27 +0800 Subject: [PATCH 05/26] Fix bug in auht-rust-lock --- ckb-auth-rs/src/lib.rs | 2 +- .../contracts/auth-rust-demo/src/entry.rs | 19 ++++++++++++------- tests/auth-spawn-tests/Cargo.lock | 4 ++++ tools/ckb-auth-cli/Cargo.lock | 10 ++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ckb-auth-rs/src/lib.rs b/ckb-auth-rs/src/lib.rs index ec8408d..abe830e 100644 --- a/ckb-auth-rs/src/lib.rs +++ b/ckb-auth-rs/src/lib.rs @@ -54,7 +54,7 @@ impl TryFrom for AuthAlgorithmIdType { type Error = CkbAuthError; fn try_from(value: u8) -> Result { if (value >= AuthAlgorithmIdType::Ckb.into() - && value <= AuthAlgorithmIdType::Iso97962.into()) + && value <= AuthAlgorithmIdType::Secp256r1.into()) || value == AuthAlgorithmIdType::OwnerLock.into() { Ok(unsafe { transmute(value) }) diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs index 9adb73e..fb3c282 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs @@ -31,7 +31,7 @@ pub fn main() -> Result<(), Error> { // get message let message = generate_sighash_all().map_err(|_| Error::GeneratedMsgError)?; - let signature = { + let mut signature = { let script = load_script()?; let args: Bytes = script.args().unpack(); if args.len() != 55 { @@ -54,12 +54,6 @@ pub fn main() -> Result<(), Error> { let witness_args = load_witness_args(0, Source::GroupInput).map_err(|_| Error::WitnessError)?; - ckb_std::debug!( - "-- ckb-auth, entry_category({}), hash_type({}) ", - entry_type, - args[53] - ); - witness_args .lock() .to_opt() @@ -72,6 +66,17 @@ pub fn main() -> Result<(), Error> { pubkey_hash: pubkey_hash, }; + match id.algorithm_id { + AuthAlgorithmIdType::Ripple => { + let l = signature[signature.len() - 1] as usize; + if l >= signature.len() { + return Err(Error::ArgsError); + } + signature = Bytes::from(signature[..signature.len() - l].to_vec()); + } + _ => {} + } + let entry = CkbEntryType { code_hash, hash_type, diff --git a/tests/auth-spawn-tests/Cargo.lock b/tests/auth-spawn-tests/Cargo.lock index 6590a92..7fe1e11 100644 --- a/tests/auth-spawn-tests/Cargo.lock +++ b/tests/auth-spawn-tests/Cargo.lock @@ -361,6 +361,7 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", + "lazy_static", ] [[package]] @@ -1173,6 +1174,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "lazycell" diff --git a/tools/ckb-auth-cli/Cargo.lock b/tools/ckb-auth-cli/Cargo.lock index 3160d57..afe8325 100644 --- a/tools/ckb-auth-cli/Cargo.lock +++ b/tools/ckb-auth-cli/Cargo.lock @@ -326,6 +326,7 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", + "lazy_static", ] [[package]] @@ -1084,6 +1085,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "lazycell" @@ -1800,6 +1804,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "static_assertions" version = "1.1.0" From d2b6b19e5361f61d3967db2961f08dc2ad082930 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 12 Dec 2023 18:33:12 +0800 Subject: [PATCH 06/26] Add Cargo.lock --- tests/auth-rust-lock/Cargo.lock | 130 ++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 tests/auth-rust-lock/Cargo.lock diff --git a/tests/auth-rust-lock/Cargo.lock b/tests/auth-rust-lock/Cargo.lock new file mode 100644 index 0000000..ed841e2 --- /dev/null +++ b/tests/auth-rust-lock/Cargo.lock @@ -0,0 +1,130 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "auth-rust-demo" +version = "0.1.0" +dependencies = [ + "ckb-auth-rs", + "ckb-std", + "hex", + "log", +] + +[[package]] +name = "blake2b-ref" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "294d17c72e0ba59fad763caa112368d0672083779cdebbb97164f4bb4c1e339a" + +[[package]] +name = "blake2b-rs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89a8565807f21b913288968e391819e7f9b2f0f46c7b89549c051cccf3a2771" +dependencies = [ + "cc", + "cty", +] + +[[package]] +name = "buddy-alloc" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f0d2da64a6a895d5a7e0724882825d50f83c13396b1b9f1878e19a024bab395" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ckb-auth-rs" +version = "0.1.0" +dependencies = [ + "blake2b-rs", + "ckb-std", + "hex", + "lazy_static", +] + +[[package]] +name = "ckb-standalone-types" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c776d70eb4f60a22a3180857646d77b2da8d33c0c4a063ad9f6610fc94609f" +dependencies = [ + "blake2b-ref", + "cfg-if", + "molecule", +] + +[[package]] +name = "ckb-std" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a08518aa0fd4ce069d3ec80b63dcd3d6543ad3805ad1c0b4e1d8e4d38f8a9fc" +dependencies = [ + "buddy-alloc", + "cc", + "ckb-standalone-types", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "molecule" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd9767ab5e5f2ea40f71ff4c8bdb633c50509052e093c2fdd0e390a749dfa3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" From e4204ea09bf1a9b39d5ebac1d9690ab6e79cac81 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 10:47:03 +0800 Subject: [PATCH 07/26] Support feature enable-dynamic-library --- ckb-auth-rs/Cargo.toml | 12 +-- ckb-auth-rs/src/ckb_auth.rs | 134 ++------------------------------ ckb-auth-rs/src/ckb_auth_dl.rs | 137 +++++++++++++++++++++++++++++++++ ckb-auth-rs/src/lib.rs | 4 + 4 files changed, 154 insertions(+), 133 deletions(-) create mode 100644 ckb-auth-rs/src/ckb_auth_dl.rs diff --git a/ckb-auth-rs/Cargo.toml b/ckb-auth-rs/Cargo.toml index d96d48c..842c4f0 100644 --- a/ckb-auth-rs/Cargo.toml +++ b/ckb-auth-rs/Cargo.toml @@ -6,15 +6,17 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = [] +default = ["dynamic-library-memory-200"] ckb2023 = ["ckb-std/ckb2023"] -dynamic-library-memory = [] -dynamic-library-memory2 = [] -dynamic-library-memory3 = [] + +enable-dynamic-library = ["lazy_static"] +dynamic-library-memory-200 = ["enable-dynamic-library"] +dynamic-library-memory-400 = ["enable-dynamic-library"] +dynamic-library-memory-600 = ["enable-dynamic-library"] [dependencies] ckb-std = "0.14.3" -lazy_static = { version = "1.4.0", features = ["spin_no_std"] } +lazy_static = { version = "1.4.0", optional = true, features = ["spin_no_std"] } [target.'cfg(target_arch = "riscv64")'.dependencies] hex = { version = "0.4.3", default-features = false, features = ["alloc"]} diff --git a/ckb-auth-rs/src/ckb_auth.rs b/ckb-auth-rs/src/ckb_auth.rs index 62ffb0f..7be05af 100644 --- a/ckb-auth-rs/src/ckb_auth.rs +++ b/ckb-auth-rs/src/ckb_auth.rs @@ -1,21 +1,17 @@ extern crate alloc; use crate::{CkbAuthError, CkbAuthType, CkbEntryType, EntryCategoryType}; -use alloc::boxed::Box; -use alloc::collections::BTreeMap; use alloc::ffi::CString; use alloc::format; use alloc::vec::Vec; use ckb_std::high_level::exec_cell; #[cfg(feature = "ckb2023")] use ckb_std::high_level::spawn_cell; -use ckb_std::{ - ckb_types::core::ScriptHashType, - dynamic_loading_c_impl::{CKBDLContext, Library, Symbol}, -}; -use core::mem::size_of; use hex::encode; +#[cfg(feature = "enable-dynamic-library")] +use super::ckb_auth_dl::ckb_auth_dl; + pub fn ckb_auth( entry: &CkbEntryType, id: &CkbAuthType, @@ -24,9 +20,12 @@ pub fn ckb_auth( ) -> Result<(), CkbAuthError> { match entry.entry_category { EntryCategoryType::Exec => ckb_auth_exec(entry, id, signature, message), + #[cfg(feature = "enable-dynamic-library")] EntryCategoryType::DynamicLinking => ckb_auth_dl(entry, id, signature, message), #[cfg(feature = "ckb2023")] EntryCategoryType::Spawn => ckb_auth_spawn(entry, id, signature, message), + #[allow(unreachable_patterns)] + _ => Err(CkbAuthError::UnsupportEntryType), } } @@ -74,124 +73,3 @@ fn ckb_auth_exec( exec_cell(&entry.code_hash, entry.hash_type, &args)?; Ok(()) } - -type DLContext = CKBDLContext<[u8; 256 * 1024]>; -type CkbAuthValidate = unsafe extern "C" fn( - auth_algorithm_id: u8, - signature: *const u8, - signature_size: u32, - message: *const u8, - message_size: u32, - pubkey_hash: *mut u8, - pubkey_hash_size: u32, -) -> i32; - -const EXPORTED_FUNC_NAME: &str = "ckb_auth_validate"; - -struct CKBDLLoader { - pub context: Box, - pub context_used: usize, - pub loaded_lib: BTreeMap<[u8; 33], Library>, -} - -lazy_static::lazy_static! { - static ref G_DL_CONTEXT: DLContext = unsafe { DLContext::new() }; -} - -static mut G_CKB_DL_LOADER: Option = None; -impl CKBDLLoader { - pub fn get() -> &'static mut Self { - unsafe { - match G_CKB_DL_LOADER.as_mut() { - Some(v) => v, - None => { - G_CKB_DL_LOADER = Some(Self::new()); - G_CKB_DL_LOADER.as_mut().unwrap() - } - } - } - } - - fn new() -> Self { - Self { - context: unsafe { - let dl_ctx: &DLContext = &G_DL_CONTEXT; - Box::from_raw(dl_ctx as *const DLContext as *mut DLContext) - }, - context_used: 0, - loaded_lib: BTreeMap::new(), - } - } - - fn get_lib( - &mut self, - code_hash: &[u8; 32], - hash_type: ScriptHashType, - ) -> Result<&Library, CkbAuthError> { - let mut lib_key = [0u8; 33]; - lib_key[..32].copy_from_slice(code_hash); - lib_key[32] = hash_type as u8; - - let has_lib = match self.loaded_lib.get(&lib_key) { - Some(_) => true, - None => false, - }; - - if !has_lib { - let size = size_of::(); - let lib = self - .context - .load_with_offset(code_hash, hash_type, self.context_used, size) - .map_err(|_| CkbAuthError::LoadDLError)?; - self.context_used += lib.consumed_size(); - self.loaded_lib.insert(lib_key.clone(), lib); - }; - Ok(self.loaded_lib.get(&lib_key).unwrap()) - } - - pub fn get_validate_func( - &mut self, - code_hash: &[u8; 32], - hash_type: ScriptHashType, - func_name: &str, - ) -> Result, CkbAuthError> { - let lib = self.get_lib(code_hash, hash_type)?; - - let func: Option> = unsafe { lib.get(func_name.as_bytes()) }; - if func.is_none() { - return Err(CkbAuthError::LoadDLFuncError); - } - Ok(func.unwrap()) - } -} - -fn ckb_auth_dl( - entry: &CkbEntryType, - id: &CkbAuthType, - signature: &[u8], - message: &[u8; 32], -) -> Result<(), CkbAuthError> { - let func: Symbol = CKBDLLoader::get().get_validate_func( - &entry.code_hash, - entry.hash_type, - EXPORTED_FUNC_NAME, - )?; - - let mut pub_key = id.pubkey_hash.clone(); - let rc_code = unsafe { - func( - id.algorithm_id.clone().into(), - signature.as_ptr(), - signature.len() as u32, - message.as_ptr(), - message.len() as u32, - pub_key.as_mut_ptr(), - pub_key.len() as u32, - ) - }; - - match rc_code { - 0 => Ok(()), - _ => Err(CkbAuthError::RunDLError), - } -} diff --git a/ckb-auth-rs/src/ckb_auth_dl.rs b/ckb-auth-rs/src/ckb_auth_dl.rs new file mode 100644 index 0000000..88d97e9 --- /dev/null +++ b/ckb-auth-rs/src/ckb_auth_dl.rs @@ -0,0 +1,137 @@ +use crate::{CkbAuthError, CkbAuthType, CkbEntryType}; +use alloc::boxed::Box; +use alloc::collections::BTreeMap; +use ckb_std::{ + ckb_types::core::ScriptHashType, + dynamic_loading_c_impl::{CKBDLContext, Library, Symbol}, +}; +use core::mem::size_of; + +#[cfg(feature = "dynamic-library-memory-200")] +type DLContext = CKBDLContext<[u8; 200 * 1024]>; + +#[cfg(feature = "dynamic-library-memory-400")] +type DLContext = CKBDLContext<[u8; 400 * 1024]>; + +#[cfg(feature = "dynamic-library-memory-600")] +type DLContext = CKBDLContext<[u8; 600 * 1024]>; + +type CkbAuthValidate = unsafe extern "C" fn( + auth_algorithm_id: u8, + signature: *const u8, + signature_size: u32, + message: *const u8, + message_size: u32, + pubkey_hash: *mut u8, + pubkey_hash_size: u32, +) -> i32; + +const EXPORTED_FUNC_NAME: &str = "ckb_auth_validate"; + +struct CKBDLLoader { + pub context: Box, + pub context_used: usize, + pub loaded_lib: BTreeMap<[u8; 33], Library>, +} + +lazy_static::lazy_static! { + static ref G_DL_CONTEXT: DLContext = unsafe { DLContext::new() }; +} + +static mut G_CKB_DL_LOADER: Option = None; +impl CKBDLLoader { + pub fn get() -> &'static mut Self { + unsafe { + match G_CKB_DL_LOADER.as_mut() { + Some(v) => v, + None => { + G_CKB_DL_LOADER = Some(Self::new()); + G_CKB_DL_LOADER.as_mut().unwrap() + } + } + } + } + + fn new() -> Self { + Self { + context: unsafe { + let dl_ctx: &DLContext = &G_DL_CONTEXT; + Box::from_raw(dl_ctx as *const DLContext as *mut DLContext) + }, + context_used: 0, + loaded_lib: BTreeMap::new(), + } + } + + fn get_lib( + &mut self, + code_hash: &[u8; 32], + hash_type: ScriptHashType, + ) -> Result<&Library, CkbAuthError> { + let mut lib_key = [0u8; 33]; + lib_key[..32].copy_from_slice(code_hash); + lib_key[32] = hash_type as u8; + + let has_lib = match self.loaded_lib.get(&lib_key) { + Some(_) => true, + None => false, + }; + + if !has_lib { + let size = size_of::(); + let lib = self + .context + .load_with_offset(code_hash, hash_type, self.context_used, size) + .map_err(|_| CkbAuthError::LoadDLError)?; + self.context_used += lib.consumed_size(); + self.loaded_lib.insert(lib_key.clone(), lib); + }; + Ok(self.loaded_lib.get(&lib_key).unwrap()) + } + + pub fn get_validate_func( + &mut self, + code_hash: &[u8; 32], + hash_type: ScriptHashType, + func_name: &str, + ) -> Result, CkbAuthError> { + let lib = self.get_lib(code_hash, hash_type)?; + + let func: Option> = unsafe { lib.get(func_name.as_bytes()) }; + if func.is_none() { + return Err(CkbAuthError::LoadDLFuncError); + } + Ok(func.unwrap()) + } +} + +pub fn ckb_auth_dl( + entry: &CkbEntryType, + id: &CkbAuthType, + signature: &[u8], + message: &[u8; 32], +) -> Result<(), CkbAuthError> { + let func: Symbol = CKBDLLoader::get().get_validate_func( + &entry.code_hash, + entry.hash_type, + EXPORTED_FUNC_NAME, + )?; + + let mut pub_key = id.pubkey_hash.clone(); + let rc_code = unsafe { + func( + id.algorithm_id.clone().into(), + signature.as_ptr(), + signature.len() as u32, + message.as_ptr(), + message.len() as u32, + pub_key.as_mut_ptr(), + pub_key.len() as u32, + ) + }; + + match rc_code { + 0 => Ok(()), + _ => Err(CkbAuthError::RunDLError), + } +} diff --git a/ckb-auth-rs/src/lib.rs b/ckb-auth-rs/src/lib.rs index abe830e..5c1cac5 100644 --- a/ckb-auth-rs/src/lib.rs +++ b/ckb-auth-rs/src/lib.rs @@ -8,6 +8,9 @@ mod ckb_auth; #[cfg(target_arch = "riscv64")] pub use ckb_auth::ckb_auth; +#[cfg(all(feature = "enable-dynamic-library", target_arch = "riscv64"))] +mod ckb_auth_dl; + #[cfg(target_arch = "riscv64")] mod generate_sighash_all; @@ -75,6 +78,7 @@ pub enum CkbAuthError { SignatureMissing, EncodeArgs, GenerateSigHash, + UnsupportEntryType } #[cfg(target_arch = "riscv64")] From 298815c5175d34911de851a83f466910ab138bc9 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 11:25:53 +0800 Subject: [PATCH 08/26] Add testcase about ckb-auth-rs features --- ckb-auth-rs/Cargo.toml | 2 +- ckb-auth-rs/src/ckb_auth.rs | 8 +- ckb-auth-rs/src/lib.rs | 4 +- tests/Makefile | 26 +- tests/auth-c-tests/Cargo.toml | 2 +- .../contracts/auth-rust-demo/Cargo.toml | 7 +- .../contracts/auth-rust-demo/src/error.rs | 4 + tests/auth-rust-lock/tests/Cargo.lock | 1524 +++++++++++++++++ tests/auth-rust-lock/tests/Cargo.toml | 7 +- tests/auth-rust-lock/tests/src/tests.rs | 2 + tests/auth-spawn-tests/Cargo.lock | 4 - tools/ckb-auth-cli/Cargo.lock | 10 - 12 files changed, 1576 insertions(+), 24 deletions(-) create mode 100644 tests/auth-rust-lock/tests/Cargo.lock diff --git a/ckb-auth-rs/Cargo.toml b/ckb-auth-rs/Cargo.toml index 842c4f0..aa25a6e 100644 --- a/ckb-auth-rs/Cargo.toml +++ b/ckb-auth-rs/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["dynamic-library-memory-200"] +default = [] ckb2023 = ["ckb-std/ckb2023"] enable-dynamic-library = ["lazy_static"] diff --git a/ckb-auth-rs/src/ckb_auth.rs b/ckb-auth-rs/src/ckb_auth.rs index 7be05af..b010c2f 100644 --- a/ckb-auth-rs/src/ckb_auth.rs +++ b/ckb-auth-rs/src/ckb_auth.rs @@ -3,11 +3,13 @@ extern crate alloc; use crate::{CkbAuthError, CkbAuthType, CkbEntryType, EntryCategoryType}; use alloc::ffi::CString; use alloc::format; -use alloc::vec::Vec; use ckb_std::high_level::exec_cell; +use hex::encode; + +#[cfg(feature = "ckb2023")] +use alloc::vec::Vec; #[cfg(feature = "ckb2023")] use ckb_std::high_level::spawn_cell; -use hex::encode; #[cfg(feature = "enable-dynamic-library")] use super::ckb_auth_dl::ckb_auth_dl; @@ -24,8 +26,6 @@ pub fn ckb_auth( EntryCategoryType::DynamicLinking => ckb_auth_dl(entry, id, signature, message), #[cfg(feature = "ckb2023")] EntryCategoryType::Spawn => ckb_auth_spawn(entry, id, signature, message), - #[allow(unreachable_patterns)] - _ => Err(CkbAuthError::UnsupportEntryType), } } diff --git a/ckb-auth-rs/src/lib.rs b/ckb-auth-rs/src/lib.rs index 5c1cac5..873647d 100644 --- a/ckb-auth-rs/src/lib.rs +++ b/ckb-auth-rs/src/lib.rs @@ -78,7 +78,7 @@ pub enum CkbAuthError { SignatureMissing, EncodeArgs, GenerateSigHash, - UnsupportEntryType + UnsupportEntryType, } #[cfg(target_arch = "riscv64")] @@ -98,6 +98,7 @@ impl From for CkbAuthError { #[derive(Clone)] pub enum EntryCategoryType { Exec = 0, + #[cfg(feature = "enable-dynamic-library")] DynamicLinking = 1, #[cfg(feature = "ckb2023")] Spawn = 2, @@ -108,6 +109,7 @@ impl TryFrom for EntryCategoryType { fn try_from(value: u8) -> Result { match value { 0 => Ok(Self::Exec), + #[cfg(feature = "enable-dynamic-library")] 1 => Ok(Self::DynamicLinking), #[cfg(feature = "ckb2023")] 2 => Ok(Self::Spawn), diff --git a/tests/Makefile b/tests/Makefile index b4e89c4..402e0da 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,7 +8,10 @@ all: \ rust-demo-tests \ clean-rust-demo-tests \ spawn-tests \ - clean-spawn-tests + clean-spawn-tests \ + rust-demo-tests-no-def-features \ + rust-demo-tests-only-ckb2023 \ + rust-demo-tests-only-dl all-with-clang: \ build-auth-lock-with-clang \ @@ -45,6 +48,27 @@ rust-demo-tests: clean-rust-demo-tests: export PATH=$(shell pwd)/bin/:"$(PATH)" && cd auth-rust-lock/ && capsule clean +rust-demo-tests-no-def-features: clean-rust-demo-tests + export PATH=$(shell pwd)/bin/:"$(PATH)" && \ + cd auth-rust-lock && \ + capsule build -- --no-default-features && \ + cd tests && \ + cargo test --no-default-features + +rust-demo-tests-only-ckb2023: clean-rust-demo-tests + export PATH=$(shell pwd)/bin/:"$(PATH)" && \ + cd auth-rust-lock && \ + capsule build -- --no-default-features --features="ckb2023" && \ + cd tests && \ + cargo test --no-default-features --features="ckb2023" + +rust-demo-tests-only-dl: clean-rust-demo-tests + export PATH=$(shell pwd)/bin/:"$(PATH)" && \ + cd auth-rust-lock && \ + capsule build -- --no-default-features --features="enable-dynamic-library" && \ + cd tests && \ + cargo test --no-default-features --features="enable-dynamic-library" + spawn-tests: export PATH=`pwd`/bin/:"$(PATH)" && cd auth-spawn-tests && make all diff --git a/tests/auth-c-tests/Cargo.toml b/tests/auth-c-tests/Cargo.toml index 0b57732..a503dcd 100644 --- a/tests/auth-c-tests/Cargo.toml +++ b/tests/auth-c-tests/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] -ckb-auth-rs = { path = "../../ckb-auth-rs", features = ["ckb2023"] } +ckb-auth-rs = { path = "../../ckb-auth-rs", features = ["ckb2023", "enable-dynamic-library"] } ckb-crypto = "0.111.0" ckb-error = "0.111.0" ckb-hash = "0.111.0" diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml b/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml index 65d4a26..c7a5ec4 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml @@ -5,8 +5,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["ckb2023", "enable-dynamic-library"] +ckb2023 = ["ckb-auth-rs/ckb2023", "ckb-std/ckb2023"] +enable-dynamic-library = ["ckb-auth-rs/dynamic-library-memory-600"] + [dependencies] ckb-std = "0.14.3" -ckb-auth-rs = { path = "../../../../ckb-auth-rs", features = ["ckb2023"] } +ckb-auth-rs = { path = "../../../../ckb-auth-rs" } log = { version = "0.4.17", default-features = false } hex = { version = "0.4.3", default-features = false, features = ["alloc"]} diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/error.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/error.rs index 6b812ab..d3211a9 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/error.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/error.rs @@ -22,6 +22,10 @@ pub enum Error { impl From for Error { fn from(err: SysError) -> Self { use SysError::*; + + #[allow(unreachable_patterns)] // When --no-default-features + #[allow(unused_variables)] + #[allow(non_snake_case)] match err { IndexOutOfBound => Self::IndexOutOfBound, ItemMissing => Self::ItemMissing, diff --git a/tests/auth-rust-lock/tests/Cargo.lock b/tests/auth-rust-lock/tests/Cargo.lock new file mode 100644 index 0000000..fd3767c --- /dev/null +++ b/tests/auth-rust-lock/tests/Cargo.lock @@ -0,0 +1,1524 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +dependencies = [ + "getrandom 0.2.11", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "autocfg" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" +dependencies = [ + "autocfg 1.1.0", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "blake2b-ref" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "294d17c72e0ba59fad763caa112368d0672083779cdebbb97164f4bb4c1e339a" + +[[package]] +name = "blake2b-rs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89a8565807f21b913288968e391819e7f9b2f0f46c7b89549c051cccf3a2771" +dependencies = [ + "cc", + "cty", +] + +[[package]] +name = "buddy-alloc" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f0d2da64a6a895d5a7e0724882825d50f83c13396b1b9f1878e19a024bab395" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +dependencies = [ + "serde", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ckb-always-success-script" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3b72a38c9920a29990df12002c4d069a147c8782f0c211f8a01b2df8f42bfd" + +[[package]] +name = "ckb-auth-rs" +version = "0.1.0" +dependencies = [ + "blake2b-rs", + "ckb-std", + "hex", + "lazy_static", +] + +[[package]] +name = "ckb-chain-spec" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbd58081d4ac4f08d068b52c5a07f0b379d93aad0dfa8344c6890429a9b73c2b" +dependencies = [ + "ckb-constant", + "ckb-crypto", + "ckb-dao-utils", + "ckb-error", + "ckb-hash", + "ckb-jsonrpc-types", + "ckb-pow", + "ckb-rational", + "ckb-resource", + "ckb-traits", + "ckb-types", + "ckb-util", + "serde", + "toml", +] + +[[package]] +name = "ckb-channel" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701e6829c3dcbae46dd2442de63d080046480a6c2bb4951dbf419ad092459402" +dependencies = [ + "crossbeam-channel", +] + +[[package]] +name = "ckb-constant" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5c980d4724770f72a37bceffa26ea64dd914891e45e856e2a3792fdb4a5a18" + +[[package]] +name = "ckb-crypto" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df80db694e42b64a5774ae551daff3c8310cd99bb528643dbe0dd409abb298e7" +dependencies = [ + "ckb-fixed-hash", + "faster-hex", + "lazy_static", + "rand 0.7.3", + "secp256k1", + "thiserror", +] + +[[package]] +name = "ckb-dao" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cb0dd4d284d6908595fa809668555ad36bc89538ea9440d11208090481c240" +dependencies = [ + "byteorder", + "ckb-chain-spec", + "ckb-dao-utils", + "ckb-traits", + "ckb-types", +] + +[[package]] +name = "ckb-dao-utils" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e158ce5a4e9d1fcd08d9dee87332474572c629c6273cca0aea80ba24892a403" +dependencies = [ + "byteorder", + "ckb-error", + "ckb-types", +] + +[[package]] +name = "ckb-error" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cfd733cabcb4262ee679c02733864b13c8fa879e3aabc078fe0ec727cd95d6" +dependencies = [ + "anyhow", + "ckb-occupied-capacity", + "derive_more", + "thiserror", +] + +[[package]] +name = "ckb-fixed-hash" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1dfab045fffa31cae9680d73e1f09833ca1abfb807dc4b9544739c94c23fd0" +dependencies = [ + "ckb-fixed-hash-core", + "ckb-fixed-hash-macros", +] + +[[package]] +name = "ckb-fixed-hash-core" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd1727a6ecd4d0bcab604cb1ef707fe92e939fa6e9a438f9f25bf05208cb080" +dependencies = [ + "faster-hex", + "serde", + "thiserror", +] + +[[package]] +name = "ckb-fixed-hash-macros" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5da34c32585c35715fcde4e3a1dd3b0346d7af43506c5e51c613f01483e4f9" +dependencies = [ + "ckb-fixed-hash-core", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ckb-gen-types" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3bc54ca99b09e1eb5fc6c49bb1156644ce57fce9c6f52b5c13110b9a3143f7e" +dependencies = [ + "cfg-if", + "ckb-error", + "ckb-fixed-hash", + "ckb-hash", + "ckb-occupied-capacity", + "molecule", + "numext-fixed-uint", +] + +[[package]] +name = "ckb-hash" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c88e5e2d6454be488fa5cf8b49175879353c6af969ff210dd6416f315b53120" +dependencies = [ + "blake2b-ref", + "blake2b-rs", +] + +[[package]] +name = "ckb-jsonrpc-types" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d789a71538da07871c11aecbd28d6c632bb426bdfeed5fc2fa1b455e31152468" +dependencies = [ + "ckb-types", + "faster-hex", + "serde", + "serde_json", +] + +[[package]] +name = "ckb-logger" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939fa09ca3534248d3d452552546f016fc7e11346644fbc5b55d2ad38d3e80e7" +dependencies = [ + "log", +] + +[[package]] +name = "ckb-merkle-mountain-range" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ccb671c5921be8a84686e6212ca184cb1d7c51cadcdbfcbd1cc3f042f5dfb8" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ckb-occupied-capacity" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358ad364465a5a359575642c12952ba8735a148382789d65ddd5231cd21899fc" +dependencies = [ + "ckb-occupied-capacity-core", + "ckb-occupied-capacity-macros", +] + +[[package]] +name = "ckb-occupied-capacity-core" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de2dc06db98f8a995cb7145bc56dbd17bb0c8ab2e59a07aaa40f2c956c2451dd" +dependencies = [ + "serde", +] + +[[package]] +name = "ckb-occupied-capacity-macros" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1709e0f101026c4ef29b1593692e480b03cdb4e0dace1e348494c6554d50d35" +dependencies = [ + "ckb-occupied-capacity-core", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ckb-pow" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "481e76388993d7e6e0dd797e8532c60398901787e28d0638ca114254257b8813" +dependencies = [ + "byteorder", + "ckb-hash", + "ckb-types", + "eaglesong", + "log", + "serde", +] + +[[package]] +name = "ckb-rational" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd3959391a4fb05d6a2578aa8db75732ada1ce381fb34d6eeaf09d395702e63c" +dependencies = [ + "numext-fixed-uint", + "serde", +] + +[[package]] +name = "ckb-resource" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03222b0613cf3f55cb181471d7a84879b6fba5e920e2e1c7ba2c2315614bd387" +dependencies = [ + "ckb-system-scripts", + "ckb-types", + "includedir", + "includedir_codegen", + "phf", + "serde", + "walkdir", +] + +[[package]] +name = "ckb-script" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9075ad901eae97925f491b6be675d7b19bf7b10eaa94a88f6e8070c0cd00ba" +dependencies = [ + "byteorder", + "ckb-chain-spec", + "ckb-error", + "ckb-hash", + "ckb-logger", + "ckb-traits", + "ckb-types", + "ckb-vm", + "faster-hex", + "serde", +] + +[[package]] +name = "ckb-standalone-types" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c776d70eb4f60a22a3180857646d77b2da8d33c0c4a063ad9f6610fc94609f" +dependencies = [ + "blake2b-ref", + "cfg-if", + "molecule", +] + +[[package]] +name = "ckb-std" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a08518aa0fd4ce069d3ec80b63dcd3d6543ad3805ad1c0b4e1d8e4d38f8a9fc" +dependencies = [ + "buddy-alloc", + "cc", + "ckb-standalone-types", +] + +[[package]] +name = "ckb-system-scripts" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa5c59063142de7a68cfad4449c6b3863563856219a2925dfb8c5f019ec2aa47" +dependencies = [ + "blake2b-rs", + "faster-hex", + "includedir", + "includedir_codegen", + "phf", +] + +[[package]] +name = "ckb-systemtime" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5c03dd01263a66eaf171fb1bbadd12d80a0b54abe19aa55a2c53c5ae3300cda" + +[[package]] +name = "ckb-testtool" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f7426eb44c6cfc703a68fb99c74b675a378fdca12df5af94683b27a60d377e" +dependencies = [ + "ckb-always-success-script", + "ckb-chain-spec", + "ckb-crypto", + "ckb-error", + "ckb-hash", + "ckb-jsonrpc-types", + "ckb-resource", + "ckb-script", + "ckb-traits", + "ckb-types", + "ckb-verification", + "lazy_static", + "rand 0.8.5", +] + +[[package]] +name = "ckb-traits" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca049aba2cb2d1208c6044accb497b17290ad56de629f6a4b95eded67a43fd40" +dependencies = [ + "ckb-types", +] + +[[package]] +name = "ckb-types" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6ec737e4957418bbd0f4091e8565a89bbd8f6fc37a20360820e44d1f1e44e58" +dependencies = [ + "bit-vec", + "bytes", + "ckb-channel", + "ckb-constant", + "ckb-error", + "ckb-fixed-hash", + "ckb-gen-types", + "ckb-hash", + "ckb-merkle-mountain-range", + "ckb-occupied-capacity", + "ckb-rational", + "derive_more", + "golomb-coded-set", + "merkle-cbt", + "molecule", + "numext-fixed-uint", + "once_cell", + "paste", +] + +[[package]] +name = "ckb-util" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "011b907b18aa706fc224a1309f14eadd9cc14c42cf2258ca3010d1324bc20f10" +dependencies = [ + "linked-hash-map", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "ckb-verification" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe3338bb8cf49c5a21de636eeb448deeba1e379491d34b67f2201fc77a08e215" +dependencies = [ + "ckb-chain-spec", + "ckb-dao", + "ckb-dao-utils", + "ckb-error", + "ckb-pow", + "ckb-script", + "ckb-systemtime", + "ckb-traits", + "ckb-types", + "ckb-verification-traits", + "derive_more", + "lru", +] + +[[package]] +name = "ckb-verification-traits" +version = "0.111.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1bbfdeff1f930f26c60103b59442494dba83493254bb255f1ba318be2f27fe" +dependencies = [ + "bitflags", + "ckb-error", +] + +[[package]] +name = "ckb-vm" +version = "0.24.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc004a826b9bc9319ffae0b8415690e1b5f1482266d55fbd43843aa40ddcd63" +dependencies = [ + "byteorder", + "bytes", + "cc", + "ckb-vm-definitions", + "derive_more", + "goblin 0.2.3", + "goblin 0.4.0", + "rand 0.7.3", + "scroll", + "serde", +] + +[[package]] +name = "ckb-vm-definitions" +version = "0.24.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ced3ff9d79b53d93c106720f6c1f855694290e33581850e05c859500eee83f" +dependencies = [ + "paste", +] + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "eaglesong" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d978bd5d343e8ab9b5c0fc8d93ff9c602fdc96616ffff9c05ac7a155419b824" + +[[package]] +name = "faster-hex" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "goblin" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "goblin" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532a09cd3df2c6bbfc795fb0434bff8f22255d1d07328180e918a2e6ce122d4d" +dependencies = [ + "log", + "plain", + "scroll", +] + +[[package]] +name = "golomb-coded-set" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7076c0cd6257d84b785b0f22c36443dd47a5e86a1256d7ef82c8cb88ea9a7e" +dependencies = [ + "siphasher", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "heapsize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" +dependencies = [ + "winapi", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "includedir" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afd126bd778c00c43a9dc76d1609a0894bf4222088088b2217ccc0ce9e816db7" +dependencies = [ + "flate2", + "phf", +] + +[[package]] +name = "includedir_codegen" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ac1500c9780957c9808c4ec3b94002f35aab01483833f5a8bce7dfb243e3148" +dependencies = [ + "flate2", + "phf_codegen", + "walkdir", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +dependencies = [ + "serde", +] + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg 1.1.0", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "lru" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "merkle-cbt" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171d2f700835121c3b04ccf0880882987a050fd5c7ae88148abf537d33dd3a56" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "molecule" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd9767ab5e5f2ea40f71ff4c8bdb633c50509052e093c2fdd0e390a749dfa3" +dependencies = [ + "bytes", + "cfg-if", + "faster-hex", +] + +[[package]] +name = "numext-constructor" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "621fe0f044729f810c6815cdd77e8f5e0cd803ce4f6a38380ebfc1322af98661" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "numext-fixed-uint" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c68c76f96d589d1009a666c5072f37f3114d682696505f2cf445f27766c7d70" +dependencies = [ + "numext-fixed-uint-core", + "numext-fixed-uint-hack", +] + +[[package]] +name = "numext-fixed-uint-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aab1d6457b97b49482f22a92f0f58a2f39bdd7f3b2f977eae67e8bc206aa980" +dependencies = [ + "heapsize", + "numext-constructor", + "rand 0.7.3", + "serde", + "thiserror", +] + +[[package]] +name = "numext-fixed-uint-hack" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0200f8d55c36ec1b6a8cf810115be85d4814f045e0097dfd50033ba25adb4c9e" +dependencies = [ + "numext-fixed-uint-core", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "phf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +dependencies = [ + "phf_shared", + "rand 0.7.3", +] + +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher", +] + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.8", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg 0.1.2", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", + "rand_pcg 0.2.1", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.11", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scroll" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaaae8f38bb311444cfb7f1979af0bc9240d95795f75f9ceddf6a59b79ceffa0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "secp256k1" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +dependencies = [ + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +dependencies = [ + "cc", +] + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tests" +version = "0.1.0" +dependencies = [ + "ckb-auth-rs", + "ckb-testtool", + "rand 0.6.5", +] + +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/tests/auth-rust-lock/tests/Cargo.toml b/tests/auth-rust-lock/tests/Cargo.toml index 8b05086..c394675 100644 --- a/tests/auth-rust-lock/tests/Cargo.toml +++ b/tests/auth-rust-lock/tests/Cargo.toml @@ -5,8 +5,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["ckb2023", "enable-dynamic-library"] +ckb2023 = ["ckb-auth-rs/ckb2023"] +enable-dynamic-library = ["ckb-auth-rs/dynamic-library-memory-600"] + [dependencies] ckb-testtool = "0.10" -ckb-auth-rs = { path = "../../../ckb-auth-rs", features = ["ckb2023"] } +ckb-auth-rs = { path = "../../../ckb-auth-rs" } rand = "0.6.5" diff --git a/tests/auth-rust-lock/tests/src/tests.rs b/tests/auth-rust-lock/tests/src/tests.rs index 9a80fb1..d10a538 100644 --- a/tests/auth-rust-lock/tests/src/tests.rs +++ b/tests/auth-rust-lock/tests/src/tests.rs @@ -210,6 +210,7 @@ fn test_exec() { } #[test] +#[cfg(feature = "enable-dynamic-library")] fn test_dll() { let auth = CKbAuth::new(); let mut ctx = Context::default(); @@ -227,6 +228,7 @@ fn test_dll() { } #[test] +#[cfg(feature = "ckb2023")] fn test_spawn() { let auth = CKbAuth::new(); diff --git a/tests/auth-spawn-tests/Cargo.lock b/tests/auth-spawn-tests/Cargo.lock index 7fe1e11..6590a92 100644 --- a/tests/auth-spawn-tests/Cargo.lock +++ b/tests/auth-spawn-tests/Cargo.lock @@ -361,7 +361,6 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", - "lazy_static", ] [[package]] @@ -1174,9 +1173,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "lazycell" diff --git a/tools/ckb-auth-cli/Cargo.lock b/tools/ckb-auth-cli/Cargo.lock index afe8325..3160d57 100644 --- a/tools/ckb-auth-cli/Cargo.lock +++ b/tools/ckb-auth-cli/Cargo.lock @@ -326,7 +326,6 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", - "lazy_static", ] [[package]] @@ -1085,9 +1084,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -1804,12 +1800,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "static_assertions" version = "1.1.0" From 8f6568629b37571106594a0085d797023891cb20 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 11:29:10 +0800 Subject: [PATCH 09/26] Execute ckb-auth twice consecutively in auth-rust-lock --- tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs index fb3c282..220a058 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs @@ -86,7 +86,7 @@ pub fn main() -> Result<(), Error> { }; ckb_auth(&entry, &id, &signature, &message)?; - // ckb_auth(&entry, &id, &signature, &message)?; + ckb_auth(&entry, &id, &signature, &message)?; Ok(()) } From a8269030ef9290bfa958e5d2499d6f5a5ae57d25 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 13:34:05 +0800 Subject: [PATCH 10/26] Fix CI: rust-demo-tests build before testing --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 402e0da..d97b4ba 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -43,7 +43,7 @@ clean-c-tests: rm -rf auth-c-tests/target rust-demo-tests: - export PATH=$(shell pwd)/bin/:"$(PATH)" && cd auth-rust-lock/ && capsule test + export PATH=$(shell pwd)/bin/:"$(PATH)" && cd auth-rust-lock/ && capsule build && capsule test clean-rust-demo-tests: export PATH=$(shell pwd)/bin/:"$(PATH)" && cd auth-rust-lock/ && capsule clean From f7391c114c983eb7f8c24d4cc97fd2566576539f Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 13:35:21 +0800 Subject: [PATCH 11/26] ckb-auth-rs: Defaule enable dynamic-library --- ckb-auth-rs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckb-auth-rs/Cargo.toml b/ckb-auth-rs/Cargo.toml index aa25a6e..842c4f0 100644 --- a/ckb-auth-rs/Cargo.toml +++ b/ckb-auth-rs/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = [] +default = ["dynamic-library-memory-200"] ckb2023 = ["ckb-std/ckb2023"] enable-dynamic-library = ["lazy_static"] From d5aa29886c92bc50c12990db7cc168c5fddc6f00 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 13:37:26 +0800 Subject: [PATCH 12/26] Replace DynamicLinking to DynamicLibrary in ckb-auth-rs --- ckb-auth-rs/src/ckb_auth.rs | 2 +- ckb-auth-rs/src/lib.rs | 4 ++-- tests/auth-c-tests/src/tests/mod.rs | 22 +++++++++++----------- tests/auth-rust-lock/tests/src/tests.rs | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ckb-auth-rs/src/ckb_auth.rs b/ckb-auth-rs/src/ckb_auth.rs index b010c2f..c807f32 100644 --- a/ckb-auth-rs/src/ckb_auth.rs +++ b/ckb-auth-rs/src/ckb_auth.rs @@ -23,7 +23,7 @@ pub fn ckb_auth( match entry.entry_category { EntryCategoryType::Exec => ckb_auth_exec(entry, id, signature, message), #[cfg(feature = "enable-dynamic-library")] - EntryCategoryType::DynamicLinking => ckb_auth_dl(entry, id, signature, message), + EntryCategoryType::DynamicLibrary => ckb_auth_dl(entry, id, signature, message), #[cfg(feature = "ckb2023")] EntryCategoryType::Spawn => ckb_auth_spawn(entry, id, signature, message), } diff --git a/ckb-auth-rs/src/lib.rs b/ckb-auth-rs/src/lib.rs index 873647d..ac26db7 100644 --- a/ckb-auth-rs/src/lib.rs +++ b/ckb-auth-rs/src/lib.rs @@ -99,7 +99,7 @@ impl From for CkbAuthError { pub enum EntryCategoryType { Exec = 0, #[cfg(feature = "enable-dynamic-library")] - DynamicLinking = 1, + DynamicLibrary = 1, #[cfg(feature = "ckb2023")] Spawn = 2, } @@ -110,7 +110,7 @@ impl TryFrom for EntryCategoryType { match value { 0 => Ok(Self::Exec), #[cfg(feature = "enable-dynamic-library")] - 1 => Ok(Self::DynamicLinking), + 1 => Ok(Self::DynamicLibrary), #[cfg(feature = "ckb2023")] 2 => Ok(Self::Spawn), _ => Err(CkbAuthError::EncodeArgs), diff --git a/tests/auth-c-tests/src/tests/mod.rs b/tests/auth-c-tests/src/tests/mod.rs index f09f5be..87dc5f7 100644 --- a/tests/auth-c-tests/src/tests/mod.rs +++ b/tests/auth-c-tests/src/tests/mod.rs @@ -176,14 +176,14 @@ fn unit_test_common_with_runtype( fn unit_test_common_all_runtype(auth: &Box) { unit_test_common_with_auth(auth, EntryCategoryType::Exec); - unit_test_common_with_auth(auth, EntryCategoryType::DynamicLinking); + unit_test_common_with_auth(auth, EntryCategoryType::DynamicLibrary); unit_test_common_with_auth(auth, EntryCategoryType::Spawn); } fn unit_test_common(algorithm_type: AuthAlgorithmIdType) { for t in [ EntryCategoryType::Exec, - EntryCategoryType::DynamicLinking, + EntryCategoryType::DynamicLibrary, EntryCategoryType::Spawn, ] { unit_test_common_with_runtype(algorithm_type.clone(), t, false); @@ -193,7 +193,7 @@ fn unit_test_common(algorithm_type: AuthAlgorithmIdType) { fn unit_test_common_official(algorithm_type: AuthAlgorithmIdType) { for t in [ EntryCategoryType::Exec, - EntryCategoryType::DynamicLinking, + EntryCategoryType::DynamicLibrary, EntryCategoryType::Spawn, ] { unit_test_common_with_runtype(algorithm_type.clone(), t, true); @@ -284,7 +284,7 @@ fn bitcoin_pubkey_recid_verify() { 0: BitcoinAuth::default(), }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver btc", @@ -375,7 +375,7 @@ fn convert_eth_error() { }, }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver eth", @@ -413,7 +413,7 @@ fn convert_tron_error() { let auth: Box = Box::new(TronConverFaileAuth { 0: TronAuth { privkey, pubkey }, }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver tron", @@ -455,7 +455,7 @@ fn convert_btc_error() { 0: BitcoinAuth::default(), }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver btc", @@ -502,7 +502,7 @@ fn convert_doge_error() { }, }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver doge", @@ -550,7 +550,7 @@ fn convert_lite_error() { }, }); - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "failed conver lite", @@ -671,7 +671,7 @@ fn unit_test_ckbmultisig(auth: &Box, run_type: EntryCategoryType) { fn ckbmultisig_verify() { let auth: Box = CkbMultisigAuth::new(2, 2, 1); unit_test_ckbmultisig(&auth, EntryCategoryType::Exec); - unit_test_ckbmultisig(&auth, EntryCategoryType::DynamicLinking); + unit_test_ckbmultisig(&auth, EntryCategoryType::DynamicLibrary); unit_test_ckbmultisig(&auth, EntryCategoryType::Spawn); } @@ -709,7 +709,7 @@ fn abnormal_algorithm_type() { ); } { - let config = TestConfig::new(&auth, EntryCategoryType::DynamicLinking, 1); + let config = TestConfig::new(&auth, EntryCategoryType::DynamicLibrary, 1); assert_result_error( verify_unit(&config), "sign size(smaller)", diff --git a/tests/auth-rust-lock/tests/src/tests.rs b/tests/auth-rust-lock/tests/src/tests.rs index d10a538..b6ac59b 100644 --- a/tests/auth-rust-lock/tests/src/tests.rs +++ b/tests/auth-rust-lock/tests/src/tests.rs @@ -218,7 +218,7 @@ fn test_dll() { let tx = gen_tx( &mut ctx, vec![( - auth.get_auth_args(&EntryCategoryType::DynamicLinking), + auth.get_auth_args(&EntryCategoryType::DynamicLibrary), CKB_SIGN_GROUP_SIZE, )], ); From 8b69cc2b111f38180154081d8239ed5f846fdc67 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 13:42:45 +0800 Subject: [PATCH 13/26] Fix CI: aut-rust-demo add no default features --- tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml b/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml index c7a5ec4..691b3f7 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/Cargo.toml @@ -12,6 +12,6 @@ enable-dynamic-library = ["ckb-auth-rs/dynamic-library-memory-600"] [dependencies] ckb-std = "0.14.3" -ckb-auth-rs = { path = "../../../../ckb-auth-rs" } +ckb-auth-rs = { path = "../../../../ckb-auth-rs", default-features = false } log = { version = "0.4.17", default-features = false } hex = { version = "0.4.3", default-features = false, features = ["alloc"]} From 0cfc9c4b92a877d2066caf40000b3f75589df8f4 Mon Sep 17 00:00:00 2001 From: xjd Date: Wed, 13 Dec 2023 13:55:07 +0800 Subject: [PATCH 14/26] Add more comments --- ckb-auth-rs/Cargo.toml | 1 + ckb-auth-rs/src/ckb_auth_dl.rs | 3 +++ tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/ckb-auth-rs/Cargo.toml b/ckb-auth-rs/Cargo.toml index aa25a6e..9f4a4a9 100644 --- a/ckb-auth-rs/Cargo.toml +++ b/ckb-auth-rs/Cargo.toml @@ -11,6 +11,7 @@ ckb2023 = ["ckb-std/ckb2023"] enable-dynamic-library = ["lazy_static"] dynamic-library-memory-200 = ["enable-dynamic-library"] +# enable these features when memory is not enough dynamic-library-memory-400 = ["enable-dynamic-library"] dynamic-library-memory-600 = ["enable-dynamic-library"] diff --git a/ckb-auth-rs/src/ckb_auth_dl.rs b/ckb-auth-rs/src/ckb_auth_dl.rs index 88d97e9..2034460 100644 --- a/ckb-auth-rs/src/ckb_auth_dl.rs +++ b/ckb-auth-rs/src/ckb_auth_dl.rs @@ -7,6 +7,9 @@ use ckb_std::{ }; use core::mem::size_of; +// By design, it is allowed to load multiple versions of ckb-auth into memory. +// These different ckb-auth can provide different authentication methods with +// the same interfaces. Extra memory is required for this scenario. #[cfg(feature = "dynamic-library-memory-200")] type DLContext = CKBDLContext<[u8; 200 * 1024]>; diff --git a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs index 220a058..fbe9535 100644 --- a/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs +++ b/tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs @@ -86,6 +86,8 @@ pub fn main() -> Result<(), Error> { }; ckb_auth(&entry, &id, &signature, &message)?; + // ckb_auth can be invoked multiple times for different signatures. Here we + // use the same one to demo the usage. ckb_auth(&entry, &id, &signature, &message)?; Ok(()) From bd31ce411c8780983f8070bd51331916a4627663 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:02:49 +0800 Subject: [PATCH 15/26] C ckb_auht.h support multi dynamic lib --- c/ckb_auth.h | 95 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 17 deletions(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index a42711a..78edea8 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -119,30 +119,91 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id, uint32_t message_size, uint8_t *pubkey_hash, uint32_t pubkey_hash_size); -static uint8_t g_code_buff[300 * 1024] __attribute__((aligned(RISCV_PGSIZE))); -static void* g_code_handle; +#ifndef CKB_AUTH_DL_BUFF_SIZE +#define CKB_AUTH_DL_BUFF_SIZE 1024 * 200 +#endif // CKB_AUTH_DL_MAX_COUNT + +#ifndef CKB_AUTH_DL_MAX_COUNT +#define CKB_AUTH_DL_MAX_COUNT 8 +#endif // CKB_AUTH_DL_MAX_COUNT + +static uint8_t g_dl_code_buffer[CKB_AUTH_DL_BUFF_SIZE] + __attribute__((aligned(RISCV_PGSIZE))); +static void *g_code_handle; + +typedef struct { + uint8_t *code_ptr; + size_t code_ptr_size; + + uint8_t code_hash[BLAKE2B_BLOCK_SIZE]; + uint8_t hash_type; + + void *handle; + ckb_auth_validate_t func; +} CkbDLCache; +static CkbDLCache g_dl_cache[CKB_AUTH_DL_MAX_COUNT]; +static size_t g_dl_cache_count = 0; + +int get_dl_func_by_code_hash(const uint8_t *code_hash, uint8_t hash_type, + ckb_auth_validate_t *out_func) { + // Find from cache + for (size_t i = 0; i < g_dl_cache_count; i++) { + CkbDLCache *cache = &g_dl_cache[i]; + if (memcmp(cache->code_hash, code_hash, BLAKE2B_BLOCK_SIZE) == 0 && + hash_type == cache->hash_type) { + *out_func = cache->func; + return 0; + } + } + + // get by cache + size_t buf_offset = 0; + if (g_dl_cache_count) { + CkbDLCache *cache = &g_dl_cache[g_dl_cache_count - 1]; + buf_offset = + (size_t)(cache->code_ptr + cache->code_ptr_size - g_dl_code_buffer); + if (buf_offset % RISCV_PGSIZE != 0) { + buf_offset += RISCV_PGSIZE - buf_offset % RISCV_PGSIZE; + } + } + + // load function by cell + CkbDLCache *cache = &g_dl_cache[g_dl_cache_count]; + memset(cache, 0, sizeof(CkbDLCache)); + cache->code_ptr = g_dl_code_buffer + buf_offset; + + int err = ckb_dlopen2(code_hash, hash_type, cache->code_ptr, + sizeof(g_dl_code_buffer) - buf_offset, &cache->handle, + &cache->code_ptr_size); + if (err != 0) { + return err; + } + cache->func = + (ckb_auth_validate_t)ckb_dlsym(cache->handle, "ckb_auth_validate"); + if (cache->func == 0) { + return CKB_INVALID_DATA; + } + + *out_func = cache->func; + memcpy(cache->code_hash, code_hash, BLAKE2B_BLOCK_SIZE); + cache->hash_type = hash_type; + + g_dl_cache_count += 1; + return 0; +} int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, uint32_t signature_size, const uint8_t *message32) { int err = 0; if (entry->entry_category == EntryCategoryDynamicLinking) { - size_t consumed_size = 0; - - if (!g_code_handle) { - err = ckb_dlopen2(entry->code_hash, entry->hash_type, g_code_buff, - sizeof(g_code_buff), &g_code_handle, &consumed_size); - if (err != 0) { - return err; - } - } - - ckb_auth_validate_t func = - (ckb_auth_validate_t)ckb_dlsym(g_code_handle, "ckb_auth_validate"); - if (func == 0) { - return CKB_INVALID_DATA; + ckb_auth_validate_t func = NULL; + err = + get_dl_func_by_code_hash(entry->code_hash, entry->hash_type, &func); + if (err) { + return err; } return func(id->algorithm_id, signature, signature_size, message32, 32, - id->content, 20); + id->content, 20); } else if (entry->entry_category == EntryCategoryExec || entry->entry_category == EntryCategorySpawn) { char algorithm_id_str[2 + 1]; From 2d0847fbfa42364ec3e33daf58e9600289b86c3e Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:06:13 +0800 Subject: [PATCH 16/26] Some numbers are replaced with macros --- c/ckb_auth.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index 78edea8..07b7c19 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -68,7 +68,7 @@ typedef struct { // TODO: when ready, move it into ckb-c-stdlib typedef struct CkbAuthType { uint8_t algorithm_id; - uint8_t content[20]; + uint8_t content[AUTH160_SIZE]; } CkbAuthType; enum EntryCategoryType { @@ -78,7 +78,7 @@ enum EntryCategoryType { }; typedef struct CkbEntryType { - uint8_t code_hash[32]; + uint8_t code_hash[BLAKE2B_BLOCK_SIZE]; uint8_t hash_type; uint8_t entry_category; } CkbEntryType; @@ -202,8 +202,8 @@ int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, if (err) { return err; } - return func(id->algorithm_id, signature, signature_size, message32, 32, - id->content, 20); + return func(id->algorithm_id, signature, signature_size, message32, BLAKE2B_BLOCK_SIZE, + id->content, AUTH160_SIZE); } else if (entry->entry_category == EntryCategoryExec || entry->entry_category == EntryCategorySpawn) { char algorithm_id_str[2 + 1]; @@ -211,8 +211,8 @@ int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, return CKB_INVALID_DATA; } char signature_str[signature_size * 2 + 1]; - char message_str[32 * 2 + 1]; - char pubkey_hash_str[20 * 2 + 1]; + char message_str[BLAKE2B_BLOCK_SIZE * 2 + 1]; + char pubkey_hash_str[AUTH160_SIZE * 2 + 1]; uint32_t bin2hex_output_len = 0; if (ckb_bin2hex(&id->algorithm_id, 1, algorithm_id_str, @@ -225,12 +225,12 @@ int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, sizeof(signature_str), &bin2hex_output_len, true)) { return CKB_INVALID_DATA; } - if (ckb_bin2hex(message32, 32, message_str, sizeof(message_str), + if (ckb_bin2hex(message32, BLAKE2B_BLOCK_SIZE, message_str, sizeof(message_str), &bin2hex_output_len, true)) { return CKB_INVALID_DATA; } - if (ckb_bin2hex(id->content, 20, pubkey_hash_str, + if (ckb_bin2hex(id->content, AUTH160_SIZE, pubkey_hash_str, sizeof(pubkey_hash_str), &bin2hex_output_len, true)) { return CKB_INVALID_DATA; } From bc07adbcdeac136dd91ab7e1f8e05eb791096f3f Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:08:00 +0800 Subject: [PATCH 17/26] ckb_auth.h: EntryCategoryDynamicLinking replace to EntryCategoryDynamicLibrary --- c/ckb_auth.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index 07b7c19..7c22c2b 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -73,7 +73,7 @@ typedef struct CkbAuthType { enum EntryCategoryType { EntryCategoryExec = 0, - EntryCategoryDynamicLinking = 1, + EntryCategoryDynamicLibrary = 1, EntryCategorySpawn = 2, }; @@ -195,7 +195,7 @@ int get_dl_func_by_code_hash(const uint8_t *code_hash, uint8_t hash_type, int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, uint32_t signature_size, const uint8_t *message32) { int err = 0; - if (entry->entry_category == EntryCategoryDynamicLinking) { + if (entry->entry_category == EntryCategoryDynamicLibrary) { ckb_auth_validate_t func = NULL; err = get_dl_func_by_code_hash(entry->code_hash, entry->hash_type, &func); From 71ea41810215be2e44713f14b41d7e5e0dea86ed Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:14:49 +0800 Subject: [PATCH 18/26] Init dynamic library global cache to zero --- c/ckb_auth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index 7c22c2b..ad8e4a7 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -128,7 +128,7 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id, #endif // CKB_AUTH_DL_MAX_COUNT static uint8_t g_dl_code_buffer[CKB_AUTH_DL_BUFF_SIZE] - __attribute__((aligned(RISCV_PGSIZE))); + __attribute__((aligned(RISCV_PGSIZE))) = {0}; static void *g_code_handle; typedef struct { From 8ec271cd4e25b406af5b841240e9fe6eaa8c80a4 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:15:11 +0800 Subject: [PATCH 19/26] Add comment --- tests/auth-c-lock/auth_c_lock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auth-c-lock/auth_c_lock.c b/tests/auth-c-lock/auth_c_lock.c index fa09113..c4063b2 100644 --- a/tests/auth-c-lock/auth_c_lock.c +++ b/tests/auth-c-lock/auth_c_lock.c @@ -221,6 +221,8 @@ int main() { break; } + // ckb_auth can be invoked multiple times for different signatures. + // Here we use the same one to demo the usages. ret = ckb_auth(&entry, &auth, lock_bytes_seg.ptr, lock_bytes_seg.size, msg32); if (ret) { return ret; From 14531e0923504a189d090c8cabeadef41436351c Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:21:33 +0800 Subject: [PATCH 20/26] Fix CI: warning with docker --- c/ckb_auth.h | 1 - 1 file changed, 1 deletion(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index ad8e4a7..fd20c2f 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -129,7 +129,6 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id, static uint8_t g_dl_code_buffer[CKB_AUTH_DL_BUFF_SIZE] __attribute__((aligned(RISCV_PGSIZE))) = {0}; -static void *g_code_handle; typedef struct { uint8_t *code_ptr; From bfc2db89f9dc5e6a522e6b4c4e3fb0a12e43e4cb Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:22:01 +0800 Subject: [PATCH 21/26] Update Cargo.lock --- tests/auth-spawn-tests/Cargo.lock | 4 ++++ tools/ckb-auth-cli/Cargo.lock | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/auth-spawn-tests/Cargo.lock b/tests/auth-spawn-tests/Cargo.lock index 6590a92..7fe1e11 100644 --- a/tests/auth-spawn-tests/Cargo.lock +++ b/tests/auth-spawn-tests/Cargo.lock @@ -361,6 +361,7 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", + "lazy_static", ] [[package]] @@ -1173,6 +1174,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "lazycell" diff --git a/tools/ckb-auth-cli/Cargo.lock b/tools/ckb-auth-cli/Cargo.lock index 3160d57..afe8325 100644 --- a/tools/ckb-auth-cli/Cargo.lock +++ b/tools/ckb-auth-cli/Cargo.lock @@ -326,6 +326,7 @@ dependencies = [ "blake2b-rs", "ckb-std", "hex", + "lazy_static", ] [[package]] @@ -1084,6 +1085,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "lazycell" @@ -1800,6 +1804,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "static_assertions" version = "1.1.0" From e9b77fda4e045c575fa3b5cc388bb270e7455582 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 16:52:17 +0800 Subject: [PATCH 22/26] Add macro CKB_AUTH_DISABLE_DYNAMIC_LIB. If defined, dynamic library is disabled. --- c/ckb_auth.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/c/ckb_auth.h b/c/ckb_auth.h index fd20c2f..20ad52e 100644 --- a/c/ckb_auth.h +++ b/c/ckb_auth.h @@ -119,6 +119,8 @@ typedef int (*ckb_auth_validate_t)(uint8_t auth_algorithm_id, uint32_t message_size, uint8_t *pubkey_hash, uint32_t pubkey_hash_size); +#ifndef CKB_AUTH_DISABLE_DYNAMIC_LIB + #ifndef CKB_AUTH_DL_BUFF_SIZE #define CKB_AUTH_DL_BUFF_SIZE 1024 * 200 #endif // CKB_AUTH_DL_MAX_COUNT @@ -191,18 +193,25 @@ int get_dl_func_by_code_hash(const uint8_t *code_hash, uint8_t hash_type, return 0; } +#endif // CKB_AUTH_DISABLE_DYNAMIC_LIB + int ckb_auth(CkbEntryType *entry, CkbAuthType *id, const uint8_t *signature, uint32_t signature_size, const uint8_t *message32) { int err = 0; if (entry->entry_category == EntryCategoryDynamicLibrary) { +#ifdef CKB_AUTH_DISABLE_DYNAMIC_LIB + // Disable DynamicLibrary via macro can save memory + return ERROR_INVALID_ARG; +#else // CKB_AUTH_DISABLE_DYNAMIC_LIB ckb_auth_validate_t func = NULL; err = get_dl_func_by_code_hash(entry->code_hash, entry->hash_type, &func); if (err) { return err; } - return func(id->algorithm_id, signature, signature_size, message32, BLAKE2B_BLOCK_SIZE, - id->content, AUTH160_SIZE); + return func(id->algorithm_id, signature, signature_size, message32, + BLAKE2B_BLOCK_SIZE, id->content, AUTH160_SIZE); +#endif // CKB_AUTH_DISABLE_DYNAMIC_LIB } else if (entry->entry_category == EntryCategoryExec || entry->entry_category == EntryCategorySpawn) { char algorithm_id_str[2 + 1]; From d493e865ffa477a0bb1ee856331a03967e4ef5fd Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 17:24:41 +0800 Subject: [PATCH 23/26] Add testcase: When disable dynamic lib --- tests/auth-c-lock/Makefile | 9 ++++++++- tests/auth-c-tests/src/lib.rs | 18 +++++++----------- tests/auth-c-tests/src/tests/mod.rs | 9 +++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/auth-c-lock/Makefile b/tests/auth-c-lock/Makefile index 5a04d4a..7212d94 100644 --- a/tests/auth-c-lock/Makefile +++ b/tests/auth-c-lock/Makefile @@ -19,7 +19,9 @@ AUTH_CFLAGS=$(subst ckb-c-std-lib,ckb-c-stdlib-2023,$(CFLAGS)) -Wno-dangling-poi # docker pull nervos/ckb-riscv-gnu-toolchain:gnu-jammy-20230214 BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:d3f649ef8079395eb25a21ceaeb15674f47eaa2d8cc23adc8bcdae3d5abce6ec -all: build/auth_c_lock +all: \ + build/auth_c_lock \ + build/auth_c_lock_disable_dl all-via-docker: docker run --platform linux/amd64 --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make -f tests/auth-c-lock/Makefile all" @@ -29,5 +31,10 @@ build/auth_c_lock: tests/auth-c-lock/auth_c_lock.c c/ckb_auth.h $(OBJCOPY) --only-keep-debug $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@ +build/auth_c_lock_disable_dl: tests/auth-c-lock/auth_c_lock.c c/ckb_auth.h + $(CC) $(AUTH_CFLAGS) $(LDFLAGS) -DCKB_AUTH_DISABLE_DYNAMIC_LIB -o $@ $^ + $(OBJCOPY) --only-keep-debug $@ $@.debug + $(OBJCOPY) --strip-debug --strip-all $@ + clean: rm -rf build/auth_c_lock diff --git a/tests/auth-c-tests/src/lib.rs b/tests/auth-c-tests/src/lib.rs index 1ba1dff..565c419 100644 --- a/tests/auth-c-tests/src/lib.rs +++ b/tests/auth-c-tests/src/lib.rs @@ -53,6 +53,8 @@ lazy_static! { Bytes::from(&include_bytes!("../../../build/auth_c_lock")[..]); pub static ref AUTH_RUST_LOCK: Bytes = Bytes::from(&include_bytes!("../../../build/auth-rust-demo")[..]); + pub static ref AUTH_C_LOCK_DISABLE_DL: Bytes = + Bytes::from(&include_bytes!("../../../build/auth_c_lock_disable_dl")[..]); pub static ref SECP256K1_DATA_BIN: Bytes = Bytes::from(&include_bytes!("../../../build/secp256k1_data_20210801")[..]); pub static ref ALWAYS_SUCCESS: Bytes = @@ -400,6 +402,7 @@ fn append_cells_deps( match &config.auth_lock_type { TestConfigAuthLockType::C => &AUTH_C_LOCK, TestConfigAuthLockType::Rust => &AUTH_RUST_LOCK, + TestConfigAuthLockType::CDisableDl => &AUTH_C_LOCK_DISABLE_DL, TestConfigAuthLockType::Rand(auth_bin) => auth_bin, }, ); @@ -484,14 +487,11 @@ pub fn gen_tx_with_grouped_args( let sighash_all_cell_data_hash = CellOutput::calc_data_hash(match &config.auth_lock_type { TestConfigAuthLockType::C => &AUTH_C_LOCK, TestConfigAuthLockType::Rust => &AUTH_RUST_LOCK, + TestConfigAuthLockType::CDisableDl => &AUTH_C_LOCK_DISABLE_DL, TestConfigAuthLockType::Rand(auth_bin) => auth_bin, }); - let sighash_all_cell_hash_type = if config.auth_lock_type == TestConfigAuthLockType::Rust { - ScriptHashType::Data2 - } else { - ScriptHashType::Data2 - }; + let sighash_all_cell_hash_type = ScriptHashType::Data2; for (args, inputs_size) in grouped_args { // setup dummy input unlock script @@ -548,6 +548,7 @@ pub enum TestConfigIncorrectSing { pub enum TestConfigAuthLockType { C, Rust, + CDisableDl, Rand(Bytes), } @@ -608,12 +609,7 @@ pub fn do_gen_args(config: &TestConfig, pub_key_hash: Option>) -> Bytes let hash_type: u8 = match &config.script_hash_type { Some(t) => t.clone(), - None => if config.auth_lock_type == TestConfigAuthLockType::Rust { - ScriptHashType::Data2 - } else { - ScriptHashType::Data2 - } - .into(), + None => ScriptHashType::Data2.into(), }; let mut entry_type = EntryType { diff --git a/tests/auth-c-tests/src/tests/mod.rs b/tests/auth-c-tests/src/tests/mod.rs index 87dc5f7..3441193 100644 --- a/tests/auth-c-tests/src/tests/mod.rs +++ b/tests/auth-c-tests/src/tests/mod.rs @@ -767,3 +767,12 @@ fn ethereum_recid() { &[AuthErrorCodeType::InvalidArg as i32], ); } + +#[test] +fn disable_dynamic_lib() { + let auth = auth_builder(AuthAlgorithmIdType::Ckb, false).unwrap(); + let mut config = TestConfig::new(&auth, EntryCategoryType::Exec, 1); + + config.auth_lock_type = TestConfigAuthLockType::CDisableDl; + assert_result_ok(verify_unit(&config), ""); +} From 9a2f645ac2c4881947a0a6713885ea56d43d75df Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 17:40:01 +0800 Subject: [PATCH 24/26] Update auth.md, about dynamic library --- docs/auth.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/auth.md b/docs/auth.md index 4c14e83..a43cbcd 100644 --- a/docs/auth.md +++ b/docs/auth.md @@ -20,9 +20,8 @@ For detailed instructions, please refer to the [README.md](../README.md) or [CI] ```C typedef struct CkbAuthType { uint8_t algorithm_id; - uint8_t content[20]; + uint8_t content[AUTH160_SIZE]; // #define AUTH160_SIZE 20 } CkbAuthType; - ``` It is a data structure with 21 bytes. The content can be hash (blake160 or some @@ -167,11 +166,11 @@ It is based on the following idea: First we define the "EntryType": ```C -typedef struct EntryType { - uint8_t code_hash[32]; +typedef struct CkbEntryType { + uint8_t code_hash[BLAKE2B_BLOCK_SIZE]; uint8_t hash_type; uint8_t entry_category; -} EntryType; +} CkbEntryType; ``` * code_hash/hash_type @@ -195,6 +194,9 @@ The first argument denotes the `algorithm_id` in `CkbAuthType` described above. A valid dynamic library denoted by `EntryType` should provide `ckb_auth_validate` exported function. +A dynamic library will create a cache in static memory for loading ckb-auth. This cache is initially set to 200k, and if adjustments are necessary, you can modify it by defining the macro CKB_AUTH_DL_BUFF_SIZE. However, it's important to note that the ckb-auth default is around 100k, and setting it too small may result in execution failure. CKB-VM allocates a maximum of 4M memory, and setting it too large may lead to insufficient memory. +By default, you can load up to 8 different ckb-auth libraries. If this is insufficient, you can modify it by defining CKB_AUTH_DL_MAX_COUNT. If you prefer not to use this feature, you can disable it by including CKB_AUTH_DISABLE_DYNAMIC_LIB. This will help conserve memory and reduce the size of the contract. + ### Entry Category: Spawn This category shares same arguments and behavior to dynamic library. It uses `spawn` instead of `dynamic library`. When entry category is `spawn`, its arguments format is below: @@ -212,6 +214,9 @@ The `auth algorithm id` denotes the `algorithm_id` in `CkbAuthType` described ab We can implement different auth algorithm ids in same code binary. +### Entry Category: Exec +The invocation method is the same as that of `Spawn`. + ### High Level APIs The following API can combine the low level APIs together: From 451d5815686f17e3910ecb255550e9447d8dd32f Mon Sep 17 00:00:00 2001 From: joii2020 Date: Wed, 13 Dec 2023 17:58:36 +0800 Subject: [PATCH 25/26] Fix CI: auth-c-lock add auth_c_lock_disable_dl --- tests/auth-c-lock/Makefile.clang | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/auth-c-lock/Makefile.clang b/tests/auth-c-lock/Makefile.clang index c29c700..cd22a07 100644 --- a/tests/auth-c-lock/Makefile.clang +++ b/tests/auth-c-lock/Makefile.clang @@ -20,12 +20,20 @@ CFLAGS := $(LLVM_CFLAGS) $(GCC_CFLAGS) \ LDFLAGS := -Wl,-static -Wl,--gc-sections AUTH_CFLAGS=$(subst ckb-c-std-lib,ckb-c-stdlib-2023,$(CFLAGS)) -Wno-array-bounds -all: build/auth_c_lock +all: \ + build/auth_c_lock \ + build/auth_c_lock_disable_dl build/auth_c_lock: tests/auth-c-lock/auth_c_lock.c c/ckb_auth.h $(CC) $(AUTH_CFLAGS) $(LDFLAGS) -o $@ tests/auth-c-lock/auth_c_lock.c $(OBJCOPY) --only-keep-debug $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@ + +build/auth_c_lock_disable_dl: tests/auth-c-lock/auth_c_lock.c c/ckb_auth.h + $(CC) $(AUTH_CFLAGS) $(LDFLAGS) -DCKB_AUTH_DISABLE_DYNAMIC_LIB -o $@ tests/auth-c-lock/auth_c_lock.c + $(OBJCOPY) --only-keep-debug $@ $@.debug + $(OBJCOPY) --strip-debug --strip-all $@ + clean: rm -rf build/auth_c_lock From 04a659e646c8c8d8c2e908450b4a1737fb4c3612 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Mon, 18 Dec 2023 10:20:38 +0800 Subject: [PATCH 26/26] rust dynamic lib cache remains aligned --- ckb-auth-rs/src/ckb_auth_dl.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ckb-auth-rs/src/ckb_auth_dl.rs b/ckb-auth-rs/src/ckb_auth_dl.rs index 2034460..0eb44e4 100644 --- a/ckb-auth-rs/src/ckb_auth_dl.rs +++ b/ckb-auth-rs/src/ckb_auth_dl.rs @@ -19,6 +19,8 @@ type DLContext = CKBDLContext<[u8; 400 * 1024]>; #[cfg(feature = "dynamic-library-memory-600")] type DLContext = CKBDLContext<[u8; 600 * 1024]>; +const RISCV_PGSIZE: usize = 4096; + type CkbAuthValidate = unsafe extern "C" fn( auth_algorithm_id: u8, signature: *const u8, @@ -87,6 +89,9 @@ impl CKBDLLoader { .load_with_offset(code_hash, hash_type, self.context_used, size) .map_err(|_| CkbAuthError::LoadDLError)?; self.context_used += lib.consumed_size(); + if self.context_used % RISCV_PGSIZE != 0 { + self.context_used += RISCV_PGSIZE - self.context_used % RISCV_PGSIZE; + } self.loaded_lib.insert(lib_key.clone(), lib); }; Ok(self.loaded_lib.get(&lib_key).unwrap())