From 2afefde8b423f0a6399cb8483cf3a3eec14595a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Talip=20Akal=C4=B1n?= <56600661+otaliptus@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:30:03 +0300 Subject: [PATCH 1/2] Fix ci (#284) --- examples/demo-rollup/tests/evm/mod.rs | 2 +- .../src/prover_service/parallel/prover.rs | 1 + .../sov-modules-macros/src/rpc/rpc_gen.rs | 1 + ...xpose_rpc_first_generic_not_context.stderr | 252 ++++++++++++++++++ 4 files changed, 255 insertions(+), 1 deletion(-) diff --git a/examples/demo-rollup/tests/evm/mod.rs b/examples/demo-rollup/tests/evm/mod.rs index b08c590de..d09d63c0e 100644 --- a/examples/demo-rollup/tests/evm/mod.rs +++ b/examples/demo-rollup/tests/evm/mod.rs @@ -49,7 +49,7 @@ async fn web3_rpc_tests() -> Result<(), anyhow::Error> { assert_eq!( test_client.web3_client_version().await, - format!("citrea/{}/{}/rust-1.76.0", tag, arch) + format!("citrea/{}/{}/rust-1.77.0", tag, arch) ); assert_eq!( test_client diff --git a/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs b/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs index 3cf293775..13714a555 100644 --- a/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs +++ b/full-node/sov-stf-runner/src/prover_service/parallel/prover.rs @@ -18,6 +18,7 @@ use crate::{ enum ProverStatus { WitnessSubmitted(StateTransitionData), ProvingInProgress, + #[allow(dead_code)] Proved(Proof), Err(anyhow::Error), } diff --git a/module-system/sov-modules-macros/src/rpc/rpc_gen.rs b/module-system/sov-modules-macros/src/rpc/rpc_gen.rs index c71d298b3..e3dba3f1d 100644 --- a/module-system/sov-modules-macros/src/rpc/rpc_gen.rs +++ b/module-system/sov-modules-macros/src/rpc/rpc_gen.rs @@ -365,6 +365,7 @@ pub(crate) fn rpc_gen( build_rpc_trait(attrs, type_name.clone(), input) } +#[allow(dead_code)] struct TypeList(pub Punctuated); impl Parse for TypeList { diff --git a/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr b/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr index 2bbff2f3a..024ae486d 100644 --- a/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr +++ b/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr @@ -5,3 +5,255 @@ error[E0220]: associated type `Storage` not found for `S` | ^^^^^^^^^^^^^ associated type `Storage` not found | = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:16 + | +99 | struct Runtime { + | ^ the trait `sov_modules_api::Context` is not implemented for `S` + | +note: required by a bound in `sov_modules_api::Genesis::Context` + --> $WORKSPACE/module-system/sov-modules-core/src/module/mod.rs + | + | type Context: Context; + | ^^^^^^^ required by this bound in `Genesis::Context` +help: consider further restricting this bound + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ + +error[E0277]: `::Data` cannot be shared between threads safely + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be shared between threads safely + | + = help: within `Runtime`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `Runtime: std::marker::Sync` +note: required because it appears within the type `PhantomData<::Data>` + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ +note: required because it appears within the type `sov_modules_api::StateValue<::Data>` + --> $WORKSPACE/module-system/sov-modules-api/src/containers/value.rs + | + | pub struct StateValue { + | ^^^^^^^^^^ +note: required because it appears within the type `QueryModule::Data>` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 + | +33 | pub struct QueryModule { + | ^^^^^^^^^^^ +note: required because it appears within the type `Runtime` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^ +note: required by a bound in `sov_modules_api::DispatchCall` + --> $WORKSPACE/module-system/sov-modules-core/src/module/dispatch.rs + | + | pub trait DispatchCall: Send + Sync { + | ^^^^ required by this bound in `DispatchCall` +help: consider further restricting the associated type + | +99 | struct Runtime where ::Data: std::marker::Sync { + | ++++++++++++++++++++++++++++++++++++++++++++++ + +error[E0277]: `::Data` cannot be sent between threads safely + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be sent between threads safely + | + = help: within `Runtime`, the trait `Send` is not implemented for `::Data`, which is required by `Runtime: Send` +note: required because it appears within the type `PhantomData<::Data>` + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ +note: required because it appears within the type `sov_modules_api::StateValue<::Data>` + --> $WORKSPACE/module-system/sov-modules-api/src/containers/value.rs + | + | pub struct StateValue { + | ^^^^^^^^^^ +note: required because it appears within the type `QueryModule::Data>` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:33:16 + | +33 | pub struct QueryModule { + | ^^^^^^^^^^^ +note: required because it appears within the type `Runtime` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:8 + | +99 | struct Runtime { + | ^^^^^^^ +note: required by a bound in `sov_modules_api::DispatchCall` + --> $WORKSPACE/module-system/sov-modules-core/src/module/dispatch.rs + | + | pub trait DispatchCall: Send + Sync { + | ^^^^ required by this bound in `DispatchCall` +help: consider further restricting the associated type + | +99 | struct Runtime where ::Data: Send { + | +++++++++++++++++++++++++++++++++ + +error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:99:16 + | +99 | struct Runtime { + | ^ the trait `sov_modules_api::Context` is not implemented for `S` + | +note: required by a bound in `sov_modules_api::DispatchCall::Context` + --> $WORKSPACE/module-system/sov-modules-core/src/module/dispatch.rs + | + | type Context: Context; + | ^^^^^^^ required by this bound in `DispatchCall::Context` +help: consider further restricting this bound + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ + +error[E0277]: `::Data` cannot be shared between threads safely + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ `::Data` cannot be shared between threads safely + | + = help: within `RuntimeCall`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `RuntimeCall: std::marker::Sync` +note: required because it appears within the type `RuntimeCall` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ +note: required by a bound in `sov_modules_api::DispatchCall::Decodable` + --> $WORKSPACE/module-system/sov-modules-core/src/module/dispatch.rs + | + | type Decodable: Send + Sync; + | ^^^^ required by this bound in `DispatchCall::Decodable` + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting the associated type + | +99 | struct Runtime where ::Data: std::marker::Sync { + | ++++++++++++++++++++++++++++++++++++++++++++++ + +error[E0277]: `::Data` cannot be sent between threads safely + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ `::Data` cannot be sent between threads safely + | + = help: within `RuntimeCall`, the trait `Send` is not implemented for `::Data`, which is required by `RuntimeCall: Send` +note: required because it appears within the type `RuntimeCall` + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ +note: required by a bound in `sov_modules_api::DispatchCall::Decodable` + --> $WORKSPACE/module-system/sov-modules-core/src/module/dispatch.rs + | + | type Decodable: Send + Sync; + | ^^^^ required by this bound in `DispatchCall::Decodable` + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting the associated type + | +99 | struct Runtime where ::Data: Send { + | +++++++++++++++++++++++++++++++++ + +error[E0277]: the trait bound `S: Spec` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` + | + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +99 | struct Runtime { + | +++++++++++++++++++++++ + +error[E0277]: the trait bound `S: Spec` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` + | + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +99 | struct Runtime { + | +++++++++++++++++++++++ + +error[E0053]: method `get_working_set` has an incompatible type for trait + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ + | | + | expected type parameter `C`, found type parameter `S` + | help: change the output type to match the trait: `sov_modules_api::WorkingSet` +... +99 | struct Runtime { + | - - expected type parameter + | | + | found type parameter + | +note: type in trait + --> tests/rpc/expose_rpc_first_generic_not_context.rs:86:57 + | +86 | pub fn query_value(&self, working_set: &mut WorkingSet) -> RpcResult { + | ^^^^^^^^^^^^^ + = note: expected signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` + found signature `fn(&RpcStorage<_, _>) -> sov_modules_api::WorkingSet` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:10 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | +note: required by a bound in `sov_modules_api::WorkingSet` + --> $WORKSPACE/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ + +error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + | +97 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] + | ^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | +note: required by a bound in `sov_modules_api::WorkingSet` + --> $WORKSPACE/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ + +error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:1 + | +96 | #[expose_rpc] + | ^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` + | +note: required by a bound in `sov_modules_api::WorkingSet` + --> $WORKSPACE/module-system/sov-modules-core/src/storage/scratchpad.rs + | + | pub struct WorkingSet { + | ^^^^^^^ required by this bound in `WorkingSet` + = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +99 | struct Runtime { + | ++++++++++++++++++++++++++ From 239bb3da2577e68a9e4849d47ec126d0e2c63abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Talip=20Akal=C4=B1n?= <56600661+otaliptus@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:31:09 +0300 Subject: [PATCH 2/2] Fix test + update deps (#280) * Fix test + update deps * Add comment --- Cargo.lock | 58 +++++++++++++++++++----- adapters/bitcoin/Cargo.toml | 2 +- adapters/bitcoin/src/helpers/builders.rs | 55 +++++++++++----------- adapters/bitcoin/src/helpers/parsers.rs | 45 +++++++++++++++--- adapters/bitcoin/src/service.rs | 8 ++-- adapters/bitcoin/src/spec/proof.rs | 2 +- 6 files changed, 119 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 863d93c2f..e25f0ee21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1024,6 +1024,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.10.0-beta" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" + [[package]] name = "beef" version = "0.5.2" @@ -1106,15 +1112,16 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitcoin" -version = "0.30.2" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1945a5048598e4189e239d3f809b19bdad4845c4b2ba400d304d2dcf26d2c462" +checksum = "fd00f3c09b5f21fb357abe32d29946eb8bb7a0862bae62c0b5e4a692acbbe73c" dependencies = [ - "bech32", - "bitcoin-private", - "bitcoin_hashes", + "bech32 0.10.0-beta", + "bitcoin-internals", + "bitcoin_hashes 0.13.0", + "hex-conservative", "hex_lit", - "secp256k1 0.27.0", + "secp256k1 0.28.2", "serde", ] @@ -1142,6 +1149,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "bitcoin-internals" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" +dependencies = [ + "serde", +] + [[package]] name = "bitcoin-private" version = "0.1.0" @@ -1155,6 +1171,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" dependencies = [ "bitcoin-private", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" +dependencies = [ + "bitcoin-internals", + "hex-conservative", "serde", ] @@ -1716,7 +1742,7 @@ version = "0.1.0" source = "git+https://github.com/eigerco/celestia-node-rs.git?rev=66b7c6c#66b7c6cd58213c0cbf79207ba549cef82764ddca" dependencies = [ "base64 0.21.7", - "bech32", + "bech32 0.9.1", "bytes", "celestia-proto", "cid", @@ -2014,7 +2040,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" dependencies = [ "base64 0.21.7", - "bech32", + "bech32 0.9.1", "bs58 0.5.0", "digest 0.10.7", "generic-array 0.14.7", @@ -4287,6 +4313,12 @@ dependencies = [ "serde", ] +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + [[package]] name = "hex-literal" version = "0.4.1" @@ -9213,7 +9245,6 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" dependencies = [ - "bitcoin_hashes", "rand 0.8.5", "secp256k1-sys 0.8.1", "serde", @@ -9225,7 +9256,10 @@ version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ + "bitcoin_hashes 0.12.0", + "rand 0.8.5", "secp256k1-sys 0.9.2", + "serde", ] [[package]] @@ -9905,7 +9939,7 @@ dependencies = [ "anyhow", "async-trait", "base64 0.21.7", - "bech32", + "bech32 0.9.1", "borsh", "celestia-proto", "celestia-rpc", @@ -10227,7 +10261,7 @@ version = "0.3.0" dependencies = [ "anyhow", "arbitrary", - "bech32", + "bech32 0.9.1", "bincode", "borsh", "clap 4.5.2", @@ -10265,7 +10299,7 @@ version = "0.3.0" dependencies = [ "anyhow", "arbitrary", - "bech32", + "bech32 0.9.1", "borsh", "derive_more", "digest 0.10.7", diff --git a/adapters/bitcoin/Cargo.toml b/adapters/bitcoin/Cargo.toml index 354dd0dbb..99884ae4e 100644 --- a/adapters/bitcoin/Cargo.toml +++ b/adapters/bitcoin/Cargo.toml @@ -32,7 +32,7 @@ borsh = { workspace = true } anyhow = { workspace = true } thiserror = { workspace = true } -bitcoin = { version = "0.30.1", features = ["serde", "rand"] } +bitcoin = { version = "0.31.1", features = ["serde", "rand"] } brotli = "3.3.4" async-recursion = "1.0.5" futures.workspace = true diff --git a/adapters/bitcoin/src/helpers/builders.rs b/adapters/bitcoin/src/helpers/builders.rs index c927acaca..b42dac814 100644 --- a/adapters/bitcoin/src/helpers/builders.rs +++ b/adapters/bitcoin/src/helpers/builders.rs @@ -9,16 +9,16 @@ use bitcoin::blockdata::opcodes::all::{OP_CHECKSIG, OP_ENDIF, OP_IF}; use bitcoin::blockdata::opcodes::OP_FALSE; use bitcoin::blockdata::script; use bitcoin::hashes::{sha256d, Hash}; -use bitcoin::key::{TapTweak, TweakedPublicKey, UntweakedKeyPair}; -use bitcoin::psbt::Prevouts; +use bitcoin::key::{TapTweak, TweakedPublicKey, UntweakedKeypair}; use bitcoin::script::PushBytesBuf; use bitcoin::secp256k1::constants::SCHNORR_SIGNATURE_SIZE; use bitcoin::secp256k1::schnorr::Signature; use bitcoin::secp256k1::{self, Secp256k1, SecretKey, XOnlyPublicKey}; -use bitcoin::sighash::SighashCache; +use bitcoin::sighash::{Prevouts, SighashCache}; use bitcoin::taproot::{ControlBlock, LeafVersion, TapLeafHash, TaprootBuilder}; use bitcoin::{ - Address, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, Witness, + Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, + Witness, }; use brotli::{CompressorWriter, DecompressorWriter}; @@ -45,7 +45,7 @@ pub fn sign_blob_with_private_key( let message = sha256d::Hash::hash(blob).to_byte_array(); let secp = Secp256k1::new(); let public_key = secp256k1::PublicKey::from_secret_key(&secp, private_key); - let msg = secp256k1::Message::from_slice(&message).unwrap(); + let msg = secp256k1::Message::from_digest_slice(&message).unwrap(); let sig = secp.sign_ecdsa(&msg, private_key); Ok(( sig.serialize_compact().to_vec(), @@ -64,7 +64,7 @@ fn get_size( input: inputs.clone(), output: outputs.clone(), lock_time: LockTime::ZERO, - version: 2, + version: bitcoin::transaction::Version(2), }; for i in 0..tx.input.len() { @@ -147,7 +147,7 @@ fn build_commit_transaction( }], &vec![TxOut { script_pubkey: recipient.clone().script_pubkey(), - value: output_value, + value: Amount::from_sat(output_value), }], None, None, @@ -176,7 +176,7 @@ fn build_commit_transaction( let mut outputs: Vec = vec![]; outputs.push(TxOut { - value: output_value, + value: Amount::from_sat(output_value), script_pubkey: recipient.script_pubkey(), }); @@ -184,7 +184,7 @@ fn build_commit_transaction( if let Some(excess) = sum.checked_sub(input_total) { if excess >= 546 { outputs.push(TxOut { - value: excess, + value: Amount::from_sat(excess), script_pubkey: change_address.script_pubkey(), }); } else { @@ -211,7 +211,7 @@ fn build_commit_transaction( if size == last_size || direct_return { break Transaction { lock_time: LockTime::ZERO, - version: 2, + version: bitcoin::transaction::Version(2), input: inputs, output: outputs, }; @@ -235,7 +235,7 @@ fn build_reveal_transaction( control_block: &ControlBlock, ) -> Result { let outputs: Vec = vec![TxOut { - value: output_value, + value: Amount::from_sat(output_value), script_pubkey: recipient.script_pubkey(), }]; @@ -255,13 +255,14 @@ fn build_reveal_transaction( let input_total = output_value + fee; - if input_utxo.value < 546 || input_utxo.value < input_total { + if input_utxo.value < Amount::from_sat(546) || input_utxo.value < Amount::from_sat(input_total) + { return Err(anyhow::anyhow!("input UTXO not big enough")); } let tx = Transaction { lock_time: LockTime::ZERO, - version: 2, + version: bitcoin::transaction::Version(2), input: inputs, output: outputs, }; @@ -288,7 +289,7 @@ pub fn create_inscription_transactions( ) -> Result<(Transaction, Transaction), anyhow::Error> { // Create commit key let secp256k1 = Secp256k1::new(); - let key_pair = UntweakedKeyPair::new(&secp256k1, &mut rand::thread_rng()); + let key_pair = UntweakedKeypair::new(&secp256k1, &mut rand::thread_rng()); let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair); // start creating inscription content @@ -375,7 +376,7 @@ pub fn create_inscription_transactions( }], &vec![TxOut { script_pubkey: recipient.clone().script_pubkey(), - value: reveal_value, + value: Amount::from_sat(reveal_value), }], Some(&reveal_script), Some(&control_block), @@ -425,7 +426,7 @@ pub fn create_inscription_transactions( // sign reveal tx data let signature = secp256k1.sign_schnorr_with_rng( - &secp256k1::Message::from_slice(signature_hash.as_byte_array()) + &secp256k1::Message::from_digest_slice(signature_hash.as_byte_array()) .expect("should be cryptographically secure hash"), &key_pair, &mut rand::thread_rng(), @@ -470,7 +471,7 @@ mod tests { use bitcoin::secp256k1::constants::SCHNORR_SIGNATURE_SIZE; use bitcoin::secp256k1::schnorr::Signature; use bitcoin::taproot::ControlBlock; - use bitcoin::{Address, ScriptBuf, TxOut, Txid}; + use bitcoin::{Address, Amount, ScriptBuf, TxOut, Txid}; use crate::helpers::builders::{compress_blob, decompress_blob}; use crate::helpers::parsers::parse_transaction; @@ -647,9 +648,9 @@ mod tests { assert_eq!(tx.vsize(), 154); assert_eq!(tx.input.len(), 1); assert_eq!(tx.output.len(), 2); - assert_eq!(tx.output[0].value, 5_000); + assert_eq!(tx.output[0].value, Amount::from_sat(5_000)); assert_eq!(tx.output[0].script_pubkey, recipient.script_pubkey()); - assert_eq!(tx.output[1].value, 3_768); + assert_eq!(tx.output[1].value, Amount::from_sat(3_768)); assert_eq!(tx.output[1].script_pubkey, address.script_pubkey()); let mut tx = super::build_commit_transaction( @@ -674,7 +675,7 @@ mod tests { assert_eq!(tx.vsize(), 111); assert_eq!(tx.input.len(), 1); assert_eq!(tx.output.len(), 1); - assert_eq!(tx.output[0].value, 5_000); + assert_eq!(tx.output[0].value, Amount::from_sat(5_000)); assert_eq!(tx.output[0].script_pubkey, recipient.script_pubkey()); let mut tx = super::build_commit_transaction( @@ -704,7 +705,7 @@ mod tests { assert_eq!(tx.vsize(), 111); assert_eq!(tx.input.len(), 1); assert_eq!(tx.output.len(), 1); - assert_eq!(tx.output[0].value, 5_000); + assert_eq!(tx.output[0].value, Amount::from_sat(5_000)); assert_eq!(tx.output[0].script_pubkey, recipient.script_pubkey()); let mut tx = super::build_commit_transaction( @@ -734,9 +735,9 @@ mod tests { assert_eq!(tx.vsize(), 212); assert_eq!(tx.input.len(), 2); assert_eq!(tx.output.len(), 2); - assert_eq!(tx.output[0].value, 1_050_000); + assert_eq!(tx.output[0].value, Amount::from_sat(1_050_000)); assert_eq!(tx.output[0].script_pubkey, recipient.script_pubkey()); - assert_eq!(tx.output[1].value, 48940); + assert_eq!(tx.output[1].value, Amount::from_sat(48940)); assert_eq!(tx.output[1].script_pubkey, address.script_pubkey()); let tx = super::build_commit_transaction( @@ -789,7 +790,7 @@ mod tests { let mut tx = super::build_reveal_transaction( TxOut { - value: utxo.amount, + value: Amount::from_sat(utxo.amount), script_pubkey: ScriptBuf::from_hex(utxo.script_pubkey.as_str()).unwrap(), }, utxo.tx_id, @@ -811,14 +812,14 @@ mod tests { assert_eq!(tx.input[0].previous_output.vout, utxo.vout); assert_eq!(tx.output.len(), 1); - assert_eq!(tx.output[0].value, 546); + assert_eq!(tx.output[0].value, Amount::from_sat(546)); assert_eq!(tx.output[0].script_pubkey, address.script_pubkey()); let utxo = utxos.get(2).unwrap(); let tx = super::build_reveal_transaction( TxOut { - value: utxo.amount, + value: Amount::from_sat(utxo.amount), script_pubkey: ScriptBuf::from_hex(utxo.script_pubkey.as_str()).unwrap(), }, utxo.tx_id, @@ -837,7 +838,7 @@ mod tests { let tx = super::build_reveal_transaction( TxOut { - value: utxo.amount, + value: Amount::from_sat(utxo.amount), script_pubkey: ScriptBuf::from_hex(utxo.script_pubkey.as_str()).unwrap(), }, utxo.tx_id, diff --git a/adapters/bitcoin/src/helpers/parsers.rs b/adapters/bitcoin/src/helpers/parsers.rs index 31ed84e5b..2eb7d2391 100644 --- a/adapters/bitcoin/src/helpers/parsers.rs +++ b/adapters/bitcoin/src/helpers/parsers.rs @@ -4,6 +4,11 @@ use bitcoin::blockdata::opcodes::all::{OP_ENDIF, OP_IF}; use bitcoin::blockdata::script::{Instruction, Instructions}; use bitcoin::consensus::Decodable; use bitcoin::hashes::{sha256d, Hash}; +use bitcoin::opcodes::all::{ + OP_PUSHNUM_1, OP_PUSHNUM_10, OP_PUSHNUM_11, OP_PUSHNUM_12, OP_PUSHNUM_13, OP_PUSHNUM_14, + OP_PUSHNUM_15, OP_PUSHNUM_16, OP_PUSHNUM_2, OP_PUSHNUM_3, OP_PUSHNUM_4, OP_PUSHNUM_5, + OP_PUSHNUM_6, OP_PUSHNUM_7, OP_PUSHNUM_8, OP_PUSHNUM_9, +}; use bitcoin::opcodes::OP_FALSE; use bitcoin::secp256k1::{ecdsa, Message, Secp256k1}; use bitcoin::{secp256k1, Script, Transaction}; @@ -24,7 +29,7 @@ impl ParsedInscription { let public_key = secp256k1::PublicKey::from_slice(&self.public_key); let signature = ecdsa::Signature::from_compact(&self.signature); let hash = sha256d::Hash::hash(&self.body).to_byte_array(); - let message = Message::from_slice(&hash).unwrap(); // cannot fail + let message = Message::from_digest_slice(&hash).unwrap(); // cannot fail let secp = Secp256k1::new(); @@ -99,13 +104,33 @@ fn parse_relevant_inscriptions( break; // we are done parsing } } - Instruction::Op(another_op) => { - // don't allow anything except data pushes inside envelope + // If the found nonce is less than or equal to 16, push_int of reveal_script_builder + // uses the dedicated opcode OP_PUSHNUM before OP_PUSHDATA rather than OP_PUSHBYTES. + // When occurred, it was causing our tests to fail in the last match arm and returning an error. + // This giga fix is added to not to fail inside the envelope at the end when nonce <= 16. + Instruction::Op(OP_PUSHNUM_1) + | Instruction::Op(OP_PUSHNUM_2) + | Instruction::Op(OP_PUSHNUM_3) + | Instruction::Op(OP_PUSHNUM_4) + | Instruction::Op(OP_PUSHNUM_5) + | Instruction::Op(OP_PUSHNUM_6) + | Instruction::Op(OP_PUSHNUM_7) + | Instruction::Op(OP_PUSHNUM_8) + | Instruction::Op(OP_PUSHNUM_9) + | Instruction::Op(OP_PUSHNUM_10) + | Instruction::Op(OP_PUSHNUM_11) + | Instruction::Op(OP_PUSHNUM_12) + | Instruction::Op(OP_PUSHNUM_13) + | Instruction::Op(OP_PUSHNUM_14) + | Instruction::Op(OP_PUSHNUM_15) + | Instruction::Op(OP_PUSHNUM_16) => { if inside_envelope { - return Err(ParserError::EnvelopeHasNonPushOp); - } + if inside_envelope_index != 7 { + return Err(ParserError::EnvelopeHasNonPushOp); + } - last_op = Some(another_op); + inside_envelope_index += 1; + } } Instruction::PushBytes(bytes) => { if inside_envelope { @@ -137,6 +162,14 @@ fn parse_relevant_inscriptions( last_op = Some(OP_FALSE); // rust bitcoin pushes [] instead of op_false } } + Instruction::Op(another_op) => { + // don't allow anything except data pushes inside envelope + if inside_envelope { + return Err(ParserError::EnvelopeHasNonPushOp); + } + + last_op = Some(another_op); + } } } diff --git a/adapters/bitcoin/src/service.rs b/adapters/bitcoin/src/service.rs index 6e23fb11f..9eb9ee624 100644 --- a/adapters/bitcoin/src/service.rs +++ b/adapters/bitcoin/src/service.rs @@ -492,7 +492,7 @@ mod tests { // use futures::{Stream, StreamExt}; use bitcoin::block::{Header, Version}; use bitcoin::hash_types::TxMerkleNode; - use bitcoin::secp256k1::KeyPair; + use bitcoin::secp256k1::Keypair; use bitcoin::string::FromHexStr; use bitcoin::{BlockHash, CompactTarget, Transaction}; use sov_rollup_interface::da::DaVerifier; @@ -618,7 +618,7 @@ mod tests { // The transaction was sent with this service and the tx data is stored in false_signature_txs.txt let da_service = get_service().await; let secp = bitcoin::secp256k1::Secp256k1::new(); - let da_pubkey = KeyPair::from_secret_key(&secp, &da_service.sequencer_da_private_key) + let da_pubkey = Keypair::from_secret_key(&secp, &da_service.sequencer_da_private_key) .public_key() .serialize() .to_vec(); @@ -645,7 +645,7 @@ mod tests { .await; let incorrect_pub_key = - KeyPair::from_secret_key(&secp, &incorrect_service.sequencer_da_private_key) + Keypair::from_secret_key(&secp, &incorrect_service.sequencer_da_private_key) .public_key() .serialize() .to_vec(); @@ -697,7 +697,7 @@ mod tests { async fn check_signature() { let da_service = get_service().await; let secp = bitcoin::secp256k1::Secp256k1::new(); - let da_pubkey = KeyPair::from_secret_key(&secp, &da_service.sequencer_da_private_key) + let da_pubkey = Keypair::from_secret_key(&secp, &da_service.sequencer_da_private_key) .public_key() .serialize() .to_vec(); diff --git a/adapters/bitcoin/src/spec/proof.rs b/adapters/bitcoin/src/spec/proof.rs index c16819446..49f49474c 100644 --- a/adapters/bitcoin/src/spec/proof.rs +++ b/adapters/bitcoin/src/spec/proof.rs @@ -30,7 +30,7 @@ impl Default for InclusionMultiProof { txids: vec![], wtxids: vec![], coinbase_tx: Transaction { - version: 0, + version: bitcoin::transaction::Version(0), lock_time: LockTime::Seconds(Time::MIN), input: vec![], output: vec![],