From 96fd5b60ce2dadf61697d3884ce0b87986fdb7e4 Mon Sep 17 00:00:00 2001 From: orkunkilic Date: Fri, 2 Feb 2024 13:16:22 +0300 Subject: [PATCH] Revert "fix file structure" This reverts commit 7ff9b607dde4faf79061584f5b817f822060c365. --- Cargo.toml | 6 +++--- Makefile | 16 +++++++++++++++- README.md | 2 +- src/actor.rs | 2 +- src/{ => circuit}/gates.rs | 10 +++------- src/{circuit.rs => circuit/mod.rs} | 9 ++++++--- src/{ => circuit}/wire.rs | 0 src/lib.rs | 2 -- src/prover.rs | 10 ++++------ src/traits/gate.rs | 2 +- src/{transactions.rs => transactions/mod.rs} | 2 +- src/verifier.rs | 13 ++++++------- 12 files changed, 41 insertions(+), 33 deletions(-) rename src/{ => circuit}/gates.rs (98%) rename src/{circuit.rs => circuit/mod.rs} (98%) rename src/{ => circuit}/wire.rs (100%) rename src/{transactions.rs => transactions/mod.rs} (99%) diff --git a/Cargo.toml b/Cargo.toml index 6b23602..f260146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "bitvm" +name = "toy-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 d949082..f29f02e 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,18 @@ fix: check: cargo fmt -- --check - cargo clippy -- -D warnings \ No newline at end of file + 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 diff --git a/README.md b/README.md index 7f76746..c4076cc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BitVM.rs -Experimental BitVM implementation in Rust. +Experimental toy 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 14f48a7..75603ef 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -9,7 +9,7 @@ use bitcoin::{ }; use rand::Rng; -use crate::wire::{HashValue, PreimageValue}; +use crate::circuit::wire::{HashValue, PreimageValue}; pub struct Actor { secp: Secp256k1, diff --git a/src/gates.rs b/src/circuit/gates.rs similarity index 98% rename from src/gates.rs rename to src/circuit/gates.rs index 92abe0c..b7685f3 100644 --- a/src/gates.rs +++ b/src/circuit/gates.rs @@ -4,12 +4,9 @@ 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}; @@ -225,8 +222,7 @@ pub fn create_gate( #[cfg(test)] mod tests { - use crate::wire::PreimageValue; - + use super::super::wire::PreimageValue; use super::*; use bitcoin::hashes::sha256; use bitcoin::hashes::Hash; diff --git a/src/circuit.rs b/src/circuit/mod.rs similarity index 98% rename from src/circuit.rs rename to src/circuit/mod.rs index b41fa08..d53877f 100644 --- a/src/circuit.rs +++ b/src/circuit/mod.rs @@ -1,12 +1,15 @@ +pub mod gates; +pub mod wire; + use std::collections::BTreeMap; use std::iter::zip; use std::sync::{Arc, Mutex}; -use crate::gates::create_gate; -use crate::wire::HashTuple; +use gates::create_gate; +use wire::{HashTuple, Wire}; -use crate::{traits::gate::GateTrait, utils::read_lines, wire::Wire}; +use crate::{traits::gate::GateTrait, utils::read_lines}; pub struct Circuit { pub input_sizes: Vec, diff --git a/src/wire.rs b/src/circuit/wire.rs similarity index 100% rename from src/wire.rs rename to src/circuit/wire.rs diff --git a/src/lib.rs b/src/lib.rs index ce1edc2..32cfa61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ 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 0315a18..5e49f14 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -12,20 +12,18 @@ use bitcoin::{secp256k1::Secp256k1, Amount, Transaction, XOnlyPublicKey}; use bitcoin::{OutPoint, ScriptBuf, TapLeafHash, TxIn, TxOut, Witness}; use bitcoincore_rpc::{Auth, Client, RpcApi}; -use bitvm::transactions::{ +use toy_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 bitvm::utils::number_to_bool_array; -use bitvm::wire::PreimageValue; -// prover.rs -use bitvm::{ +use toy_bitvm::circuit::wire::{HashTuple, HashValue, PreimageValue}; +use toy_bitvm::utils::number_to_bool_array; +use toy_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 a383182..cad83f9 100644 --- a/src/traits/gate.rs +++ b/src/traits/gate.rs @@ -1,4 +1,4 @@ -use crate::wire::{HashValue, PreimageValue, Wire}; +use crate::circuit::wire::{HashValue, PreimageValue, Wire}; use bitcoin::ScriptBuf; use std::{ iter::zip, diff --git a/src/transactions.rs b/src/transactions/mod.rs similarity index 99% rename from src/transactions.rs rename to src/transactions/mod.rs index 900f71f..184ba24 100644 --- a/src/transactions.rs +++ b/src/transactions/mod.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 b4a15f2..e67f1b7 100644 --- a/src/verifier.rs +++ b/src/verifier.rs @@ -10,23 +10,22 @@ 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 bitvm::transactions::{ +use toy_bitvm::circuit::wire::{HashTuple, HashValue, PreimageValue, Wire}; +use toy_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 bitvm::utils::take_stdin; -use bitvm::wire::{PreimageValue, Wire}; +use toy_bitvm::utils::take_stdin; // verifier.rs -use bitvm::{ +use tokio::net::{TcpListener, TcpStream}; +use tokio_tungstenite::accept_async; +use toy_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() {