From 138005560ff0fbf6f66886e95a3e1607f66ee1e2 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 14:06:07 +0300 Subject: [PATCH 01/17] :construction: :test_tube: add test scripts that will be used for verification --- splitter/Cargo.toml | 49 +++++++++++----------- splitter/src/debug.rs | 2 +- splitter/src/lib.rs | 2 + splitter/src/split/mod.rs | 4 ++ splitter/src/split/script.rs | 62 ++++++++++++++++++++++++++++ splitter/src/test_scripts/int_add.rs | 56 +++++++++++++++++++++++++ splitter/src/test_scripts/int_mul.rs | 4 ++ splitter/src/test_scripts/mod.rs | 9 ++++ 8 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 splitter/src/split/mod.rs create mode 100644 splitter/src/split/script.rs create mode 100644 splitter/src/test_scripts/int_add.rs create mode 100644 splitter/src/test_scripts/int_mul.rs create mode 100644 splitter/src/test_scripts/mod.rs diff --git a/splitter/Cargo.toml b/splitter/Cargo.toml index 52e2e15..c532339 100644 --- a/splitter/Cargo.toml +++ b/splitter/Cargo.toml @@ -1,36 +1,37 @@ [package] -name = "splitter" +name = "bitvm2-splitter" version = "0.1.0" edition = "2021" [dependencies] - # Bitcoin Libraries bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "bitvm", features = ["rand-std"]} bitcoin-script = { git = "https://github.com/BitVM/rust-bitcoin-script" } bitcoin-scriptexec = { git = "https://github.com/BitVM/rust-bitcoin-scriptexec/"} bitcoin-script-stack = { git = "https://github.com/FairgateLabs/rust-bitcoin-script-stack"} +# Some test script to test the splitter +bitcoin-window-mul = { git = "https://github.com/distributed-lab/bitcoin-window-mul.git" } + +# General-purpose libraries +strum = "0.26" +strum_macros = "0.26" +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.116" +tokio = { version = "1.37.0", features = ["full"] } -# Other Libraries -strum = "0.26" -strum_macros = "0.26" -hex = "0.4.3" -serde = { version = "1.0.197", features = ["derive"] } +# Crypto libraries +hex = "0.4.3" num-bigint = "0.4.4" num-traits = "0.2.18" -tokio = { version = "1.37.0", features = ["full"] } -serde_json = "1.0.116" -lazy_static = "1.4.0" -prettytable-rs = "0.10.0" -paste = "1.0" -seq-macro = "0.3.5" -[dev-dependencies] +# Random libraries rand_chacha = "0.3.1" -rand = "0.8.5" -num-bigint = { version = "0.4.4", features = ["rand"] } -ark-std = "0.4.0" -konst = "0.3.9" +rand = "0.8.0" + +[dev-dependencies] +num-bigint = { version = "0.4.4", features = ["rand"] } +ark-std = "0.4.0" +konst = "0.3.9" [profile.dev] opt-level = 3 @@ -39,25 +40,25 @@ opt-level = 3 lto = true [patch.crates-io.base58check] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" [patch.crates-io.bitcoin] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" [patch.crates-io.bitcoin_hashes] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" [patch.crates-io.bitcoin-internals] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" [patch.crates-io.bitcoin-io] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" [patch.crates-io.bitcoin-units] -git = "https://github.com/rust-bitcoin/rust-bitcoin" +git = "https://github.com/rust-bitcoin/rust-bitcoin" branch = "bitvm" \ No newline at end of file diff --git a/splitter/src/debug.rs b/splitter/src/debug.rs index eac8890..3584b1e 100644 --- a/splitter/src/debug.rs +++ b/splitter/src/debug.rs @@ -202,4 +202,4 @@ mod test { let exec_result = execute_script_no_stack_limit(script); assert!(exec_result.success); } -} \ No newline at end of file +} diff --git a/splitter/src/lib.rs b/splitter/src/lib.rs index 6dc88ea..ae7e007 100644 --- a/splitter/src/lib.rs +++ b/splitter/src/lib.rs @@ -9,6 +9,8 @@ pub mod treepp { } pub(crate) mod debug; +pub mod split; +pub(crate) mod test_scripts; #[cfg(test)] mod tests { diff --git a/splitter/src/split/mod.rs b/splitter/src/split/mod.rs new file mode 100644 index 0000000..065720b --- /dev/null +++ b/splitter/src/split/mod.rs @@ -0,0 +1,4 @@ +//! Module that contains the implementation of the splitter +//! together with all auxiliary functions and data structures. + +pub mod script; diff --git a/splitter/src/split/script.rs b/splitter/src/split/script.rs new file mode 100644 index 0000000..79a6261 --- /dev/null +++ b/splitter/src/split/script.rs @@ -0,0 +1,62 @@ +//! Module containing the structure for scripts that we are going to use + +use bitcoin_script_stack::debugger::pushable::Pushable; + +use crate::treepp::*; + +/// Structure that represents a pair of input and output scripts. Typically, the prover +/// wants to prove `script(input) == output` +pub struct IOPair< + I, O: Pushable, + const INPUT_SIZE: usize, + const OUTPUT_SIZE: usize, +> { + pub input: [I; INPUT_SIZE], + pub output: [O; OUTPUT_SIZE], +} + +/// Trait that any script that can be split should implement +pub trait SplitableScript { + /// Returns the main logic (f) of the script + fn script() -> Script; + + /// Generates a random valid input for the script + fn generate_valid_io_pair() -> IOPair; + + /// Verifies that the input is valid for the script + fn verify(input: [I; INPUT_SIZE], output: [O; OUTPUT_SIZE]) -> bool { + let output_length = output.len(); + println!("Output length: {}", output_length); + + let script = script! { + for i in 0..input.len() { + { input[i] } + } + + { Self::script() } + for i in 0..input.len() { + { output[i] } + } + + // Now, we need to verify that the output is correct. + // Since the output is not necessarily a single element, we check + // elements one by one + for i in (0..output_length).rev() { + // { ... ... } <- we need to push element to the top of the stack + { i+1 } OP_ROLL + OP_EQUALVERIFY + } + + // If everything was verified correctly, we return true to mark the script as successful + OP_TRUE + }; + + execute_script(script).success + } + + /// Verifies that the input is valid for the script with random input and output + fn verify_random() -> bool { + let IOPair { input, output } = Self::generate_valid_io_pair(); + Self::verify(input, output) + } +} diff --git a/splitter/src/test_scripts/int_add.rs b/splitter/src/test_scripts/int_add.rs new file mode 100644 index 0000000..4046453 --- /dev/null +++ b/splitter/src/test_scripts/int_add.rs @@ -0,0 +1,56 @@ +//! This module contains the test script +//! for performing the addition of two large integers (exceeding standard Bitcoin 31-bit integers) + +use crate::{ + split::script::{IOPair, SplitableScript}, + treepp::*, +}; +use bitcoin_window_mul::{ + bigint::{U254Windowed, U254}, + traits::{arithmeticable::Arithmeticable, integer::NonNativeInteger}, +}; + +use core::ops::{Rem, Shl}; +use num_bigint::{BigUint, RandomBits}; +use num_traits::One; +use rand::{Rng, SeedableRng}; +use rand_chacha::ChaCha20Rng; + +/// Script that performs the addition of two 254-bit numbers +pub struct U254AddScript; + +impl SplitableScript for U254AddScript { + fn script() -> Script { + U254::OP_ADD(1, 0) + } + + fn generate_valid_io_pair() -> IOPair { + let mut prng = ChaCha20Rng::seed_from_u64(0); + + let a: BigUint = prng.sample(RandomBits::new(254)); + let b: BigUint = prng.sample(RandomBits::new(254)); + let c: BigUint = (a.clone() + b.clone()).rem(BigUint::one().shl(254)); + + println!("a: {}", a); + println!("b: {}", b); + println!("c: {}", c); + + IOPair { + input: script! { + { U254::OP_PUSH_U32LESLICE(&a.to_u32_digits()) } + { U254::OP_PUSH_U32LESLICE(&b.to_u32_digits()) } + }, + output: U254::OP_PUSH_U32LESLICE(&c.to_u32_digits()), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_verify() { + assert!(U254AddScript::verify_random()); + } +} \ No newline at end of file diff --git a/splitter/src/test_scripts/int_mul.rs b/splitter/src/test_scripts/int_mul.rs new file mode 100644 index 0000000..209b819 --- /dev/null +++ b/splitter/src/test_scripts/int_mul.rs @@ -0,0 +1,4 @@ +//! This module contains the test script +//! for performing the multiplication of two large integers (exceeding standard Bitcoin 31-bit integers) + +use crate::treepp::*; diff --git a/splitter/src/test_scripts/mod.rs b/splitter/src/test_scripts/mod.rs new file mode 100644 index 0000000..26548cf --- /dev/null +++ b/splitter/src/test_scripts/mod.rs @@ -0,0 +1,9 @@ +//! This module contains some test scripts to test +//! the functionality of the splitter. +//! +//! Namely, we include: +//! - A script that performs an addition of two 254-bit numbers. +//! - A script that performs a multiplication of two 254-bit numbers using w-windowed approach. + +pub(crate) mod int_add; +pub(crate) mod int_mul; From f1cfd1c15acdb15b9a91901c5407050ae860f8d0 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 14:19:58 +0300 Subject: [PATCH 02/17] :adhesive_bandage: resolve conflicts in `Cargo.toml` --- splitter/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/splitter/Cargo.toml b/splitter/Cargo.toml index 0737c9b..383809d 100644 --- a/splitter/Cargo.toml +++ b/splitter/Cargo.toml @@ -21,12 +21,11 @@ tokio = { version = "1.37.0", features = ["full"] } # Crypto libraries hex = "0.4.3" -num-bigint = "0.4.4" +num-bigint = { version = "0.4.4", features = ["rand"] } num-traits = "0.2.18" # Random libraries rand_chacha = "0.3.1" rand = "0.8.5" -num-bigint = { version = "0.4.4", features = ["rand"] } ark-std = "0.4.0" konst = "0.3.9" From 7e5a68c33d42e518f9674a6d60d5232cb4307cd1 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 15:07:44 +0300 Subject: [PATCH 03/17] :construction: almost there --- splitter/src/split/script.rs | 8 ++----- splitter/src/test_scripts/int_add.rs | 32 +++++++++++++++++----------- splitter/src/test_scripts/int_mul.rs | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/splitter/src/split/script.rs b/splitter/src/split/script.rs index 79a6261..79af118 100644 --- a/splitter/src/split/script.rs +++ b/splitter/src/split/script.rs @@ -1,16 +1,12 @@ //! Module containing the structure for scripts that we are going to use -use bitcoin_script_stack::debugger::pushable::Pushable; +use pushable::Pushable; use crate::treepp::*; /// Structure that represents a pair of input and output scripts. Typically, the prover /// wants to prove `script(input) == output` -pub struct IOPair< - I, O: Pushable, - const INPUT_SIZE: usize, - const OUTPUT_SIZE: usize, -> { +pub struct IOPair { pub input: [I; INPUT_SIZE], pub output: [O; OUTPUT_SIZE], } diff --git a/splitter/src/test_scripts/int_add.rs b/splitter/src/test_scripts/int_add.rs index 4046453..3440487 100644 --- a/splitter/src/test_scripts/int_add.rs +++ b/splitter/src/test_scripts/int_add.rs @@ -6,8 +6,8 @@ use crate::{ treepp::*, }; use bitcoin_window_mul::{ - bigint::{U254Windowed, U254}, - traits::{arithmeticable::Arithmeticable, integer::NonNativeInteger}, + bigint::U254, + traits::{arithmeticable::Arithmeticable, integer::NonNativeLimbInteger}, }; use core::ops::{Rem, Shl}; @@ -19,28 +19,34 @@ use rand_chacha::ChaCha20Rng; /// Script that performs the addition of two 254-bit numbers pub struct U254AddScript; -impl SplitableScript for U254AddScript { +type IOType = u32; +const INPUT_SIZE: usize = 2 * U254::N_LIMBS; +const OUTPUT_SIZE: usize = U254::N_LIMBS; + +impl SplitableScript for U254AddScript { fn script() -> Script { U254::OP_ADD(1, 0) } - fn generate_valid_io_pair() -> IOPair { + fn generate_valid_io_pair() -> IOPair { let mut prng = ChaCha20Rng::seed_from_u64(0); let a: BigUint = prng.sample(RandomBits::new(254)); let b: BigUint = prng.sample(RandomBits::new(254)); let c: BigUint = (a.clone() + b.clone()).rem(BigUint::one().shl(254)); - println!("a: {}", a); - println!("b: {}", b); - println!("c: {}", c); + // Input is simply a and b limbs concatenated + let mut input = a.to_u32_digits().clone(); + input.append(&mut b.to_u32_digits()); + + // Output is limbs of c + let output = c.to_u32_digits(); IOPair { - input: script! { - { U254::OP_PUSH_U32LESLICE(&a.to_u32_digits()) } - { U254::OP_PUSH_U32LESLICE(&b.to_u32_digits()) } - }, - output: U254::OP_PUSH_U32LESLICE(&c.to_u32_digits()), + input: input.try_into().expect("Input is not of the correct size"), + output: output + .try_into() + .expect("Output is not of the correct size"), } } } @@ -53,4 +59,4 @@ mod tests { fn test_verify() { assert!(U254AddScript::verify_random()); } -} \ No newline at end of file +} diff --git a/splitter/src/test_scripts/int_mul.rs b/splitter/src/test_scripts/int_mul.rs index 209b819..101c7e4 100644 --- a/splitter/src/test_scripts/int_mul.rs +++ b/splitter/src/test_scripts/int_mul.rs @@ -1,4 +1,5 @@ //! This module contains the test script //! for performing the multiplication of two large integers (exceeding standard Bitcoin 31-bit integers) +#[allow(unused_imports)] use crate::treepp::*; From 00c0a28cb715285bcc0e099742f0958b31e98ba9 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 15:21:31 +0300 Subject: [PATCH 04/17] :green_heart: make it somewhat working --- splitter/src/split/script.rs | 30 +++++++++--------------- splitter/src/test_scripts/int_add.rs | 34 +++++++++++++--------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/splitter/src/split/script.rs b/splitter/src/split/script.rs index 79af118..c60bb56 100644 --- a/splitter/src/split/script.rs +++ b/splitter/src/split/script.rs @@ -1,43 +1,35 @@ //! Module containing the structure for scripts that we are going to use -use pushable::Pushable; - use crate::treepp::*; /// Structure that represents a pair of input and output scripts. Typically, the prover /// wants to prove `script(input) == output` -pub struct IOPair { - pub input: [I; INPUT_SIZE], - pub output: [O; OUTPUT_SIZE], +pub struct IOPair { + /// Input script containing the elements which will be fed to the main script + pub input: Script, + /// Output script containing the elements which will be compared to the output of the main script + pub output: Script, } /// Trait that any script that can be split should implement -pub trait SplitableScript { +pub trait SplitableScript { /// Returns the main logic (f) of the script fn script() -> Script; /// Generates a random valid input for the script - fn generate_valid_io_pair() -> IOPair; + fn generate_valid_io_pair() -> IOPair; /// Verifies that the input is valid for the script - fn verify(input: [I; INPUT_SIZE], output: [O; OUTPUT_SIZE]) -> bool { - let output_length = output.len(); - println!("Output length: {}", output_length); - + fn verify(input: Script, output: Script) -> bool { let script = script! { - for i in 0..input.len() { - { input[i] } - } - + { input } { Self::script() } - for i in 0..input.len() { - { output[i] } - } + { output } // Now, we need to verify that the output is correct. // Since the output is not necessarily a single element, we check // elements one by one - for i in (0..output_length).rev() { + for i in (0..OUTPUT_SIZE).rev() { // { ... ... } <- we need to push element to the top of the stack { i+1 } OP_ROLL OP_EQUALVERIFY diff --git a/splitter/src/test_scripts/int_add.rs b/splitter/src/test_scripts/int_add.rs index 3440487..62903ba 100644 --- a/splitter/src/test_scripts/int_add.rs +++ b/splitter/src/test_scripts/int_add.rs @@ -7,7 +7,10 @@ use crate::{ }; use bitcoin_window_mul::{ bigint::U254, - traits::{arithmeticable::Arithmeticable, integer::NonNativeLimbInteger}, + traits::{ + arithmeticable::Arithmeticable, + integer::{NonNativeInteger, NonNativeLimbInteger}, + }, }; use core::ops::{Rem, Shl}; @@ -19,34 +22,29 @@ use rand_chacha::ChaCha20Rng; /// Script that performs the addition of two 254-bit numbers pub struct U254AddScript; -type IOType = u32; +/// Input size is double the number of limbs of U254 since we are adding two numbers const INPUT_SIZE: usize = 2 * U254::N_LIMBS; +/// Output size is the number of limbs of U254 const OUTPUT_SIZE: usize = U254::N_LIMBS; -impl SplitableScript for U254AddScript { +impl SplitableScript<{ INPUT_SIZE }, { OUTPUT_SIZE }> for U254AddScript { fn script() -> Script { U254::OP_ADD(1, 0) } - fn generate_valid_io_pair() -> IOPair { + fn generate_valid_io_pair() -> IOPair<{ INPUT_SIZE }, { OUTPUT_SIZE }> { let mut prng = ChaCha20Rng::seed_from_u64(0); - let a: BigUint = prng.sample(RandomBits::new(254)); - let b: BigUint = prng.sample(RandomBits::new(254)); - let c: BigUint = (a.clone() + b.clone()).rem(BigUint::one().shl(254)); - - // Input is simply a and b limbs concatenated - let mut input = a.to_u32_digits().clone(); - input.append(&mut b.to_u32_digits()); - - // Output is limbs of c - let output = c.to_u32_digits(); + let num_1: BigUint = prng.sample(RandomBits::new(254)); + let num_2: BigUint = prng.sample(RandomBits::new(254)); + let sum: BigUint = (num_1.clone() + num_2.clone()).rem(BigUint::one().shl(254)); IOPair { - input: input.try_into().expect("Input is not of the correct size"), - output: output - .try_into() - .expect("Output is not of the correct size"), + input: script! { + { U254::OP_PUSH_U32LESLICE(&num_1.to_u32_digits()) } + { U254::OP_PUSH_U32LESLICE(&num_2.to_u32_digits()) } + }, + output: U254::OP_PUSH_U32LESLICE(&sum.to_u32_digits()), } } } From 629e45ff35f929900425d85c126712e510a1bd53 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 15:34:50 +0300 Subject: [PATCH 05/17] :sparkles: add multiplication script --- splitter/src/test_scripts/int_add.rs | 5 ++- splitter/src/test_scripts/int_mul.rs | 57 ++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/splitter/src/test_scripts/int_add.rs b/splitter/src/test_scripts/int_add.rs index 62903ba..b33ed41 100644 --- a/splitter/src/test_scripts/int_add.rs +++ b/splitter/src/test_scripts/int_add.rs @@ -1,5 +1,6 @@ //! This module contains the test script -//! for performing the addition of two large integers (exceeding standard Bitcoin 31-bit integers) +//! for performing the addition of two large integers +//! (exceeding standard Bitcoin 31-bit integers) use crate::{ split::script::{IOPair, SplitableScript}, @@ -22,6 +23,7 @@ use rand_chacha::ChaCha20Rng; /// Script that performs the addition of two 254-bit numbers pub struct U254AddScript; + /// Input size is double the number of limbs of U254 since we are adding two numbers const INPUT_SIZE: usize = 2 * U254::N_LIMBS; /// Output size is the number of limbs of U254 @@ -35,6 +37,7 @@ impl SplitableScript<{ INPUT_SIZE }, { OUTPUT_SIZE }> for U254AddScript { fn generate_valid_io_pair() -> IOPair<{ INPUT_SIZE }, { OUTPUT_SIZE }> { let mut prng = ChaCha20Rng::seed_from_u64(0); + // Generate two random 254-bit numbers and calculate their sum let num_1: BigUint = prng.sample(RandomBits::new(254)); let num_2: BigUint = prng.sample(RandomBits::new(254)); let sum: BigUint = (num_1.clone() + num_2.clone()).rem(BigUint::one().shl(254)); diff --git a/splitter/src/test_scripts/int_mul.rs b/splitter/src/test_scripts/int_mul.rs index 101c7e4..a462c19 100644 --- a/splitter/src/test_scripts/int_mul.rs +++ b/splitter/src/test_scripts/int_mul.rs @@ -1,5 +1,56 @@ //! This module contains the test script -//! for performing the multiplication of two large integers (exceeding standard Bitcoin 31-bit integers) +//! for performing the multiplication of two large integers +//! (exceeding standard Bitcoin 31-bit integers) -#[allow(unused_imports)] -use crate::treepp::*; +use crate::{ + split::script::{IOPair, SplitableScript}, + treepp::*, +}; +use bitcoin_window_mul::{ + bigint::{U254Windowed, U508}, traits::integer::{NonNativeInteger, NonNativeLimbInteger}, +}; + +use num_bigint::{BigUint, RandomBits}; +use rand::{Rng, SeedableRng}; +use rand_chacha::ChaCha20Rng; + +/// Script that performs the addition of two 254-bit numbers +pub struct U254MulScript; + +/// Input size is double the number of limbs of U254 since we are multiplying two numbers +const INPUT_SIZE: usize = 2 * U254Windowed::N_LIMBS; +/// Output size is the number of limbs of U508 +const OUTPUT_SIZE: usize = U508::N_LIMBS; + +impl SplitableScript<{ INPUT_SIZE }, { OUTPUT_SIZE }> for U254MulScript { + fn script() -> Script { + U254Windowed::OP_WIDENINGMUL::() + } + + fn generate_valid_io_pair() -> IOPair<{ INPUT_SIZE }, { OUTPUT_SIZE }> { + let mut prng = ChaCha20Rng::seed_from_u64(0); + + // Generate two random 254-bit numbers and calculate their sum + let num_1: BigUint = prng.sample(RandomBits::new(254)); + let num_2: BigUint = prng.sample(RandomBits::new(254)); + let product: BigUint = num_1.clone() * num_2.clone(); + + IOPair { + input: script! { + { U254Windowed::OP_PUSH_U32LESLICE(&num_1.to_u32_digits()) } + { U254Windowed::OP_PUSH_U32LESLICE(&num_2.to_u32_digits()) } + }, + output: U508::OP_PUSH_U32LESLICE(&product.to_u32_digits()), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_verify() { + assert!(U254MulScript::verify_random()); + } +} From 271cb301b2b625cad1e22f4cf71aa43fbe837d42 Mon Sep 17 00:00:00 2001 From: ZamDimon Date: Mon, 16 Sep 2024 16:15:04 +0300 Subject: [PATCH 06/17] :construction: wip, attempt to implement naive split --- splitter/src/split/core.rs | 54 ++++++++++++++++++++++++++++ splitter/src/split/mod.rs | 1 + splitter/src/split/script.rs | 7 ++++ splitter/src/test_scripts/int_mul.rs | 10 ++++++ 4 files changed, 72 insertions(+) create mode 100644 splitter/src/split/core.rs diff --git a/splitter/src/split/core.rs b/splitter/src/split/core.rs new file mode 100644 index 0000000..7dd0f6c --- /dev/null +++ b/splitter/src/split/core.rs @@ -0,0 +1,54 @@ +//! Module containing the logic of splitting the script into smaller parts + +use bitcoin::script::{Instruction, Instructions, PushBytes}; + +use crate::treepp::*; + +/// Maximum size of the script in bytes +pub(super) const MAX_SCRIPT_SIZE: usize = 30000; + +pub struct SplitResult { + /// Scripts that constitute the input script + pub scripts: Vec