Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Cargo Build & Test

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
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:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add clippy
- run: cargo clippy --all-targets -- -D warnings
test:
name: Cargo Test
runs-on: ubuntu-latest
environment:
GOAT_CHAIN_URL: https://rpc.testnet3.goat.network
GOAT_GATEWAY_CONTRACT_ADDRESS: 0xeD8AeeD334fA446FA03Aa00B28aFf02FA8aC02df
GOAT_GATEWAY_CONTRACT_CREATION: 0
GOAT_CHAIN_ID: 48816
RUST_LOG: info"
strategy:
matrix:
toolchain:
- nightly
steps:
- uses: actions/checkout@v2
- run: cargo test -r
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ members = [
"crates/store", "crates/identity", "node", "crates/spv", "crates/client",
]

default-members = ["node"]

[workspace.dependencies]
bitvm = { git = "https://github.com/GOATNetwork/BitVM.git", branch = "goat-test" }
goat = { git = "https://github.com/GOATNetwork/BitVM.git", branch = "goat-test" }
Expand Down Expand Up @@ -72,6 +70,7 @@ tracing-subscriber = "0.3.19"
anyhow = "1.0.97"

axum = "0.8.1"
axum-extra = { version = "0.8" }
http = "1.3.1"
uuid = { version = "1.7", features = ["v4", "serde"] }
zeroize = "1.8.1"
Expand Down
14 changes: 0 additions & 14 deletions crates/bitvm2/src/challenger/mod.rs

This file was deleted.

6 changes: 3 additions & 3 deletions crates/bitvm2/src/committee/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::types::Bitvm2Graph;
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use bitcoin::PublicKey;
use bitcoin::{hex::FromHex, key::Keypair, TapSighashType, Witness};
use bitcoin::{TapSighashType, Witness, hex::FromHex, key::Keypair};
use goat::connectors::{connector_0::Connector0, connector_5::Connector5, connector_d::ConnectorD};
use goat::contexts::base::generate_n_of_n_public_key;
use goat::transactions::signing_musig2::{
Expand All @@ -11,7 +11,7 @@ use goat::transactions::{
base::BaseTransaction, pre_signed::PreSignedTransaction, pre_signed_musig2::get_nonce_message,
signing_musig2::generate_taproot_partial_signature,
};
use musig2::{secp256k1::schnorr::Signature, AggNonce, PartialSignature, PubNonce, SecNonce};
use musig2::{AggNonce, PartialSignature, PubNonce, SecNonce, secp256k1::schnorr::Signature};
use sha2::{Digest, Sha256};

pub const COMMITTEE_PRE_SIGN_NUM: usize = 5;
Expand Down
6 changes: 3 additions & 3 deletions crates/bitvm2/src/committee/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod api;

pub use api::{
committee_pre_sign, generate_keypair_from_seed, generate_nonce_from_seed, key_aggregation,
nonce_aggregation, nonces_aggregation, push_committee_pre_signatures,
signature_aggregation_and_push, COMMITTEE_PRE_SIGN_NUM,
COMMITTEE_PRE_SIGN_NUM, committee_pre_sign, generate_keypair_from_seed,
generate_nonce_from_seed, key_aggregation, nonce_aggregation, nonces_aggregation,
push_committee_pre_signatures, signature_aggregation_and_push,
};
4 changes: 2 additions & 2 deletions crates/bitvm2/src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{
committee::{generate_keypair_from_seed, generate_nonce_from_seed, COMMITTEE_PRE_SIGN_NUM},
committee::{COMMITTEE_PRE_SIGN_NUM, generate_keypair_from_seed, generate_nonce_from_seed},
operator::generate_wots_keys,
types::{WotsPublicKeys, WotsSecretKeys},
};
use bitcoin::key::Keypair;
use musig2::{secp256k1::schnorr::Signature, PubNonce, SecNonce};
use musig2::{PubNonce, SecNonce, secp256k1::schnorr::Signature};
use sha2::{Digest, Sha256};
use uuid::Uuid;

Expand Down
1 change: 0 additions & 1 deletion crates/bitvm2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod challenger;
pub mod committee;
pub mod operator;
pub mod verifier;
Expand Down
22 changes: 11 additions & 11 deletions crates/bitvm2/src/operator/api.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::types::{
get_magic_bytes, Bitvm2Graph, Bitvm2Parameters, CustomInputs, Groth16Proof,
Groth16WotsPublicKeys, Groth16WotsSignatures, PublicInputs, VerifyingKey, WotsPublicKeys,
WotsSecretKeys,
Bitvm2Graph, Bitvm2Parameters, CustomInputs, Groth16Proof, Groth16WotsPublicKeys,
Groth16WotsSignatures, PublicInputs, VerifyingKey, WotsPublicKeys, WotsSecretKeys,
get_magic_bytes,
};
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use bitcoin::Transaction;
use bitcoin::{key::Keypair, Amount, OutPoint, Witness, XOnlyPublicKey};
use bitcoin::{Amount, OutPoint, Witness, XOnlyPublicKey, key::Keypair};
use bitvm::chunk::api::{
api_generate_full_tapscripts, api_generate_partial_script, generate_signatures_lit,
type_conversion_utils::utils_raw_witnesses_from_signatures, NUM_HASH, NUM_PUBS, NUM_U256,
NUM_HASH, NUM_PUBS, NUM_U256, api_generate_full_tapscripts, api_generate_partial_script,
generate_signatures_lit, type_conversion_utils::utils_raw_witnesses_from_signatures,
};
use bitvm::signatures::{
signing_winternitz::{WinternitzPublicKey, WinternitzSecret, WinternitzSigningInputs, LOG_D},
signing_winternitz::{LOG_D, WinternitzPublicKey, WinternitzSecret, WinternitzSigningInputs},
winternitz::Parameters,
wots_api::{wots256, wots_hash},
wots_api::{wots_hash, wots256},
};
use bitvm::treepp::*;
use goat::commitments::{CommitmentMessageId, KICKOFF_MSG_SIZE, NUM_KICKOFF};
Expand All @@ -28,8 +28,8 @@ use goat::transactions::{
assert::assert_final::AssertFinalTransaction,
assert::assert_initial::AssertInitialTransaction,
assert::utils::{
convert_to_connector_c_commits_public_key, AllCommitConnectorsE, AssertCommitConnectorsF,
COMMIT_TX_NUM,
AllCommitConnectorsE, AssertCommitConnectorsF, COMMIT_TX_NUM,
convert_to_connector_c_commits_public_key,
},
base::Input,
challenge::ChallengeTransaction,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitvm2/src/pegin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitcoin::opcodes::all::OP_RETURN;
use bitcoin::script::Instruction;
use bitcoin::{script, Network, Script};
use bitcoin::{Network, Script, script};

use crate::types::get_magic_bytes;

Expand Down
22 changes: 11 additions & 11 deletions crates/bitvm2/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bitcoin::TapNodeHash;
use bitcoin::{key::Keypair, Address, Amount, Network, PrivateKey, PublicKey, XOnlyPublicKey};
use bitcoin::{Address, Amount, Network, PrivateKey, PublicKey, XOnlyPublicKey, key::Keypair};
use bitvm::chunk::api::{
PublicKeys as ApiWotsPublicKeys, Signatures as ApiWotsSignatures, NUM_HASH, NUM_PUBS, NUM_U256,
NUM_HASH, NUM_PUBS, NUM_U256, PublicKeys as ApiWotsPublicKeys, Signatures as ApiWotsSignatures,
};
use bitvm::signatures::signing_winternitz::{WinternitzPublicKey, WinternitzSecret};
use goat::commitments::NUM_KICKOFF;
Expand All @@ -15,7 +15,7 @@ use goat::transactions::{
kick_off::KickOffTransaction, peg_in::peg_in::PegInTransaction,
peg_out_confirm::PreKickoffTransaction, take_1::Take1Transaction, take_2::Take2Transaction,
};
use rand::{distributions::Alphanumeric, Rng};
use rand::{Rng, distributions::Alphanumeric};
use secp256k1::SECP256K1;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -172,7 +172,7 @@ pub fn get_magic_bytes(net: &Network) -> Vec<u8> {
}

pub mod node_serializer {
use serde::{self, ser::Error, Deserialize, Deserializer, Serializer};
use serde::{self, Deserialize, Deserializer, Serializer, ser::Error};
use std::str::FromStr;

pub mod address {
Expand Down Expand Up @@ -203,7 +203,7 @@ pub mod node_serializer {
use crate::types::WotsPublicKeys;
use bitvm::chunk::api::{NUM_HASH, NUM_PUBS, NUM_U256};
use bitvm::signatures::signing_winternitz::WinternitzPublicKey;
use bitvm::signatures::wots_api::{wots256, wots_hash};
use bitvm::signatures::wots_api::{wots_hash, wots256};
use goat::commitments::NUM_KICKOFF;
use std::collections::HashMap;

Expand All @@ -214,17 +214,17 @@ pub mod node_serializer {
let mut pubkeys_map: HashMap<u32, Vec<Vec<u8>>> = HashMap::new();
let mut index = 0;
// wots pk for groth16 proof
for pk in pubkeys.1 .0 {
for pk in pubkeys.1.0 {
let v: Vec<Vec<u8>> = pk.iter().map(|x| x.to_vec()).collect();
pubkeys_map.insert(index, v);
index += 1;
}
for pk in pubkeys.1 .1 {
for pk in pubkeys.1.1 {
let v: Vec<Vec<u8>> = pk.iter().map(|x| x.to_vec()).collect();
pubkeys_map.insert(index, v);
index += 1;
}
for pk in pubkeys.1 .2 {
for pk in pubkeys.1.2 {
let v: Vec<Vec<u8>> = pk.iter().map(|x| x.to_vec()).collect();
pubkeys_map.insert(index, v);
index += 1;
Expand Down Expand Up @@ -359,11 +359,11 @@ pub mod node_serializer {
pub mod wots_seckeys {
use serde::de::{SeqAccess, Visitor};
use serde::ser::SerializeTuple;
use serde::{de::Error as DeError, ser::Error, Deserializer, Serializer};
use serde::{Deserializer, Serializer, de::Error as DeError, ser::Error};
use std::fmt;

use crate::types::{
Groth16WotsSecretKeys, KickoffWotsSecretKeys, WotsSecretKeys, NUM_KICKOFF, NUM_SIGS,
Groth16WotsSecretKeys, KickoffWotsSecretKeys, NUM_KICKOFF, NUM_SIGS, WotsSecretKeys,
};

pub fn serialize<S>(keys: &WotsSecretKeys, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -445,7 +445,7 @@ pub mod node_serializer {
#[cfg(test)]
mod tests {
use crate::operator::generate_wots_keys;
use crate::types::{node_serializer, WotsPublicKeys, WotsSecretKeys};
use crate::types::{WotsPublicKeys, WotsSecretKeys, node_serializer};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

Expand Down
9 changes: 5 additions & 4 deletions crates/bitvm2/src/verifier/api.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::types::{
Bitvm2Graph, Groth16WotsPublicKeys, Groth16WotsSignatures, VerifyingKey, WotsPublicKeys,
};
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use bitcoin::{Address, Amount, Transaction};
use bitvm::chunk::api::{
type_conversion_utils::{script_to_witness, utils_signatures_from_raw_witnesses, RawWitness},
validate_assertions, NUM_TAPS,
NUM_TAPS,
type_conversion_utils::{RawWitness, script_to_witness, utils_signatures_from_raw_witnesses},
validate_assertions,
};
use bitvm::treepp::*;
use goat::connectors::connector_c::{get_commit_from_assert_commit_tx, ConnectorC};
use goat::connectors::connector_c::{ConnectorC, get_commit_from_assert_commit_tx};
use goat::transactions::assert::utils::*;
use goat::transactions::{base::BaseTransaction, pre_signed::PreSignedTransaction};

Expand Down
1 change: 1 addition & 0 deletions crates/bitvm2/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use secp256k1::SECP256K1;
use std::str::FromStr;

#[test]
#[ignore]
fn e2e_test() {
let network = Network::Testnet;
// key generation
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/chain/chain_adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub struct BitcoinTx {

pub fn get_chain_adaptor(
network: GoatNetwork,
goat_config: Option<GoatInitConfig>,
goat_config: GoatInitConfig,
mock_adaptor_config: Option<MockAdaptorConfig>,
) -> Box<dyn ChainAdaptor> {
match network {
Expand Down
46 changes: 7 additions & 39 deletions crates/client/src/chain/goat_adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use alloy::primitives::TxHash;
use alloy::{
eips::BlockNumberOrTag,
network::{
eip2718::Encodable2718, Ethereum, EthereumWallet, NetworkWallet, TransactionBuilder,
TxSigner, TxSignerSync,
Ethereum, EthereumWallet, NetworkWallet, TransactionBuilder, TxSigner, TxSignerSync,
eip2718::Encodable2718,
},
primitives::{Address as EvmAddress, Bytes, ChainId, FixedBytes, U256},
providers::{Provider, ProviderBuilder, RootProvider},
rpc::types::TransactionRequest,
signers::{local::PrivateKeySigner, Signer},
signers::{Signer, local::PrivateKeySigner},
sol,
sol_types::SolEvent,
transports::http::{reqwest::Url, Client, Http},
transports::http::{Client, Http, reqwest::Url},
};
use anyhow::format_err;
use async_trait::async_trait;
Expand Down Expand Up @@ -287,7 +287,7 @@ impl ChainAdaptor for GoatAdaptor {
.await?;
Ok(WithdrawData {
pegin_txid: res._0.0,
operator_address: res._1.0 .0,
operator_address: res._1.0.0,
status: res._2.into(),
instance_id: Uuid::from_slice(res._3.as_slice())?,
lock_amount: res._4,
Expand Down Expand Up @@ -541,40 +541,8 @@ impl ChainAdaptor for GoatAdaptor {
}

impl GoatAdaptor {
pub fn new(config: Option<GoatInitConfig>) -> Self {
if let Some(_config) = config {
Self::from_config(_config)
} else {
dotenv::dotenv().ok();
let rpc_url_str = dotenv::var("GATE_CHAIN_ADAPTOR_GOAT_RPC_URL")
.expect("Failed to read GATE_CHAIN_ADAPTOR_GOAT_RPC_URL variable");
let gateway_address_str = dotenv::var("GATEWAY_CHAIN_ADAPTOR_GOAT_GATE_ADDRESS")
.expect("Failed to read GATE_CHAIN_ADAPTOR_GOAT_GATE_ADDRESS variable");
let gateway_creation = dotenv::var("GATE_CHAIN_ADAPTOR_GOAT_GATE_CREATION")
.expect("Failed to read GATE_CHAIN_ADAPTOR_GOAT_GATE_CREATION variable");
let to_block = dotenv::var("GATE_CHAIN_ADAPTOR_GOAT_TO_BLOCK");

let private_key = match dotenv::var("GATE_CHAIN_ADAPTOR_GOAT_PRIVATE_KEY") {
Ok(key) => Some(key),
Err(_) => None,
};
let chain_id = dotenv::var("GATE_CHAIN_ADAPTOR_GOAT_CHAIN_ID")
.expect("Failed to read GATE_CHAIN_ADAPTOR_GOAT_CHAIN_ID variable");

let rpc_url = rpc_url_str.parse::<Url>();
let gateway_address = gateway_address_str.parse::<EvmAddress>();
Self::from_config(GoatInitConfig {
rpc_url: rpc_url.unwrap(),
gateway_address: gateway_address.unwrap(),
gateway_creation_block: gateway_creation.parse::<u64>().unwrap(),
to_block: match to_block {
Ok(block) => Some(BlockNumberOrTag::from_str(block.as_str()).unwrap()),
Err(_) => Some(BlockNumberOrTag::Finalized),
},
private_key,
chain_id: chain_id.parse().expect("fail to parse int"),
})
}
pub fn new(config: GoatInitConfig) -> Self {
Self::from_config(config)
}

fn from_config(config: GoatInitConfig) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::chain::chain::Chain;
use crate::chain::chain_adaptor::{
get_chain_adaptor, ChainAdaptor, GoatNetwork, OperatorData, PeginData, WithdrawData,
ChainAdaptor, GoatNetwork, OperatorData, PeginData, WithdrawData, get_chain_adaptor,
};
use crate::chain::goat_adaptor::GoatInitConfig;
use crate::esplora::get_esplora_url;
Expand All @@ -26,7 +26,7 @@ impl BitVM2Client {
esplora_url: Option<&str>,
btc_network: Network,
goat_network: GoatNetwork,
goat_config: Option<GoatInitConfig>,
goat_config: GoatInitConfig,
) -> Self {
let local_db = LocalDB::new(&format!("sqlite:{db_path}"), true).await;
local_db.migrate().await;
Expand Down
Loading