diff --git a/contracts/ccc-btc-lock/src/entry.rs b/contracts/ccc-btc-lock/src/entry.rs index 6c3e982..244b943 100644 --- a/contracts/ccc-btc-lock/src/entry.rs +++ b/contracts/ccc-btc-lock/src/entry.rs @@ -1,65 +1,85 @@ use crate::error::Error; -use alloc::{string::String, vec::Vec}; -use ckb_lock_helper::{ - constant::{BTC_PREFIX, PREFIX, SUFFIX}, - generate_sighash_all, -}; +use alloc::vec::Vec; +use ckb_lock_helper::{generate_sighash_all, println_hex}; use ckb_std::{ ckb_constants::Source, high_level::{load_script, load_witness_args}, }; use k256::ecdsa::{RecoveryId, Signature, VerifyingKey}; -use ripemd::Ripemd160; -use sha2::{Digest, Sha256}; +use ripemd::{Digest, Ripemd160}; +use sha2::Sha256; + +fn ripemd160_sha256(msg: &[u8]) -> [u8; 20] { + ripemd160(&sha256(msg)) +} + +fn ripemd160(message: &[u8]) -> [u8; 20] { + let mut hasher = Ripemd160::new(); + hasher.update(message); + hasher.finalize().into() +} + +fn sha256(msg: &[u8]) -> [u8; 32] { + let mut hasher = Sha256::new(); + hasher.update(msg); + hasher.finalize().into() +} + +fn sha256_sha256(msg: &[u8]) -> [u8; 32] { + sha256(&sha256(msg)) +} + +fn message_hash(msg: &str) -> [u8; 32] { + // Only 32-bytes hex representation of the hash is allowed. + assert_eq!(msg.len(), 64); + // Text used to signify that a signed message follows and to prevent inadvertently signing a transaction. + const CKB_PREFIX: &str = "Signing a CKB transaction: 0x"; + const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected BTC wallet before signing this message\n"; + const BTC_PREFIX: &str = "Bitcoin Signed Message:\n"; + let mut data: Vec = Vec::new(); + assert_eq!(BTC_PREFIX.len(), 24); + data.push(24); + data.extend(BTC_PREFIX.as_bytes()); + data.push((CKB_PREFIX.len() + msg.len() + CKB_SUFFIX.len()) as u8); + data.extend(CKB_PREFIX.as_bytes()); + data.extend(msg.as_bytes()); + data.extend(CKB_SUFFIX.as_bytes()); + sha256_sha256(&data) +} pub fn entry() -> Result<(), Error> { let script = load_script()?; - let pubkey_hash = script.args().raw_data(); - if pubkey_hash.len() != 20 { + let pubkey_hash_expect = script.args().raw_data(); + if pubkey_hash_expect.len() != 20 { return Err(Error::WrongPubkeyHash); } - - let mut to_be_hashed: Vec = Default::default(); - assert_eq!(BTC_PREFIX.len(), 24); - to_be_hashed.push(BTC_PREFIX.len() as u8); - to_be_hashed.extend(BTC_PREFIX.as_bytes()); - let sighash_all = generate_sighash_all()?; let sighash_all_hex = hex::encode(&sighash_all); - let message1 = String::from(PREFIX) + &sighash_all_hex + SUFFIX; - - assert!(message1.len() < 256); - to_be_hashed.push(message1.len() as u8); - to_be_hashed.extend(message1.into_bytes()); - - // Double SHA-256 from bitcoin - let msg = Sha256::digest(&Sha256::digest(&to_be_hashed)); - + let digest_hash = message_hash(&sighash_all_hex); let witness_args = load_witness_args(0, Source::GroupInput)?; - let sig = witness_args + let sig_raw = witness_args .lock() .to_opt() .ok_or(Error::WrongSignatureFormat)? .raw_data(); - - if sig.len() != 65 { + if sig_raw.len() != 65 { return Err(Error::WrongSignatureFormat); } - let rec_id = match sig[0] { - 31 | 32 | 33 | 34 => sig[0] - 31, - 39 | 40 | 41 | 42 => sig[0] - 39, - _ => sig[0], + let rec_id = match sig_raw[0] { + 31 | 32 | 33 | 34 => sig_raw[0] - 31, + 39 | 40 | 41 | 42 => sig_raw[0] - 39, + _ => sig_raw[0], }; let rec_id = RecoveryId::try_from(rec_id).map_err(|_| Error::InvalidRecoverId)?; - let signature = Signature::from_slice(&sig[1..]).map_err(|_| Error::WrongSignatureFormat)?; - let recovered_key = VerifyingKey::recover_from_prehash(&msg, &signature, rec_id) - .map_err(|_| Error::CanNotRecover)?; - // TODO: double check its format - let recovered_key_bytes = recovered_key.to_sec1_bytes(); - // RIPEMD160 over SHA-256 for pubkey hashing - let pubkey_hash_result: [u8; 20] = - Ripemd160::digest(&Sha256::digest(&recovered_key_bytes)).into(); - if pubkey_hash_result.as_ref() != pubkey_hash.as_ref() { + let sig = Signature::from_slice(&sig_raw[1..]).map_err(|_| Error::WrongSignatureFormat)?; + let pubkey_result = VerifyingKey::recover_from_prehash(&digest_hash, &sig, rec_id) + .map_err(|_| Error::CanNotRecover)? + .to_sec1_bytes(); + assert!(pubkey_result.len() == 33); + let pubkey_hash_result = ripemd160_sha256(&pubkey_result); + println_hex("pubkey_result", pubkey_hash_result.as_ref()); + println_hex("pubkey_expect", pubkey_hash_expect.as_ref()); + if pubkey_hash_result.as_ref() != pubkey_hash_expect.as_ref() { return Err(Error::PubkeyHashMismatched); } Ok(()) diff --git a/crates/ckb-lock-helper/src/blake2b.rs b/crates/ckb-lock-helper/src/blake2b.rs index f329cf3..313f0bf 100644 --- a/crates/ckb-lock-helper/src/blake2b.rs +++ b/crates/ckb-lock-helper/src/blake2b.rs @@ -18,7 +18,7 @@ pub fn blake160(data: &[u8]) -> [u8; 20] { blake2b.update(data); blake2b.finalize(&mut hash); let mut ret = [0u8; 20]; - (&mut ret).copy_from_slice(&hash[0..20]); + ret.copy_from_slice(&hash[0..20]); ret } diff --git a/crates/ckb-lock-helper/src/constant.rs b/crates/ckb-lock-helper/src/constant.rs deleted file mode 100644 index 0d865b7..0000000 --- a/crates/ckb-lock-helper/src/constant.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub const PREFIX: &str = "Signing a CKB transaction: 0x"; -pub const SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected BTC wallet before signing this message\n"; -pub const BTC_PREFIX: &str = "Bitcoin Signed Message:\n"; diff --git a/crates/ckb-lock-helper/src/lib.rs b/crates/ckb-lock-helper/src/lib.rs index 3cc3120..19153f9 100644 --- a/crates/ckb-lock-helper/src/lib.rs +++ b/crates/ckb-lock-helper/src/lib.rs @@ -2,7 +2,6 @@ #![no_main] extern crate alloc; pub mod blake2b; -pub mod constant; pub mod error; use crate::blake2b::new_blake2b_stat; @@ -15,6 +14,10 @@ use ckb_std::debug; use ckb_std::high_level::{load_tx_hash, load_witness, load_witness_args}; use ckb_std::syscalls::{load_input_by_field, SysError}; +pub fn println_hex(name: &str, data: &[u8]) { + debug!("{}(len={}): {}", name, data.len(), hex::encode(data)); +} + pub fn generate_sighash_all() -> Result<[u8; 32], Error> { let mut blake2b_ctx = new_blake2b_stat(); let tx_hash = load_tx_hash()?; @@ -58,8 +61,9 @@ pub fn generate_sighash_all() -> Result<[u8; 32], Error> { } } let mut msg = [0u8; 32]; - debug!("Hashed {} bytes in sighash_all", blake2b_ctx.count()); + debug!("hashed {} bytes in sighash_all", blake2b_ctx.count()); blake2b_ctx.finalize(&mut msg); + println_hex("sighash_all_digest", &msg); Ok(msg) } diff --git a/tests/Cargo.lock b/tests/Cargo.lock index 610ae23..1a2a82f 100644 --- a/tests/Cargo.lock +++ b/tests/Cargo.lock @@ -3,30 +3,19 @@ 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.8" +name = "addr2line" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ - "getrandom 0.2.15", - "once_cell", - "version_check", + "gimli", ] [[package]] -name = "aho-corasick" -version = "1.1.3" +name = "adler" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "anyhow" @@ -41,16 +30,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] -name = "bit-vec" -version = "0.6.3" +name = "backtrace" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] [[package]] -name = "bitflags" -version = "1.3.2" +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64ct" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" @@ -74,6 +90,15 @@ dependencies = [ "cty", ] +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -89,6 +114,33 @@ dependencies = [ "serde", ] +[[package]] +name = "cacache" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" +dependencies = [ + "digest", + "either", + "futures", + "hex", + "libc", + "memmap2", + "miette", + "reflink-copy", + "serde", + "serde_derive", + "serde_json", + "sha1", + "sha2", + "ssri", + "tempfile", + "thiserror", + "tokio", + "tokio-stream", + "walkdir", +] + [[package]] name = "cc" version = "1.1.5" @@ -99,8 +151,19 @@ checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" name = "ccc-lock-tests" version = "0.1.0" dependencies = [ - "ckb-testtool", + "blake2b-ref", + "ckb-chain-spec", + "ckb-crypto", + "ckb-error", + "ckb-jsonrpc-types", + "ckb-script", + "ckb-traits", + "ckb-types", + "hex", + "k256", + "ripemd", "serde_json", + "sha2", ] [[package]] @@ -109,81 +172,63 @@ 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-chain-spec" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa9b89cadf419c220fa8e1c655af73540bbc010e8c0e177127644848a25830c2" +checksum = "e955d55380bbd2ca883b4426fb1483e61f06fe65c8b377d5d4bceeb03ecf07bb" dependencies = [ + "cacache", "ckb-constant", "ckb-crypto", "ckb-dao-utils", "ckb-error", "ckb-hash", "ckb-jsonrpc-types", + "ckb-logger", "ckb-pow", "ckb-rational", "ckb-resource", "ckb-traits", "ckb-types", - "ckb-util", "serde", "toml", ] [[package]] name = "ckb-channel" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c904fe3e29474e4d09e8e2775a472456242f8faf18edeeb8c71502710daa38" +checksum = "853f561e90ff59d858dc87c1ac385fae948984859c874fd8d3bd1bbab335889d" dependencies = [ "crossbeam-channel", ] [[package]] name = "ckb-constant" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d562e7156216f00c5bf55c8f4c86bc25f9ec0603fcfa6df9b66747462a031a" +checksum = "5baf91b16a3b8360c85211dfdff3d2adc0a1f3ae571ea6b1637d55d6b227e312" [[package]] name = "ckb-crypto" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abac585cec6f1562e374d66b369c55a52357b33a632d30d2e45cbc455183b22d" +checksum = "5e2094270f5632808cbff1c37a37ffb9b3e79f7a99e78927fb228d8c343793eb" dependencies = [ "ckb-fixed-hash", "faster-hex", "lazy_static", - "rand 0.7.3", + "rand", "secp256k1", "thiserror", ] -[[package]] -name = "ckb-dao" -version = "0.112.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c6b5b85ebe6e02bebcc1f1a4db28f1594e1a9e43e8922c05175459f798e844" -dependencies = [ - "byteorder", - "ckb-chain-spec", - "ckb-dao-utils", - "ckb-traits", - "ckb-types", -] - [[package]] name = "ckb-dao-utils" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff55485163b842c94061b755c9e6230d1a4bb092b6bc81d8387358911c750e70" +checksum = "6eb3606c602a424098317bfde4b7d6427d4fe5dfe1a6d4ebc831ce0308508085" dependencies = [ "byteorder", "ckb-error", @@ -192,9 +237,9 @@ dependencies = [ [[package]] name = "ckb-error" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8418901ea0d15a8e26255bec0b71be5c59056858f51968894796f77f7eefa3e" +checksum = "01041f8a1d7eeaf85caca3547bb78d929d6a4d62774509d7eb438b6bc310ba30" dependencies = [ "anyhow", "ckb-occupied-capacity", @@ -204,9 +249,9 @@ dependencies = [ [[package]] name = "ckb-fixed-hash" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1254aafda84e9abc85301e9e4c5b920c00a9bff0d42248fccf921b340ec5f13e" +checksum = "4a7491f18717b84827923935cc5adb1bcdf9c924e377b478d089f4694e7c779b" dependencies = [ "ckb-fixed-hash-core", "ckb-fixed-hash-macros", @@ -214,10 +259,11 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-core" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ffc2850ac8b5643c65913185020de747b290b447d1ee1fd59a2cfdf1a7ceb4f" +checksum = "9509f63fedb9b6e42cfd0db47d3dc5acb6b029da546d5d4451d08afc44c70cf8" dependencies = [ + "ckb_schemars", "faster-hex", "serde", "thiserror", @@ -225,9 +271,9 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-macros" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa5a19a7d18caa5a3a65e66506e28943e95696e286df44457a77692319de429" +checksum = "fdd89533a5da746f50798752a46f5f084f110c849335be94baf506790ebee931" dependencies = [ "ckb-fixed-hash-core", "proc-macro2", @@ -237,9 +283,9 @@ dependencies = [ [[package]] name = "ckb-gen-types" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a12020d50dd3757cde0fdc88d3837b7a2ab503fe38bd11be86ddace11318c77" +checksum = "7a0f2d0f4224507a027d25d64824dd0dc8d367c8b5bead30289eaffe1381a7fb" dependencies = [ "cfg-if", "ckb-error", @@ -252,9 +298,9 @@ dependencies = [ [[package]] name = "ckb-hash" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af660fc8746f7c756444e6aa47ede9a874206563b6a1ce1b230a5b86519392" +checksum = "d5754bc49cf76a7e8829fe6a7cf1eea1284cbca9777b521f072c76d6ae28d303" dependencies = [ "blake2b-ref", "blake2b-rs", @@ -262,11 +308,12 @@ dependencies = [ [[package]] name = "ckb-jsonrpc-types" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06798b5bacd7fd4125a34f1c9ebf45be59d50aff0ada003bb8b1c6634a447c73" +checksum = "ef7e123043ca3701cf05ba4c3699b34f3b179609109a4c8c3afa68922f722be7" dependencies = [ "ckb-types", + "ckb_schemars", "faster-hex", "serde", "serde_json", @@ -274,9 +321,9 @@ dependencies = [ [[package]] name = "ckb-logger" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8d8de618d1dbc59ba9e6338a55d17f370f89aa009064dcbdd7eb0c8e8782fe" +checksum = "59ebecd56c9acb453bdcb5c39e66b6b7f980bdf72b35515750bc295fa635287d" dependencies = [ "log", ] @@ -290,23 +337,11 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "ckb-mock-tx-types" -version = "0.112.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accabfa378c927109844630e4c90e0d7e7e6d6a9174c232f194f490b09e4b757" -dependencies = [ - "ckb-jsonrpc-types", - "ckb-traits", - "ckb-types", - "serde", -] - [[package]] name = "ckb-occupied-capacity" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be7132362f12a0495b3b24218afb4e774f9dc0d9254173d2444ec4ac1447461e" +checksum = "ee4aa07af7cec38d15cfe4c1ce150514fba5a4e78996bbbd098982106bee7d8d" dependencies = [ "ckb-occupied-capacity-core", "ckb-occupied-capacity-macros", @@ -314,18 +349,18 @@ dependencies = [ [[package]] name = "ckb-occupied-capacity-core" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4ebe8725d6ee4feb9d376e9a600b2c78cc1dbde5aa754c9a47de871ab917635" +checksum = "a63ed90996ba24ab26d5ac8ae22fd002a293f4a4e4526042e1adf84b1889e176" dependencies = [ "serde", ] [[package]] name = "ckb-occupied-capacity-macros" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201a21d35a377b76440ce12ca62b39e548d019a6330fbdcb40ac0f73fe976cb3" +checksum = "9a6aae3f1f8d194cd5bd4328c9c7281f0d7acc73976b2771576cdc06a9ed608f" dependencies = [ "ckb-occupied-capacity-core", "quote", @@ -334,9 +369,9 @@ dependencies = [ [[package]] name = "ckb-pow" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5895b4799fbb7e537ef0a778493b8f8678284c2bb20b476edce3f3375d1c4aa1" +checksum = "eb981de6e56107cd3e1660a9105bb07891277b21604946f70bf5097dd03690f7" dependencies = [ "byteorder", "ckb-hash", @@ -348,9 +383,9 @@ dependencies = [ [[package]] name = "ckb-rational" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5134dae6f59b1c10457d2a5def081865407e756dd42dd4c7aaf5d6c6bc92b6d1" +checksum = "ed570e816c80fffdfafb58c7c895df8c08c64ba56ce79d824e5ff976dd1a7381" dependencies = [ "numext-fixed-uint", "serde", @@ -358,9 +393,9 @@ dependencies = [ [[package]] name = "ckb-resource" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3c79b7c1586ca652d150b2cfdc5ec8594055659f04e30f832178a14313cfff4" +checksum = "d482493fabf4ce3670277d7dbaa5811872379535031431dc6b19699722c7b846" dependencies = [ "ckb-system-scripts", "ckb-types", @@ -373,9 +408,9 @@ dependencies = [ [[package]] name = "ckb-script" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058cb8c72a706bfc95c9b90f7c0256abbc4f44e9c5cabcbf7d1d882df977e82b" +checksum = "a2d6528e95a0f93d4a39e569b1ffffd60cbb0a9ae8f1c96dd465e2576ad510a9" dependencies = [ "byteorder", "ckb-chain-spec", @@ -402,48 +437,20 @@ dependencies = [ "phf", ] -[[package]] -name = "ckb-systemtime" -version = "0.112.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace369d09f2a4d5d0e0b97359cf34e3282a5a90171f685e8bbab1aa21e80cd54" - -[[package]] -name = "ckb-testtool" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed25ee2af0e899736bb95e4fd1dd4c89f03dd8ae0061ae708b83e405d394431" -dependencies = [ - "ckb-always-success-script", - "ckb-chain-spec", - "ckb-crypto", - "ckb-error", - "ckb-hash", - "ckb-jsonrpc-types", - "ckb-mock-tx-types", - "ckb-resource", - "ckb-script", - "ckb-traits", - "ckb-types", - "ckb-verification", - "lazy_static", - "rand 0.8.5", -] - [[package]] name = "ckb-traits" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3396b8f328bc76bdfd9bc14ddd984a07d08120cd4e661ba1dc23fecb3a7607a3" +checksum = "c528f704f3088ec2dd467d374920b64b2bbb9ed9c4e8e12931c069a99150d8bc" dependencies = [ "ckb-types", ] [[package]] name = "ckb-types" -version = "0.112.1" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2df7c7410664bc917f1b663c574ec7c0e25711fe4f63eb0043c47c197afb0875" +checksum = "9b05cc1c6aab0c40b323b233617b67860f9d679fac431a34d1f1b0853d700e9d" dependencies = [ "bit-vec", "bytes", @@ -466,73 +473,61 @@ dependencies = [ ] [[package]] -name = "ckb-util" -version = "0.112.1" +name = "ckb-vm" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e6326a9adcfe1f4afa14f1a0da267e5718873e28cc271a5e03fc57ff02ce233" +checksum = "a2c3d68dc7f891e5555c7ebc054722b28ab005e51c5076f54c20d36002dc8e83" dependencies = [ - "linked-hash-map", - "once_cell", - "parking_lot", - "regex", + "byteorder", + "bytes", + "cc", + "ckb-vm-definitions", + "derive_more", + "goblin 0.2.3", + "goblin 0.4.0", + "rand", + "scroll", + "serde", ] [[package]] -name = "ckb-verification" -version = "0.112.1" +name = "ckb-vm-definitions" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d157e70aea7d47af07b96415c952a7d97810572c659f8da2e9ecb6f98a1c7c" +checksum = "a2fdf9c8ee14409b2208d23b9ad88828242d7881153ddc04872b66d2e018a52f" 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", + "paste", ] [[package]] -name = "ckb-verification-traits" -version = "0.112.1" +name = "ckb_schemars" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43456c274b362c89a18388a95418f18adfebb3ab25950a09e267f00284e66fd" +checksum = "f21f99fca82a4eb8708e406e99246987b087ecc1e1babeece1a0b1d5238b1750" dependencies = [ - "bitflags 1.3.2", - "ckb-error", + "ckb_schemars_derive", + "dyn-clone", + "serde", + "serde_json", ] [[package]] -name = "ckb-vm" -version = "0.24.6" +name = "ckb_schemars_derive" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc004a826b9bc9319ffae0b8415690e1b5f1482266d55fbd43843aa40ddcd63" +checksum = "40c813b4fadbdd9f33b1cf02a1ddfa9537d955c8d2fbe150d1fc1684dbf78e73" dependencies = [ - "byteorder", - "bytes", - "cc", - "ckb-vm-definitions", - "derive_more", - "goblin 0.2.3", - "goblin 0.4.0", - "rand 0.7.3", - "scroll", - "serde", + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", ] [[package]] -name = "ckb-vm-definitions" -version = "0.24.6" +name = "const-oid" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ced3ff9d79b53d93c106720f6c1f855694290e33581850e05c859500eee83f" -dependencies = [ - "paste", -] +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "convert_case" @@ -540,6 +535,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -564,12 +568,44 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "cty" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -583,18 +619,101 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "eaglesong" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d978bd5d343e8ab9b5c0fc8d93ff9c602fdc96616ffff9c05ac7a155419b824" +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "faster-hex" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "flate2" version = "1.0.30" @@ -605,6 +724,106 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + [[package]] name = "getrandom" version = "0.1.16" @@ -627,6 +846,12 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "goblin" version = "0.2.3" @@ -659,12 +884,14 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.12.3" +name = "group" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ahash", + "ff", + "rand_core 0.6.4", + "subtle", ] [[package]] @@ -676,6 +903,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "includedir" version = "0.6.0" @@ -703,6 +945,20 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2", + "signature", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -716,23 +972,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[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.12" +name = "linux-raw-sys" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "log" @@ -740,21 +983,21 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[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.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + [[package]] name = "merkle-cbt" version = "0.3.2" @@ -764,6 +1007,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -813,7 +1079,7 @@ checksum = "6aab1d6457b97b49482f22a92f0f58a2f39bdd7f3b2f977eae67e8bc206aa980" dependencies = [ "heapsize", "numext-constructor", - "rand 0.7.3", + "rand", "serde", "thiserror", ] @@ -831,33 +1097,19 @@ dependencies = [ ] [[package]] -name = "once_cell" -version = "1.19.0" +name = "object" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ - "lock_api", - "parking_lot_core", + "memchr", ] [[package]] -name = "parking_lot_core" -version = "0.9.10" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "paste" @@ -891,7 +1143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ "phf_shared", - "rand 0.7.3", + "rand", ] [[package]] @@ -903,6 +1155,28 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "plain" version = "0.2.3" @@ -941,23 +1215,12 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha 0.2.2", + "rand_chacha", "rand_core 0.5.1", "rand_hc", "rand_pcg", ] -[[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.2.2" @@ -968,16 +1231,6 @@ dependencies = [ "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.5.1" @@ -1015,42 +1268,40 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.5.2" +name = "reflink-copy" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" dependencies = [ - "bitflags 2.6.0", + "cfg-if", + "rustix", + "windows", ] [[package]] -name = "regex" -version = "1.10.5" +name = "rfc6979" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", + "hmac", + "subtle", ] [[package]] -name = "regex-automata" -version = "0.4.7" +name = "ripemd" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "digest", ] [[package]] -name = "regex-syntax" -version = "0.8.4" +name = "rustc-demangle" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" @@ -1061,6 +1312,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1076,12 +1340,6 @@ 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" @@ -1102,6 +1360,20 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "secp256k1" version = "0.24.3" @@ -1146,6 +1418,17 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "serde_json" version = "1.0.120" @@ -1157,6 +1440,49 @@ dependencies = [ "serde", ] +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -1164,10 +1490,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] -name = "smallvec" -version = "1.13.2" +name = "slab" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "ssri" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" +dependencies = [ + "base64", + "digest", + "hex", + "miette", + "serde", + "sha-1", + "sha2", + "thiserror", + "xxhash-rust", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1191,6 +1553,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + [[package]] name = "thiserror" version = "1.0.62" @@ -1211,6 +1585,40 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.11" @@ -1220,12 +1628,24 @@ dependencies = [ "serde", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "version_check" version = "0.9.4" @@ -1285,6 +1705,70 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -1357,3 +1841,15 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "xxhash-rust" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63658493314859b4dfdf3fb8c1defd61587839def09582db50b8a4e93afca6bb" + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/Cargo.toml b/tests/Cargo.toml index a1f3231..0271213 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -8,5 +8,16 @@ version = "0.1.0" edition = "2021" [dependencies] -ckb-testtool = "0.10.2" +blake2b-ref = "0.3.1" +ckb-chain-spec = "0.116.0" +ckb-crypto = "0.116.0" +ckb-error = "0.116.0" +ckb-jsonrpc-types = "0.116.0" +ckb-script = "0.116.0" +ckb-traits = "0.116.0" +ckb-types = "0.116.0" +hex = "0.4" +k256 = "0.13.1" +ripemd = "0.1.3" serde_json = "1.0" +sha2 = "0.10.8" diff --git a/tests/src/core.rs b/tests/src/core.rs new file mode 100644 index 0000000..77bae12 --- /dev/null +++ b/tests/src/core.rs @@ -0,0 +1,238 @@ +use ckb_types::prelude::{Builder, Entity, Pack}; + +#[derive(Clone, Default)] +pub struct Resource { + pub cell: + std::collections::HashMap, +} + +impl ckb_traits::CellDataProvider for Resource { + fn get_cell_data( + &self, + out_point: &ckb_types::packed::OutPoint, + ) -> Option { + self.cell + .get(out_point) + .and_then(|cell_meta| cell_meta.mem_cell_data.clone()) + } + + fn get_cell_data_hash( + &self, + out_point: &ckb_types::packed::OutPoint, + ) -> Option { + self.cell + .get(out_point) + .and_then(|cell_meta| cell_meta.mem_cell_data_hash.clone()) + } +} + +impl ckb_traits::HeaderProvider for Resource { + fn get_header(&self, _: &ckb_types::packed::Byte32) -> Option { + unimplemented!() + } +} + +impl ckb_traits::ExtensionProvider for Resource { + fn get_block_extension( + &self, + _: &ckb_types::packed::Byte32, + ) -> Option { + unimplemented!() + } +} + +impl ckb_types::core::cell::CellProvider for Resource { + fn cell( + &self, + out_point: &ckb_types::packed::OutPoint, + eager_load: bool, + ) -> ckb_types::core::cell::CellStatus { + let _ = eager_load; + if let Some(data) = self.cell.get(out_point).cloned() { + ckb_types::core::cell::CellStatus::Live(data) + } else { + ckb_types::core::cell::CellStatus::Unknown + } + } +} + +impl ckb_types::core::cell::HeaderChecker for Resource { + fn check_valid( + &self, + _: &ckb_types::packed::Byte32, + ) -> Result<(), ckb_types::core::error::OutPointError> { + Ok(()) + } +} + +#[derive(Clone, Default)] +pub struct Verifier {} + +impl Verifier { + pub fn verify_prior( + &self, + tx_resolved: &ckb_types::core::cell::ResolvedTransaction, + _: &Resource, + ) { + let a = tx_resolved.transaction.outputs().item_count(); + let b = tx_resolved.transaction.outputs_data().item_count(); + assert_eq!(a, b); + } + + pub fn verify( + &self, + tx_resolved: &ckb_types::core::cell::ResolvedTransaction, + dl: &Resource, + ) -> Result { + self.verify_prior(&tx_resolved, &dl); + let hardfork = ckb_types::core::hardfork::HardForks { + ckb2021: ckb_types::core::hardfork::CKB2021::new_dev_default(), + ckb2023: ckb_types::core::hardfork::CKB2023::new_dev_default(), + }; + let consensus = ckb_chain_spec::consensus::ConsensusBuilder::default() + .hardfork_switch(hardfork) + .build(); + let mut verifier = ckb_script::TransactionScriptsVerifier::new( + std::sync::Arc::new(tx_resolved.clone()), + dl.clone(), + std::sync::Arc::new(consensus), + std::sync::Arc::new(ckb_script::TxVerifyEnv::new_submit( + &ckb_types::core::HeaderView::new_advanced_builder() + .epoch(ckb_types::core::EpochNumberWithFraction::new(0, 0, 1).pack()) + .build(), + )), + ); + verifier.set_debug_printer(|script: &ckb_types::packed::Byte32, msg: &str| { + let str = format!("Script({})", hex::encode(&script.as_slice()[..4])); + println!("{}: {}", str, msg); + }); + let result = verifier.verify(u64::MAX); + if result.is_ok() { + let cycles = (*result.as_ref().unwrap() as f64) / 1024.0 / 1024.0; + println_log(&format!("cycles is {:.1} M ", cycles)); + } + result + } +} + +#[derive(Clone, Default)] +pub struct Pickaxer { + outpoint_hash: ckb_types::packed::Byte32, + outpoint_i: u32, +} + +impl Pickaxer { + pub fn insert_cell_data( + &mut self, + dl: &mut Resource, + data: &[u8], + ) -> ckb_types::core::cell::CellMeta { + let cell_out_point = + ckb_types::packed::OutPoint::new(self.outpoint_hash.clone(), self.outpoint_i); + let cell_output = ckb_types::packed::CellOutput::new_builder() + .capacity(ckb_types::core::Capacity::bytes(0).unwrap().pack()) + .build(); + let cell_data = ckb_types::bytes::Bytes::copy_from_slice(data); + let cell_meta = + ckb_types::core::cell::CellMetaBuilder::from_cell_output(cell_output, cell_data) + .out_point(cell_out_point.clone()) + .build(); + dl.cell.insert(cell_out_point.clone(), cell_meta.clone()); + self.outpoint_i += 1; + cell_meta + } + + pub fn insert_cell_fund( + &mut self, + dl: &mut Resource, + lock: ckb_types::packed::Script, + kype: Option, + data: &[u8], + ) -> ckb_types::core::cell::CellMeta { + let cell_out_point = + ckb_types::packed::OutPoint::new(self.outpoint_hash.clone(), self.outpoint_i); + let cell_output = ckb_types::packed::CellOutput::new_builder() + .capacity(ckb_types::core::Capacity::bytes(0).unwrap().pack()) + .lock(lock) + .type_( + ckb_types::packed::ScriptOpt::new_builder() + .set(kype) + .build(), + ) + .build(); + let cell_data = ckb_types::bytes::Bytes::copy_from_slice(data); + let cell_meta = + ckb_types::core::cell::CellMetaBuilder::from_cell_output(cell_output, cell_data) + .out_point(cell_out_point.clone()) + .build(); + dl.cell.insert(cell_out_point.clone(), cell_meta.clone()); + self.outpoint_i += 1; + cell_meta + } + + pub fn create_cell_dep( + &self, + cell_meta: &ckb_types::core::cell::CellMeta, + ) -> ckb_types::packed::CellDep { + ckb_types::packed::CellDep::new_builder() + .out_point(cell_meta.out_point.clone()) + .dep_type(ckb_types::core::DepType::Code.into()) + .build() + } + + pub fn create_cell_input( + &self, + cell_meta: &ckb_types::core::cell::CellMeta, + ) -> ckb_types::packed::CellInput { + ckb_types::packed::CellInput::new(cell_meta.out_point.clone(), 0) + } + + pub fn create_cell_output( + &self, + lock: ckb_types::packed::Script, + kype: Option, + ) -> ckb_types::packed::CellOutput { + ckb_types::packed::CellOutput::new_builder() + .capacity(ckb_types::core::Capacity::bytes(0).unwrap().pack()) + .lock(lock) + .type_( + ckb_types::packed::ScriptOpt::new_builder() + .set(kype) + .build(), + ) + .build() + } + + pub fn create_script( + &self, + cell_meta: &ckb_types::core::cell::CellMeta, + args: &[u8], + ) -> ckb_types::packed::Script { + ckb_types::packed::Script::new_builder() + .args(args.pack()) + .code_hash(cell_meta.mem_cell_data_hash.clone().unwrap()) + .hash_type(ckb_types::core::ScriptHashType::Data1.into()) + .build() + } +} + +pub fn println_hex(name: &str, data: &[u8]) { + println!( + "Tester(........): {}(len={}): {}", + name, + data.len(), + hex::encode(data) + ); +} + +pub fn println_log(data: &str) { + println!("Tester(........): {}", data); +} + +pub fn println_rtx(tx_resolved: &ckb_types::core::cell::ResolvedTransaction) { + let tx_json = ckb_jsonrpc_types::TransactionView::from(tx_resolved.transaction.clone()); + println!( + "Tester(........): {}", + serde_json::to_string_pretty(&tx_json).unwrap() + ); +} diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 08d58ca..61ac770 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -1,3 +1,3 @@ +pub mod core; #[cfg(test)] -mod tests; - +mod test_btc; diff --git a/tests/src/test_btc.rs b/tests/src/test_btc.rs new file mode 100644 index 0000000..6153efd --- /dev/null +++ b/tests/src/test_btc.rs @@ -0,0 +1,135 @@ +use crate::core::{println_hex, println_log, Pickaxer, Resource, Verifier}; +use ckb_types::prelude::{Builder, Entity, Pack}; +use sha2::Digest; + +static BINARY_CCC_LOCK_BTC: &[u8] = include_bytes!("../../build/release/ccc-btc-lock"); + +fn blake2b(data: &[u8]) -> [u8; 32] { + let mut blake2b = blake2b_ref::Blake2bBuilder::new(32) + .personal(b"ckb-default-hash") + .build(); + let mut hash = [0u8; 32]; + blake2b.update(data); + blake2b.finalize(&mut hash); + hash +} + +fn ripemd160_sha256(msg: &[u8]) -> [u8; 20] { + ripemd160(&sha256(msg)) +} + +fn ripemd160(message: &[u8]) -> [u8; 20] { + let mut hasher = ripemd::Ripemd160::new(); + hasher.update(message); + hasher.finalize().into() +} + +fn sha256(msg: &[u8]) -> [u8; 32] { + let mut hasher = sha2::Sha256::new(); + hasher.update(msg); + hasher.finalize().into() +} + +fn sha256_sha256(msg: &[u8]) -> [u8; 32] { + sha256(&sha256(msg)) +} + +fn message_hash(msg: &str) -> [u8; 32] { + // Only 32-bytes hex representation of the hash is allowed. + assert_eq!(msg.len(), 64); + // Text used to signify that a signed message follows and to prevent inadvertently signing a transaction. + pub const CKB_PREFIX: &str = "Signing a CKB transaction: 0x"; + pub const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected BTC wallet before signing this message\n"; + pub const BTC_PREFIX: &str = "Bitcoin Signed Message:\n"; + let mut data: Vec = Vec::new(); + assert_eq!(BTC_PREFIX.len(), 24); + data.push(24); + data.extend(BTC_PREFIX.as_bytes()); + data.push((CKB_PREFIX.len() + msg.len() + CKB_SUFFIX.len()) as u8); + data.extend(CKB_PREFIX.as_bytes()); + data.extend(msg.as_bytes()); + data.extend(CKB_SUFFIX.as_bytes()); + sha256_sha256(&data) +} + +fn message_sign(msg: &str, prikey: k256::ecdsa::SigningKey) -> [u8; 65] { + let m = message_hash(msg); + let sigrec = prikey.sign_prehash_recoverable(&m).unwrap(); + let mut r = [0u8; 65]; + r[0] = sigrec.1.to_byte(); + r[1..65].copy_from_slice(&sigrec.0.to_vec()); + r +} + +#[test] +fn test_success() { + let mut dl = Resource::default(); + let mut px = Pickaxer::default(); + let tx_builder = ckb_types::core::TransactionBuilder::default(); + + // Create prior knowledge + let prikey_byte: [u8; 32] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, + ]; + let prikey = k256::ecdsa::SigningKey::from_slice(&prikey_byte).unwrap(); + let pubkey = prikey.verifying_key(); + let pubkey_hash = ripemd160_sha256(&pubkey.to_sec1_bytes()); + + // Create cell meta + let cell_meta_ccc_lock_btc = px.insert_cell_data(&mut dl, BINARY_CCC_LOCK_BTC); + let cell_meta_i = px.insert_cell_fund( + &mut dl, + px.create_script(&cell_meta_ccc_lock_btc, &pubkey_hash), + None, + &[], + ); + // Create cell dep + let tx_builder = tx_builder.cell_dep(px.create_cell_dep(&cell_meta_ccc_lock_btc)); + // Create input + let tx_builder = tx_builder.input(px.create_cell_input(&cell_meta_i)); + // Create output + let tx_builder = tx_builder.output(px.create_cell_output( + px.create_script(&cell_meta_ccc_lock_btc, &pubkey_hash), + None, + )); + // Create output data + let tx_builder = tx_builder.output_data(ckb_types::packed::Bytes::default()); + // Create witness + let tx_hash = tx_builder.clone().build().hash().raw_data(); + let witness = ckb_types::packed::WitnessArgs::new_builder() + .lock( + Some(ckb_types::bytes::Bytes::copy_from_slice(&{ + let mut digest_data: Vec = vec![]; + digest_data.extend(&tx_hash); + let witness = ckb_types::packed::WitnessArgs::new_builder() + .lock(Some(ckb_types::bytes::Bytes::from(vec![0u8; 65])).pack()) + .build(); + let witness_len = witness.as_slice().len() as u64; + digest_data.extend(&witness_len.to_le_bytes()); + digest_data.extend(&witness.as_bytes()); + println_log(&format!( + "hashed {} bytes in sighash_all", + digest_data.len() + )); + let digest = blake2b(&digest_data); + println_hex("sighash_all_digest", &digest); + message_sign(&hex::encode(&digest), prikey) + })) + .pack(), + ) + .build(); + let tx_builder = tx_builder.witness(witness.as_bytes().pack()); + + // Verify transaction + let tx = tx_builder.build(); + let tx_resolved = ckb_types::core::cell::resolve_transaction( + tx, + &mut std::collections::HashSet::new(), + &dl, + &dl, + ) + .unwrap(); + let verifier = Verifier::default(); + verifier.verify(&tx_resolved, &dl).unwrap(); +} diff --git a/tests/src/tests.rs b/tests/src/tests.rs deleted file mode 100644 index 6c039d4..0000000 --- a/tests/src/tests.rs +++ /dev/null @@ -1,2 +0,0 @@ -// Include your tests here -// See https://github.com/xxuejie/ckb-native-build-sample/blob/main/tests/src/tests.rs for examples