From 7ff9b607dde4faf79061584f5b817f822060c365 Mon Sep 17 00:00:00 2001 From: orkunkilic Date: Fri, 2 Feb 2024 13:15:23 +0300 Subject: [PATCH] fix file structure --- Cargo.toml | 6 +++--- Makefile | 16 +--------------- README.md | 2 +- src/actor.rs | 2 +- src/{circuit/mod.rs => circuit.rs} | 9 +++------ src/{circuit => }/gates.rs | 10 +++++++--- src/lib.rs | 2 ++ src/prover.rs | 10 ++++++---- src/traits/gate.rs | 2 +- src/{transactions/mod.rs => transactions.rs} | 2 +- src/verifier.rs | 13 +++++++------ src/{circuit => }/wire.rs | 0 12 files changed, 33 insertions(+), 41 deletions(-) rename src/{circuit/mod.rs => circuit.rs} (98%) rename src/{circuit => }/gates.rs (98%) rename src/{transactions/mod.rs => transactions.rs} (99%) rename src/{circuit => }/wire.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index f260146..6b23602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "toy-bitvm" +name = "bitvm" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitcoin = { version = "0.31.0", features = ["rand"] } -bitcoincore-rpc = { version = "0.18.0" } +bitcoin = {version = "0.31.0", features = ["rand"]} +bitcoincore-rpc = {version = "0.18.0" } hex = "0.4.3" rand = "0.8.5" tokio = { version = "1", features = ["full"] } diff --git a/Makefile b/Makefile index f29f02e..d949082 100644 --- a/Makefile +++ b/Makefile @@ -12,18 +12,4 @@ fix: check: cargo fmt -- --check - cargo clippy -- -D warnings - -check-fuzz: ## Checks that fuzz member compiles - $(MAKE) -C fuzz check - -lint: - cargo +nightly fmt --all --check - cargo check --all-targets --all-features - $(MAKE) check-fuzz - cargo clippy --all-targets --all-features - -lint-fix: - cargo +nightly fmt --all - cargo fix --allow-dirty - cargo clippy --fix --allow-dirty \ No newline at end of file + cargo clippy -- -D warnings \ No newline at end of file diff --git a/README.md b/README.md index c4076cc..7f76746 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BitVM.rs -Experimental toy BitVM implementation in Rust. +Experimental BitVM implementation in Rust. It is recommended to always use [cargo-crev](https://github.com/crev-dev/cargo-crev) to verify the trustworthiness of each of your dependencies, including this one. diff --git a/src/actor.rs b/src/actor.rs index 75603ef..14f48a7 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -9,7 +9,7 @@ use bitcoin::{ }; use rand::Rng; -use crate::circuit::wire::{HashValue, PreimageValue}; +use crate::wire::{HashValue, PreimageValue}; pub struct Actor { secp: Secp256k1, diff --git a/src/circuit/mod.rs b/src/circuit.rs similarity index 98% rename from src/circuit/mod.rs rename to src/circuit.rs index d53877f..b41fa08 100644 --- a/src/circuit/mod.rs +++ b/src/circuit.rs @@ -1,15 +1,12 @@ -pub mod gates; -pub mod wire; - use std::collections::BTreeMap; use std::iter::zip; use std::sync::{Arc, Mutex}; -use gates::create_gate; -use wire::{HashTuple, Wire}; +use crate::gates::create_gate; +use crate::wire::HashTuple; -use crate::{traits::gate::GateTrait, utils::read_lines}; +use crate::{traits::gate::GateTrait, utils::read_lines, wire::Wire}; pub struct Circuit { pub input_sizes: Vec, diff --git a/src/circuit/gates.rs b/src/gates.rs similarity index 98% rename from src/circuit/gates.rs rename to src/gates.rs index b7685f3..92abe0c 100644 --- a/src/circuit/gates.rs +++ b/src/gates.rs @@ -4,9 +4,12 @@ use bitcoin::opcodes::all::{ use bitcoin::script::Builder; use bitcoin::ScriptBuf; -use super::wire::{HashValue, Wire}; -use crate::traits::gate::{GateTrait, Wires}; use crate::transactions::add_bit_commitment_script; +use crate::wire::HashValue; +use crate::{ + traits::gate::{GateTrait, Wires}, + wire::Wire, +}; use std::sync::{Arc, Mutex}; @@ -222,7 +225,8 @@ pub fn create_gate( #[cfg(test)] mod tests { - use super::super::wire::PreimageValue; + use crate::wire::PreimageValue; + use super::*; use bitcoin::hashes::sha256; use bitcoin::hashes::Hash; diff --git a/src/lib.rs b/src/lib.rs index 32cfa61..ce1edc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ pub mod actor; pub mod circuit; pub mod communication; +pub mod gates; pub mod traits; pub mod transactions; pub mod utils; +pub mod wire; diff --git a/src/prover.rs b/src/prover.rs index 5e49f14..0315a18 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -12,18 +12,20 @@ use bitcoin::{secp256k1::Secp256k1, Amount, Transaction, XOnlyPublicKey}; use bitcoin::{OutPoint, ScriptBuf, TapLeafHash, TxIn, TxOut, Witness}; use bitcoincore_rpc::{Auth, Client, RpcApi}; -use toy_bitvm::transactions::{ +use bitvm::transactions::{ generate_2_of_2_script, generate_equivoation_address_and_info, generate_gate_response_script, generate_response_second_address_and_info, watch_transaction, }; -use toy_bitvm::circuit::wire::{HashTuple, HashValue, PreimageValue}; -use toy_bitvm::utils::number_to_bool_array; -use toy_bitvm::{ +use bitvm::utils::number_to_bool_array; +use bitvm::wire::PreimageValue; +// prover.rs +use bitvm::{ actor::Actor, circuit::Circuit, communication::{receive_message, send_message}, transactions::{generate_challenge_address_and_info, generate_response_address_and_info}, + wire::{HashTuple, HashValue}, }; use tokio_tungstenite::connect_async; diff --git a/src/traits/gate.rs b/src/traits/gate.rs index cad83f9..a383182 100644 --- a/src/traits/gate.rs +++ b/src/traits/gate.rs @@ -1,4 +1,4 @@ -use crate::circuit::wire::{HashValue, PreimageValue, Wire}; +use crate::wire::{HashValue, PreimageValue, Wire}; use bitcoin::ScriptBuf; use std::{ iter::zip, diff --git a/src/transactions/mod.rs b/src/transactions.rs similarity index 99% rename from src/transactions/mod.rs rename to src/transactions.rs index 184ba24..900f71f 100644 --- a/src/transactions/mod.rs +++ b/src/transactions.rs @@ -10,8 +10,8 @@ use bitcoin::blockdata::script::Builder; use bitcoin::opcodes::all::*; use bitcoincore_rpc::{Client, RpcApi}; -use crate::circuit::wire::{HashTuple, HashValue}; use crate::traits::gate::GateTrait; +use crate::wire::{HashTuple, HashValue}; use crate::circuit::Circuit; diff --git a/src/verifier.rs b/src/verifier.rs index e67f1b7..b4a15f2 100644 --- a/src/verifier.rs +++ b/src/verifier.rs @@ -10,22 +10,23 @@ use bitcoin::taproot::LeafVersion; use bitcoin::{secp256k1::Secp256k1, Transaction, Txid, XOnlyPublicKey}; use bitcoin::{Amount, OutPoint, ScriptBuf, TapLeafHash, TxIn, TxOut, Witness}; use bitcoincore_rpc::{Auth, Client, RpcApi}; -use toy_bitvm::circuit::wire::{HashTuple, HashValue, PreimageValue, Wire}; -use toy_bitvm::transactions::{ +use bitvm::transactions::{ generate_2_of_2_script, generate_anti_contradiction_script, generate_challenge_script, generate_equivoation_address_and_info, generate_response_second_address_and_info, watch_transaction, }; -use toy_bitvm::utils::take_stdin; +use bitvm::utils::take_stdin; +use bitvm::wire::{PreimageValue, Wire}; // verifier.rs -use tokio::net::{TcpListener, TcpStream}; -use tokio_tungstenite::accept_async; -use toy_bitvm::{ +use bitvm::{ actor::Actor, circuit::Circuit, communication::{receive_message, send_message}, transactions::{generate_challenge_address_and_info, generate_response_address_and_info}, + wire::{HashTuple, HashValue}, }; +use tokio::net::{TcpListener, TcpStream}; +use tokio_tungstenite::accept_async; #[tokio::main] async fn main() { diff --git a/src/circuit/wire.rs b/src/wire.rs similarity index 100% rename from src/circuit/wire.rs rename to src/wire.rs