Skip to content

Commit

Permalink
Clean Up (#37)
Browse files Browse the repository at this point in the history
* fix file structure

* fix file structure

* Revert "fix file structure"

This reverts commit 7ff9b60.

* lint

* fix inputs

* remove unnecessary make

* clean prints

* lint

* Exit after slashing

---------

Co-authored-by: Ekrem BAL <[email protected]>
  • Loading branch information
orkunkilic and ekrembal authored Feb 2, 2024
1 parent 3dc2c8c commit 8f84330
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 246 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Chainway Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ fix:

check:
cargo fmt -- --check
cargo clippy -- -D warnings
cargo clippy -- -D warnings

lint:
cargo +nightly fmt --all --check
cargo check --all-targets --all-features
cargo clippy --all-targets --all-features

lint-fix:
cargo +nightly fmt --all
cargo fix --allow-dirty
cargo clippy --fix --allow-dirty
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# BitVM.rs
# Toy BitVM in Rust

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.


Run regtest with the following command:
```
bitcoind -regtest -rpcuser=admin -rpcpassword=admin -rpcport=18443 -fallbackfee=0.00001 -wallet=admin
```

Then run the following command to generate blocks continuously:
```
bitcoin-cli -regtest -rpcuser=admin -rpcpassword=admin createwallet "admin"
sh ./regtest-commands.sh
```

Then start the verifier binary with the following command:
```
cargo run --bin verifier
```
bitcoin-cli -regtest -rpcuser=admin -rpcpassword=admin generatetoaddress 101 $(bitcoin-cli -regtest -rpcuser=admin -rpcpassword=admin getnewaddress)

Start the prover binary with the following command in another terminal:
```
cargo run --bin prover
```

From now on, you can start challenging gates and waiting for the prover to respond.
There is a fraud hardcoded in the code. Challenge `64` for first, then `63` to see the fraud and slash the prover.
2 changes: 1 addition & 1 deletion src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<All>,
Expand Down
10 changes: 3 additions & 7 deletions src/gates.rs → src/circuit/gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/circuit.rs → src/circuit/mod.rs
Original file line number Diff line number Diff line change
@@ -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<usize>,
Expand Down Expand Up @@ -212,7 +215,7 @@ mod tests {
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());
let output = bool_array_to_number(o.first().unwrap().to_vec());
assert_eq!(output, a1 + a2);
}
}
File renamed without changes.
1 change: 0 additions & 1 deletion src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// communication.rs
use futures_util::{SinkExt, StreamExt};
use serde::{Deserialize, Serialize};
use std::error::Error;
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
179 changes: 0 additions & 179 deletions src/main.rs

This file was deleted.

Loading

0 comments on commit 8f84330

Please sign in to comment.