From f05290c3c291c05ec3114763e9d25cdb7ebcd61a Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Mon, 27 Nov 2023 17:06:15 +0300 Subject: [PATCH 01/12] #5 - change wire taget to byte array --- src/wire.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/wire.rs b/src/wire.rs index 228a3da..e438b96 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -4,13 +4,12 @@ use bitcoin::hashes::sha256; use bitcoin::hashes::Hash; use bitcoin::opcodes::all::*; use bitcoin::ScriptBuf; -use bitcoin::Target; use rand::Rng; #[derive(Clone, Debug)] pub struct Wire { - pub preimages: Option<[Target; 2]>, - pub hashes: [Target; 2], + pub preimages: Option<[[u8; 32]; 2]>, + pub hashes: [[u8; 32]; 2], pub selector: Option, } @@ -18,13 +17,11 @@ impl Wire { pub fn new() -> Self { let mut rng = rand::thread_rng(); - let preimage1 = Target::from_le_bytes(rng.gen()); - let preimage2 = Target::from_le_bytes(rng.gen()); + let preimage1: [u8; 32] = rng.gen(); + let preimage2: [u8; 32] = rng.gen(); - let hash1 = - Target::from_le_bytes(sha256::Hash::hash(&preimage1.to_le_bytes()).to_byte_array()); - let hash2 = - Target::from_le_bytes(sha256::Hash::hash(&preimage2.to_le_bytes()).to_byte_array()); + let hash1 = sha256::Hash::hash(&preimage1).to_byte_array(); + let hash2 = sha256::Hash::hash(&preimage2).to_byte_array(); return Wire { preimages: Some([preimage1, preimage2]), @@ -38,10 +35,10 @@ impl WireTrait for Wire { fn generate_anti_contradiction_script(&self) -> ScriptBuf { Builder::new() .push_opcode(OP_SHA256) - .push_slice(&self.hashes[0].to_le_bytes()) + .push_slice(&self.hashes[0]) .push_opcode(OP_EQUALVERIFY) .push_opcode(OP_SHA256) - .push_slice(&self.hashes[1].to_le_bytes()) + .push_slice(&self.hashes[1]) .push_opcode(OP_EQUAL) .into_script() } @@ -65,4 +62,3 @@ mod tests { // TODO:Test if script returns 1 given input witness with [preimages[0], preimages[1] } } - From 4ccecc3849565345be3cab500655de26e63f513c Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Mon, 27 Nov 2023 18:15:10 +0300 Subject: [PATCH 02/12] #2 - Add tests for wire --- Cargo.toml | 3 +++ src/wire.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 72ecd19..a65eb28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] bitcoin = "0.31.0" rand = "0.8.5" + +[dev-dependencies] +bitcoin-scriptexec = { git = "https://github.com/ekrembal/rust-bitcoin-scriptexec" } \ No newline at end of file diff --git a/src/wire.rs b/src/wire.rs index e438b96..7d92bf8 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -47,6 +47,9 @@ impl WireTrait for Wire { #[cfg(test)] mod tests { use super::*; + use bitcoin::TapLeafHash; + use bitcoin::Transaction; + use bitcoin_scriptexec::*; #[test] fn test_wire() { @@ -58,7 +61,42 @@ mod tests { #[test] fn test_generate_anti_contradiction_script() { let wire = Wire::new(); - let _script = wire.generate_anti_contradiction_script(); - // TODO:Test if script returns 1 given input witness with [preimages[0], preimages[1] + let script = wire.generate_anti_contradiction_script(); + + let preimages_vec = if let Some(preimages) = wire.preimages { + vec![preimages[1].to_vec(), preimages[0].to_vec()] + } else { + panic!("wire preimages are None") + }; + + let mut exec = Exec::new( + ExecCtx::Tapscript, + Options::default(), + TxTemplate { + tx: Transaction { + version: bitcoin::transaction::Version::TWO, + lock_time: bitcoin::locktime::absolute::LockTime::ZERO, + input: vec![], + output: vec![], + }, + prevouts: vec![], + input_idx: 0, + taproot_annex_scriptleaf: Some((TapLeafHash::all_zeros(), None)), + }, + script, + preimages_vec, + ) + .expect("error creating exec"); + + loop { + if exec.exec_next().is_err() { + break; + } + } + + let res = exec.result().unwrap().clone(); + + println!("{:?}", res); + assert_eq!(res.error, None); } } From 0860b29baff8b461890673c4a489e7dedc27efd7 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Mon, 27 Nov 2023 18:30:23 +0300 Subject: [PATCH 03/12] #5 - add ci --- .clippy.toml | 2 + .github/workflows/check-and-lint.yaml | 55 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .clippy.toml create mode 100644 .github/workflows/check-and-lint.yaml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..961117a --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,2 @@ +type-complexity-threshold = 9999 +too-many-arguments-threshold = 20 \ No newline at end of file diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml new file mode 100644 index 0000000..4fe0334 --- /dev/null +++ b/.github/workflows/check-and-lint.yaml @@ -0,0 +1,55 @@ +on: + pull_request: + push: + branches: + - main + + +name: Check and Lint + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features + name: Clippy Output \ No newline at end of file From 461fed1008fa14f963bbc90f40f56f0e44552147 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Mon, 27 Nov 2023 18:31:20 +0300 Subject: [PATCH 04/12] test --- .github/workflows/check-and-lint.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml index 4fe0334..48e5bd8 100644 --- a/.github/workflows/check-and-lint.yaml +++ b/.github/workflows/check-and-lint.yaml @@ -3,6 +3,7 @@ on: push: branches: - main + - ekrem/ci name: Check and Lint From fe51567afe417e8338d1987974e4860040da8bfc Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:05:12 +0300 Subject: [PATCH 05/12] #5 - Add more action --- .github/workflows/check-and-lint.yaml | 1 + .github/workflows/test.yaml | 58 +++++++++++++++++++++++++++ src/traits/bit_commitment.rs | 3 +- src/traits/circuit.rs | 3 +- src/traits/gate.rs | 2 +- src/traits/mod.rs | 4 +- src/utils.rs | 4 +- src/wire.rs | 1 - 8 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml index 48e5bd8..7afd783 100644 --- a/.github/workflows/check-and-lint.yaml +++ b/.github/workflows/check-and-lint.yaml @@ -4,6 +4,7 @@ on: branches: - main - ekrem/ci + - dev name: Check and Lint diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..524fd96 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,58 @@ +on: + pull_request: + push: + branches: + - main + - ekrem/ci + - dev + +name: Test with Code Coverage + +jobs: + test: + name: Test + env: + PROJECT_NAME_UNDERSCORE: rust_ci_github_actions_workflow + CARGO_INCREMENTAL: 0 + RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort + RUSTDOCFLAGS: -Cpanic=abort + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + - name: Cache dependencies + uses: actions/cache@v2 + env: + cache-name: cache-dependencies + with: + path: | + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + ~/.cargo/bin + ~/.cargo/registry/index + ~/.cargo/registry/cache + target + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - name: Generate test result and coverage report + run: | + cargo install cargo2junit grcov; + cargo test $CARGO_OPTIONS -- -Z unstable-options --format json | cargo2junit > results.xml; + zip -0 ccov.zip `find . \( -name "$PROJECT_NAME_UNDERSCORE*.gc*" \) -print`; + grcov ccov.zip -s . -t lcov --llvm --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov.info; + - name: Upload test results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + check_name: Test Results + github_token: ${{ secrets.GITHUB_TOKEN }} + files: results.xml + - name: Upload to CodeCov + uses: codecov/codecov-action@v1 + with: + # required for private repositories: + # token: ${{ secrets.CODECOV_TOKEN }} + files: ./lcov.info + fail_ci_if_error: true \ No newline at end of file diff --git a/src/traits/bit_commitment.rs b/src/traits/bit_commitment.rs index a283ec3..e6e336d 100644 --- a/src/traits/bit_commitment.rs +++ b/src/traits/bit_commitment.rs @@ -1,2 +1 @@ -pub trait BitCommitmentTrait { -} \ No newline at end of file +pub trait BitCommitmentTrait {} diff --git a/src/traits/circuit.rs b/src/traits/circuit.rs index b0442ec..0302429 100644 --- a/src/traits/circuit.rs +++ b/src/traits/circuit.rs @@ -1,4 +1,3 @@ - // This trait defines the behavior of a circuit. pub trait CircuitTrait { fn evaluate(&self); @@ -6,4 +5,4 @@ pub trait CircuitTrait { fn from_bristol(file: &str) -> Self; fn generate_commitment_tree(&self); -} \ No newline at end of file +} diff --git a/src/traits/gate.rs b/src/traits/gate.rs index 90a5d48..d487b26 100644 --- a/src/traits/gate.rs +++ b/src/traits/gate.rs @@ -1,3 +1,3 @@ pub trait GateTrait { fn create_challenge_script(&self) -> String; -} \ No newline at end of file +} diff --git a/src/traits/mod.rs b/src/traits/mod.rs index 1e74085..311a838 100644 --- a/src/traits/mod.rs +++ b/src/traits/mod.rs @@ -1,4 +1,4 @@ pub mod bit_commitment; -pub mod gate; pub mod circuit; -pub mod wire; \ No newline at end of file +pub mod gate; +pub mod wire; diff --git a/src/utils.rs b/src/utils.rs index 6e47346..43efcbc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,7 +3,9 @@ use std::io::{self, BufRead}; use std::path::Path; pub fn read_lines

(filename: P) -> io::Result>> -where P: AsRef, { +where + P: AsRef, +{ let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) } diff --git a/src/wire.rs b/src/wire.rs index 228a3da..8114e69 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -65,4 +65,3 @@ mod tests { // TODO:Test if script returns 1 given input witness with [preimages[0], preimages[1] } } - From 02202fefcf01c7f8b228dc18f1d322adfb23836d Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:16:29 +0300 Subject: [PATCH 06/12] #5 - Add test coverage --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 524fd96..7834bfd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: test: name: Test env: - PROJECT_NAME_UNDERSCORE: rust_ci_github_actions_workflow + PROJECT_NAME_UNDERSCORE: bitvm-rs CARGO_INCREMENTAL: 0 RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort RUSTDOCFLAGS: -Cpanic=abort From 66ae6e64ea745e7b27d03afd940f1179a5578134 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:25:09 +0300 Subject: [PATCH 07/12] #5 - change ci --- .githooks/pre-commit | 16 ++++++++ .github/workflows/check-and-lint.yaml | 57 -------------------------- .github/workflows/ci.yaml | 45 +++++++++++++++++++++ .github/workflows/test.yaml | 58 --------------------------- Makefile | 14 +++++++ 5 files changed, 75 insertions(+), 115 deletions(-) create mode 100644 .githooks/pre-commit delete mode 100644 .github/workflows/check-and-lint.yaml create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/test.yaml create mode 100644 Makefile diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..a1b7b0b --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,16 @@ +#!/bin/sh + +# Format the code +make fmt + +# Apply fixes +make fix + +# Run checks +make check + +# If checks fail, prevent the commit +if [ $? -ne 0 ]; then + echo "Checks failed. Commit aborted." + exit 1 +fi \ No newline at end of file diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml deleted file mode 100644 index 7afd783..0000000 --- a/.github/workflows/check-and-lint.yaml +++ /dev/null @@ -1,57 +0,0 @@ -on: - pull_request: - push: - branches: - - main - - ekrem/ci - - dev - - -name: Check and Lint - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - components: clippy - override: true - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features - name: Clippy Output \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..64bfc3a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,45 @@ +name: Rust CI + +on: + push: + branches: "main" + pull_request: + branches: "main" + +env: + CARGO_TERM_COLOR: always + +jobs: + fmt-and-clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2.7.0 + - name: Version info + run: | + rustc --version + cargo clippy --version + - name: Fmt check + run: | + if ! cargo fmt -- --check ; then + echo "Formatting errors detected, apply make fmt." + exit 1 + fi + - name: Clippy check + run: | + if ! cargo clippy -- -D warnings ; then + echo "Clippy warnings detected, apply proper fixes." + exit 1 + fi + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2.7.0 + - name: Run Tests + run: | + if ! cargo test ; then + echo "Tests failed." + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 7834bfd..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,58 +0,0 @@ -on: - pull_request: - push: - branches: - - main - - ekrem/ci - - dev - -name: Test with Code Coverage - -jobs: - test: - name: Test - env: - PROJECT_NAME_UNDERSCORE: bitvm-rs - CARGO_INCREMENTAL: 0 - RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort - RUSTDOCFLAGS: -Cpanic=abort - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - name: Cache dependencies - uses: actions/cache@v2 - env: - cache-name: cache-dependencies - with: - path: | - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/.cargo/bin - ~/.cargo/registry/index - ~/.cargo/registry/cache - target - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} - - name: Generate test result and coverage report - run: | - cargo install cargo2junit grcov; - cargo test $CARGO_OPTIONS -- -Z unstable-options --format json | cargo2junit > results.xml; - zip -0 ccov.zip `find . \( -name "$PROJECT_NAME_UNDERSCORE*.gc*" \) -print`; - grcov ccov.zip -s . -t lcov --llvm --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov.info; - - name: Upload test results - uses: EnricoMi/publish-unit-test-result-action@v1 - with: - check_name: Test Results - github_token: ${{ secrets.GITHUB_TOKEN }} - files: results.xml - - name: Upload to CodeCov - uses: codecov/codecov-action@v1 - with: - # required for private repositories: - # token: ${{ secrets.CODECOV_TOKEN }} - files: ./lcov.info - fail_ci_if_error: true \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0498d3a --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +.PHONY: set-hook fmt fix check + +set-hook: + git config core.hooksPath .githooks + +fmt: + cargo fmt + +fix: + cargo clippy --fix --allow-dirty --allow-staged + +check: + cargo fmt -- --check + cargo clippy -- -D warnings \ No newline at end of file From af42eee6a58589c70c2c398c09f48e36280cf4d7 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:31:50 +0300 Subject: [PATCH 08/12] #5 - minor changes --- .githooks/pre-commit | 0 Makefile | 1 + src/circuit.rs | 6 +++--- src/gates.rs | 18 +++++++++--------- src/main.rs | 1 + src/wire.rs | 8 ++++---- 6 files changed, 18 insertions(+), 16 deletions(-) mode change 100644 => 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile index 0498d3a..d949082 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: set-hook fmt fix check set-hook: + chmod u+x .githooks/* git config core.hooksPath .githooks fmt: diff --git a/src/circuit.rs b/src/circuit.rs index ae29384..b315113 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -16,12 +16,12 @@ pub struct Circuit { impl Circuit { pub fn new() -> Self { - return Circuit { + Circuit { input_sizes: vec![32, 32], output_sizes: vec![32], gates: vec![Box::new(NotGate::new(vec![], vec![]))], wires: vec![], - }; + } } } @@ -54,7 +54,7 @@ impl CircuitTrait for Circuit { let x: usize = words.next().unwrap().parse().unwrap(); output_sizes.push(x); } - } else if line_str != "" { + } else if !line_str.is_empty() { let mut words = line_str.split_whitespace(); let noi = words.next().unwrap().parse().unwrap(); // number of inputs let noo = words.next().unwrap().parse().unwrap(); // number of outputs diff --git a/src/gates.rs b/src/gates.rs index 6f9a7d9..b7a4fa0 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -9,16 +9,16 @@ pub struct NotGate { impl NotGate { pub fn new(input_wires: Vec, output_wires: Vec) -> Self { - return NotGate { + NotGate { input_wires, output_wires, - }; + } } } impl GateTrait for NotGate { fn create_challenge_script(&self) -> String { - return "NotGate".to_string(); + "NotGate".to_string() } } @@ -29,16 +29,16 @@ pub struct AndGate { impl AndGate { pub fn new(input_wires: Vec, output_wires: Vec) -> Self { - return AndGate { + AndGate { input_wires, output_wires, - }; + } } } impl GateTrait for AndGate { fn create_challenge_script(&self) -> String { - return "NotGate".to_string(); + "NotGate".to_string() } } @@ -49,15 +49,15 @@ pub struct XorGate { impl XorGate { pub fn new(input_wires: Vec, output_wires: Vec) -> Self { - return XorGate { + XorGate { input_wires, output_wires, - }; + } } } impl GateTrait for XorGate { fn create_challenge_script(&self) -> String { - return "NotGate".to_string(); + "NotGate".to_string() } } diff --git a/src/main.rs b/src/main.rs index f803547..c042d8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,5 +3,6 @@ use bitvmrs::{circuit::Circuit, traits::circuit::CircuitTrait}; fn main() { println!("Hello, world!"); let circuit = Circuit::from_bristol("bristol/add.txt"); + println!("{}", circuit.input_sizes[0]); } diff --git a/src/wire.rs b/src/wire.rs index 8114e69..493892b 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -26,11 +26,11 @@ impl Wire { let hash2 = Target::from_le_bytes(sha256::Hash::hash(&preimage2.to_le_bytes()).to_byte_array()); - return Wire { + Wire { preimages: Some([preimage1, preimage2]), hashes: [hash1, hash2], selector: None, - }; + } } } @@ -38,10 +38,10 @@ impl WireTrait for Wire { fn generate_anti_contradiction_script(&self) -> ScriptBuf { Builder::new() .push_opcode(OP_SHA256) - .push_slice(&self.hashes[0].to_le_bytes()) + .push_slice(self.hashes[0].to_le_bytes()) .push_opcode(OP_EQUALVERIFY) .push_opcode(OP_SHA256) - .push_slice(&self.hashes[1].to_le_bytes()) + .push_slice(self.hashes[1].to_le_bytes()) .push_opcode(OP_EQUAL) .into_script() } From 19060c7970cc084be29346bd2af96653ff9edb28 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:32:00 +0300 Subject: [PATCH 09/12] #5 - minor changess --- src/circuit.rs | 6 ++++++ src/wire.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/circuit.rs b/src/circuit.rs index b315113..795e73d 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -14,6 +14,12 @@ pub struct Circuit { pub wires: Vec, } +impl Default for Circuit { + fn default() -> Self { + Self::new() + } +} + impl Circuit { pub fn new() -> Self { Circuit { diff --git a/src/wire.rs b/src/wire.rs index 493892b..714b9a8 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -14,6 +14,12 @@ pub struct Wire { pub selector: Option, } +impl Default for Wire { + fn default() -> Self { + Self::new() + } +} + impl Wire { pub fn new() -> Self { let mut rng = rand::thread_rng(); From f01cd52bdf540a91bea8ac51b985bef8c0320e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Karaku=C5=9F?= Date: Tue, 28 Nov 2023 12:36:04 +0300 Subject: [PATCH 10/12] wires are shared among gates and evaluate function works --- bristol/test.txt | 10 +++--- src/circuit.rs | 76 +++++++++++++++++++++++++++++++++++-------- src/gates.rs | 75 +++++++++++++++++++++++++++++++++++++----- src/main.rs | 13 ++++++-- src/traits/circuit.rs | 2 +- src/traits/gate.rs | 7 ++++ src/utils.rs | 19 +++++++++++ src/wire.rs | 18 +++++++--- 8 files changed, 186 insertions(+), 34 deletions(-) diff --git a/bristol/test.txt b/bristol/test.txt index 339f4e8..b9402af 100644 --- a/bristol/test.txt +++ b/bristol/test.txt @@ -1,8 +1,8 @@ -278356 78623 -2 32 32 -1 32 +2 5 +2 1 2 +1 1 -2 1 10 15 16 NOT -2 1 15 17 18 NOT +2 1 0 1 3 NOT +2 1 2 3 4 NOT diff --git a/src/circuit.rs b/src/circuit.rs index ae29384..60b07e2 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -1,4 +1,7 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; +use std::iter::zip; +use std::rc::Rc; +use std::cell::RefCell; use crate::utils::read_lines; use crate::{ @@ -11,7 +14,7 @@ pub struct Circuit { pub input_sizes: Vec, pub output_sizes: Vec, pub gates: Vec>, - pub wires: Vec, + pub wires: Vec>>, } impl Circuit { @@ -26,7 +29,36 @@ impl Circuit { } impl CircuitTrait for Circuit { - fn evaluate(&self) {} + fn evaluate(&mut self, inputs: Vec>) -> Vec> { + assert_eq!(inputs.len(), self.input_sizes.len()); + let mut combined_inputs = Vec::new(); + for (a, b) in zip(inputs, self.input_sizes.clone()) { + assert_eq!(a.len(), b); + combined_inputs.extend(a); + } + for (i, value) in combined_inputs.iter().enumerate() { + self.wires[i].try_borrow_mut().unwrap().selector = Some(value.clone()); + } + //self.gates[0].set_input_wires(); + //self.wires[0].try_borrow_mut().unwrap().selector = Some(true); + //self.wires[1].try_borrow_mut().unwrap().selector = Some(true); + for gate in self.gates.as_mut_slice() { + gate.evaluate(); + } + let mut output = Vec::new(); + let total_output_size = self.output_sizes.iter().sum::(); + let mut output_index = self.wires.len() - total_output_size; + for os in self.output_sizes.clone() { + let mut output_vec = Vec::new(); + for i in output_index..(output_index + os) { + let value = self.wires[i].try_borrow_mut().unwrap().selector.unwrap(); + output_vec.push(value); + } + output_index += os; + output.push(output_vec); + } + return output; + } fn from_bristol(file: &str) -> Self { let mut nog: usize = 0; // number of gates @@ -34,7 +66,7 @@ impl CircuitTrait for Circuit { let mut input_sizes = Vec::::new(); let mut output_sizes = Vec::::new(); let mut gates = Vec::>::new(); - let mut wire_indices = HashMap::new(); + let mut wire_indices = BTreeMap::new(); for (i, line) in read_lines(file).unwrap().enumerate() { if let Ok(line_str) = line { @@ -42,6 +74,10 @@ impl CircuitTrait for Circuit { let mut words = line_str.split_whitespace(); nog = words.next().unwrap().parse().unwrap(); now = words.next().unwrap().parse().unwrap(); + for i in 0..now { + let wire = Wire::new(i); + wire_indices.insert(i, Rc::new(RefCell::new(wire))); + } } else if i == 1 { let mut words = line_str.split_whitespace(); for _ in 0..words.next().unwrap().parse().unwrap() { @@ -60,18 +96,17 @@ impl CircuitTrait for Circuit { let noo = words.next().unwrap().parse().unwrap(); // number of outputs let input_wires = (0..noi) .map(|_| { - wire_indices - .entry(words.next().unwrap().parse::().unwrap()) - .or_insert(Wire::new()) - .to_owned() + let k = words.next().unwrap().parse::().unwrap(); + let x = wire_indices.get(&k).unwrap().clone(); + x }) .collect(); let output_wires = (0..noo) .map(|_| { - wire_indices - .entry(words.next().unwrap().parse::().unwrap()) - .or_insert(Wire::new()) - .to_owned() + let k = words.next().unwrap().parse::().unwrap(); + let x = wire_indices + .get(&k).unwrap().clone(); + x }) .collect(); let gate_type = words.next().unwrap(); @@ -104,12 +139,13 @@ impl CircuitTrait for Circuit { assert_eq!(nog, gates.len()); assert_eq!(wire_indices.keys().min().unwrap().to_owned(), 0); assert_eq!(wire_indices.keys().max().unwrap().to_owned(), now - 1); + assert!(input_sizes.iter().sum::() + output_sizes.iter().sum::() <= now); return Circuit { input_sizes, output_sizes, gates, - wires: wire_indices.values().cloned().collect::>(), + wires: wire_indices.values().cloned().collect::>>>(), }; } @@ -119,6 +155,7 @@ impl CircuitTrait for Circuit { #[cfg(test)] mod tests { use super::*; + use crate::utils::{number_to_bool_array, bool_array_to_number}; #[test] fn test_circuit() { @@ -131,4 +168,17 @@ mod tests { let circuit = Circuit::from_bristol("bristol/add.txt"); assert!(circuit.output_sizes[0] == 64); } + + #[test] + fn test_add_circuit() { + let mut circuit = Circuit::from_bristol("bristol/add.txt"); + let a1 = 633; + let a2 = 15; + let b1 = number_to_bool_array(a1, 64); + let b2 = number_to_bool_array(a2, 64); + + let o = circuit.evaluate(vec![b1, b2]); + let output = bool_array_to_number(o.get(0).unwrap().to_vec()); + assert_eq!(output, a1 + a2); + } } diff --git a/src/gates.rs b/src/gates.rs index 6f9a7d9..fd9a3aa 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -1,14 +1,16 @@ use crate::{traits::gate::GateTrait, wire::Wire}; +use std::rc::Rc; +use std::cell::RefCell; // Every gate has a type parameter COM, which is a bit commitment scheme which can be hash based or schnorr based. // Every gate has an array of input wire pointers. pub struct NotGate { - pub input_wires: Vec, - pub output_wires: Vec, + pub input_wires: Vec>>, + pub output_wires: Vec>>, } impl NotGate { - pub fn new(input_wires: Vec, output_wires: Vec) -> Self { + pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { return NotGate { input_wires, output_wires, @@ -20,15 +22,34 @@ impl GateTrait for NotGate { fn create_challenge_script(&self) -> String { return "NotGate".to_string(); } + + fn evaluate(&mut self) { + let in1 = &mut self.input_wires[0].try_borrow_mut().unwrap(); + let out = &mut self.output_wires[0].try_borrow_mut().unwrap(); + let u = in1.selector.as_mut().unwrap(); + let w = !*u; + out.selector = Some(w); + } + + fn set_input_wires(&mut self) { + let in1 = &mut self.input_wires[0].try_borrow_mut().unwrap(); + let in2 = &mut self.input_wires[1].try_borrow_mut().unwrap(); + in1.selector = Some(true); + in2.selector = Some(true); + } + + fn print(&self) -> String { + return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + } } pub struct AndGate { - pub input_wires: Vec, - pub output_wires: Vec, + pub input_wires: Vec>>, + pub output_wires: Vec>>, } impl AndGate { - pub fn new(input_wires: Vec, output_wires: Vec) -> Self { + pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { return AndGate { input_wires, output_wires, @@ -40,15 +61,33 @@ impl GateTrait for AndGate { fn create_challenge_script(&self) -> String { return "NotGate".to_string(); } + + fn evaluate(&mut self) { + let in1 = &mut self.input_wires[0].try_borrow_mut().unwrap(); + let in2 = &mut self.input_wires[1].try_borrow_mut().unwrap(); + let out = &mut self.output_wires[0].try_borrow_mut().unwrap(); + let u = in1.selector.as_mut().unwrap(); + let v = in2.selector.as_mut().unwrap(); + let w = *u && *v; + out.selector = Some(w); + } + + fn set_input_wires(&mut self) { + + } + + fn print(&self) -> String { + return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + } } pub struct XorGate { - pub input_wires: Vec, - pub output_wires: Vec, + pub input_wires: Vec>>, + pub output_wires: Vec>>, } impl XorGate { - pub fn new(input_wires: Vec, output_wires: Vec) -> Self { + pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { return XorGate { input_wires, output_wires, @@ -60,4 +99,22 @@ impl GateTrait for XorGate { fn create_challenge_script(&self) -> String { return "NotGate".to_string(); } + + fn evaluate(&mut self) { + let in1 = &mut self.input_wires[0].try_borrow_mut().unwrap(); + let in2 = &mut self.input_wires[1].try_borrow_mut().unwrap(); + let out = &mut self.output_wires[0].try_borrow_mut().unwrap(); + let u = in1.selector.as_mut().unwrap(); + let v = in2.selector.as_mut().unwrap(); + let w = *u ^ *v; + out.selector = Some(w); + } + + fn set_input_wires(&mut self) { + + } + + fn print(&self) -> String { + return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + } } diff --git a/src/main.rs b/src/main.rs index f803547..12e5e07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,16 @@ use bitvmrs::{circuit::Circuit, traits::circuit::CircuitTrait}; +use bitvmrs::utils::{number_to_bool_array, bool_array_to_number}; fn main() { println!("Hello, world!"); - let circuit = Circuit::from_bristol("bristol/add.txt"); - println!("{}", circuit.input_sizes[0]); + let mut circuit = Circuit::from_bristol("bristol/add.txt"); + let a1 = 633; + let a2 = 15; + let b1 = number_to_bool_array(a1, 64); + let b2 = number_to_bool_array(a2, 64); + + let o = circuit.evaluate(vec![b1, b2]); + let output = bool_array_to_number(o.get(0).unwrap().to_vec()); + println!("output : {:?}", output); + assert_eq!(output, a1 + a2); } diff --git a/src/traits/circuit.rs b/src/traits/circuit.rs index b0442ec..4bdfe20 100644 --- a/src/traits/circuit.rs +++ b/src/traits/circuit.rs @@ -1,7 +1,7 @@ // This trait defines the behavior of a circuit. pub trait CircuitTrait { - fn evaluate(&self); + fn evaluate(&mut self, inputs: Vec>) -> Vec>; fn from_bristol(file: &str) -> Self; diff --git a/src/traits/gate.rs b/src/traits/gate.rs index 90a5d48..bc182ef 100644 --- a/src/traits/gate.rs +++ b/src/traits/gate.rs @@ -1,3 +1,10 @@ +//use crate::wire::Wire; +//use std::rc::Rc; +//use std::cell::RefCell; + pub trait GateTrait { fn create_challenge_script(&self) -> String; + fn evaluate(&mut self); + fn set_input_wires(&mut self); + fn print(&self) -> String; } \ No newline at end of file diff --git a/src/utils.rs b/src/utils.rs index 6e47346..ec6680e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,3 +7,22 @@ where P: AsRef, { let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) } + +pub fn number_to_bool_array(number: usize, length: usize) -> Vec { + let mut v = Vec::new(); + for i in 0..length { + v.push(0 != number & (1 << i)); + } + return v; +} + +pub fn bool_array_to_number(bool_array: Vec) -> usize { + let mut a = 0; + for b in bool_array.iter().rev() { + a *= 2; + if *b { + a += 1; + } + } + return a; +} diff --git a/src/wire.rs b/src/wire.rs index 228a3da..90054a2 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use crate::traits::wire::WireTrait; use bitcoin::blockdata::script::Builder; use bitcoin::hashes::sha256; @@ -7,15 +9,22 @@ use bitcoin::ScriptBuf; use bitcoin::Target; use rand::Rng; -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Wire { pub preimages: Option<[Target; 2]>, pub hashes: [Target; 2], pub selector: Option, + pub index: usize, +} + +impl Debug for Wire { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Wire[{}]: {:?}", self.index, self.selector) + } } impl Wire { - pub fn new() -> Self { + pub fn new(index: usize) -> Self { let mut rng = rand::thread_rng(); let preimage1 = Target::from_le_bytes(rng.gen()); @@ -30,6 +39,7 @@ impl Wire { preimages: Some([preimage1, preimage2]), hashes: [hash1, hash2], selector: None, + index, }; } } @@ -53,14 +63,14 @@ mod tests { #[test] fn test_wire() { - let wire = Wire::new(); + let wire = Wire::new(0); assert_eq!(wire.preimages.is_some(), true); assert_eq!(wire.selector.is_none(), true); } #[test] fn test_generate_anti_contradiction_script() { - let wire = Wire::new(); + let wire = Wire::new(0); let _script = wire.generate_anti_contradiction_script(); // TODO:Test if script returns 1 given input witness with [preimages[0], preimages[1] } From c38eda9ad4e72a734db2251d4c9a9ebe06512cad Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:53:40 +0300 Subject: [PATCH 11/12] #5 - Change wire index to option --- src/circuit.rs | 4 ++-- src/gates.rs | 12 ++++++------ src/utils.rs | 4 ++-- src/wire.rs | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index db2f91c..a4fda1d 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -43,7 +43,7 @@ impl CircuitTrait for Circuit { combined_inputs.extend(a); } for (i, value) in combined_inputs.iter().enumerate() { - self.wires[i].try_borrow_mut().unwrap().selector = Some(value.clone()); + self.wires[i].try_borrow_mut().unwrap().selector = Some(*value); } //self.gates[0].set_input_wires(); //self.wires[0].try_borrow_mut().unwrap().selector = Some(true); @@ -63,7 +63,7 @@ impl CircuitTrait for Circuit { output_index += os; output.push(output_vec); } - return output; + output } fn from_bristol(file: &str) -> Self { diff --git a/src/gates.rs b/src/gates.rs index 83b803f..1be3f77 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -11,7 +11,7 @@ pub struct NotGate { impl NotGate { pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { - return NotGate { + NotGate { input_wires, output_wires, } @@ -39,7 +39,7 @@ impl GateTrait for NotGate { } fn print(&self) -> String { - return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) } } @@ -50,7 +50,7 @@ pub struct AndGate { impl AndGate { pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { - return AndGate { + AndGate { input_wires, output_wires, } @@ -77,7 +77,7 @@ impl GateTrait for AndGate { } fn print(&self) -> String { - return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) } } @@ -88,7 +88,7 @@ pub struct XorGate { impl XorGate { pub fn new(input_wires: Vec>>, output_wires: Vec>>) -> Self { - return XorGate { + XorGate { input_wires, output_wires, } @@ -115,6 +115,6 @@ impl GateTrait for XorGate { } fn print(&self) -> String { - return format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]); + format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) } } diff --git a/src/utils.rs b/src/utils.rs index 4c6e138..51a8210 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -15,7 +15,7 @@ pub fn number_to_bool_array(number: usize, length: usize) -> Vec { for i in 0..length { v.push(0 != number & (1 << i)); } - return v; + v } pub fn bool_array_to_number(bool_array: Vec) -> usize { @@ -26,5 +26,5 @@ pub fn bool_array_to_number(bool_array: Vec) -> usize { a += 1; } } - return a; + a } diff --git a/src/wire.rs b/src/wire.rs index 9344ffc..a790d0d 100644 --- a/src/wire.rs +++ b/src/wire.rs @@ -13,18 +13,18 @@ pub struct Wire { pub preimages: Option<[[u8; 32]; 2]>, pub hashes: [[u8; 32]; 2], pub selector: Option, - pub index: usize, + pub index: Option, } impl Debug for Wire { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Wire[{}]: {:?}", self.index, self.selector) + write!(f, "Wire[{:?}]: {:?}", self.index, self.selector) } } impl Default for Wire { fn default() -> Self { - Self::new() + Self::new(0) } } @@ -42,8 +42,8 @@ impl Wire { preimages: Some([preimage1, preimage2]), hashes: [hash1, hash2], selector: None, - index, - }; + index: Some(index), + } } } @@ -51,10 +51,10 @@ impl WireTrait for Wire { fn generate_anti_contradiction_script(&self) -> ScriptBuf { Builder::new() .push_opcode(OP_SHA256) - .push_slice(&self.hashes[0]) + .push_slice(self.hashes[0]) .push_opcode(OP_EQUALVERIFY) .push_opcode(OP_SHA256) - .push_slice(&self.hashes[1]) + .push_slice(self.hashes[1]) .push_opcode(OP_EQUAL) .into_script() } @@ -70,13 +70,13 @@ mod tests { #[test] fn test_wire() { let wire = Wire::new(0); - assert_eq!(wire.preimages.is_some(), true); - assert_eq!(wire.selector.is_none(), true); + assert!(wire.preimages.is_some()); + assert!(wire.selector.is_none()); } #[test] fn test_generate_anti_contradiction_script() { - let wire = Wire::new(); + let wire = Wire::new(0); let script = wire.generate_anti_contradiction_script(); let preimages_vec = if let Some(preimages) = wire.preimages { From 21277995c5bc953df4952cadffcaecb6250f10b5 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Tue, 28 Nov 2023 12:54:07 +0300 Subject: [PATCH 12/12] #5 - Wire index optional --- src/circuit.rs | 12 +++++++----- src/gates.rs | 25 +++++++++++++++---------- src/main.rs | 2 +- src/traits/gate.rs | 1 - 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index a4fda1d..09ead31 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -1,7 +1,7 @@ +use std::cell::RefCell; use std::collections::BTreeMap; use std::iter::zip; use std::rc::Rc; -use std::cell::RefCell; use crate::utils::read_lines; use crate::{ @@ -110,8 +110,7 @@ impl CircuitTrait for Circuit { let output_wires = (0..noo) .map(|_| { let k = words.next().unwrap().parse::().unwrap(); - let x = wire_indices - .get(&k).unwrap().clone(); + let x = wire_indices.get(&k).unwrap().clone(); x }) .collect(); @@ -151,7 +150,10 @@ impl CircuitTrait for Circuit { input_sizes, output_sizes, gates, - wires: wire_indices.values().cloned().collect::>>>(), + wires: wire_indices + .values() + .cloned() + .collect::>>>(), }; } @@ -161,7 +163,7 @@ impl CircuitTrait for Circuit { #[cfg(test)] mod tests { use super::*; - use crate::utils::{number_to_bool_array, bool_array_to_number}; + use crate::utils::{bool_array_to_number, number_to_bool_array}; #[test] fn test_circuit() { diff --git a/src/gates.rs b/src/gates.rs index 1be3f77..22f5a3a 100644 --- a/src/gates.rs +++ b/src/gates.rs @@ -1,6 +1,6 @@ use crate::{traits::gate::GateTrait, wire::Wire}; -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; // Every gate has a type parameter COM, which is a bit commitment scheme which can be hash based or schnorr based. // Every gate has an array of input wire pointers. @@ -39,7 +39,10 @@ impl GateTrait for NotGate { } fn print(&self) -> String { - format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) + format!( + "Gate[]: {:?}, {:?}, {:?}", + self.input_wires[0], self.input_wires[1], self.output_wires[0] + ) } } @@ -72,12 +75,13 @@ impl GateTrait for AndGate { out.selector = Some(w); } - fn set_input_wires(&mut self) { - - } + fn set_input_wires(&mut self) {} fn print(&self) -> String { - format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) + format!( + "Gate[]: {:?}, {:?}, {:?}", + self.input_wires[0], self.input_wires[1], self.output_wires[0] + ) } } @@ -110,11 +114,12 @@ impl GateTrait for XorGate { out.selector = Some(w); } - fn set_input_wires(&mut self) { - - } + fn set_input_wires(&mut self) {} fn print(&self) -> String { - format!("Gate[]: {:?}, {:?}, {:?}", self.input_wires[0], self.input_wires[1], self.output_wires[0]) + format!( + "Gate[]: {:?}, {:?}, {:?}", + self.input_wires[0], self.input_wires[1], self.output_wires[0] + ) } } diff --git a/src/main.rs b/src/main.rs index 12e5e07..6a4f392 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ +use bitvmrs::utils::{bool_array_to_number, number_to_bool_array}; use bitvmrs::{circuit::Circuit, traits::circuit::CircuitTrait}; -use bitvmrs::utils::{number_to_bool_array, bool_array_to_number}; fn main() { println!("Hello, world!"); diff --git a/src/traits/gate.rs b/src/traits/gate.rs index 82087c5..d24c827 100644 --- a/src/traits/gate.rs +++ b/src/traits/gate.rs @@ -8,4 +8,3 @@ pub trait GateTrait { fn set_input_wires(&mut self); fn print(&self) -> String; } -