Skip to content

Commit 901d1d7

Browse files
authored
Bridge use global secp256k1 context (BitVM#185)
* replace Secp256k1::new calls with global SECP256K1 * remove secp instance from base, verifier and operator contexts * remove unused secp imports * remove unnecessary & * remove unused context args * use newer api that does not need secp256k1 instance
1 parent 9afa5cd commit 901d1d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+144
-304
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitive
5050
ark-relations = { git = "https://github.com/arkworks-rs/snark/" }
5151
serial_test = "*"
5252
tqdm = "0.7"
53+
secp256k1 = { version = "0.29.1", features = ["global-context"]}
5354

5455
[profile.dev]
5556
opt-level = 3

bridge/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ark-bn254.workspace = true
3838
ark-groth16.workspace = true
3939
ark-ff.workspace = true
4040
ark-std.workspace = true
41-
41+
secp256k1.workspace = true
4242

4343
[profile.dev]
4444
opt-level = 3

bridge/src/client/cli/client_command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl ClientCommand {
3939
let config = keys_command.read_config().expect("Failed to read config");
4040

4141
let n_of_n_public_keys = common_args.verifiers.unwrap_or_else(|| {
42-
let (_, _, verifier_0_public_key) =
42+
let (_, verifier_0_public_key) =
4343
generate_keys_from_secret(Network::Bitcoin, VERIFIER_0_SECRET);
44-
let (_, _, verifier_1_public_key) =
44+
let (_, verifier_1_public_key) =
4545
generate_keys_from_secret(Network::Bitcoin, VERIFIER_1_SECRET);
4646
vec![verifier_0_public_key, verifier_1_public_key]
4747
});

bridge/src/client/cli/key_command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ impl KeysCommand {
135135
}
136136
}
137137
fn pubkey_of(private_key: &str) -> PublicKey {
138-
generate_keys_from_secret(Network::Bitcoin, private_key).2
138+
generate_keys_from_secret(Network::Bitcoin, private_key).1
139139
}

bridge/src/client/cli/query_command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ impl QueryCommand {
3030
destination_network: DestinationNetwork,
3131
path_prefix: Option<&str>,
3232
) -> Self {
33-
let (_, _, verifier_0_public_key) =
33+
let (_, verifier_0_public_key) =
3434
generate_keys_from_secret(Network::Bitcoin, VERIFIER_0_SECRET);
35-
let (_, _, verifier_1_public_key) =
35+
let (_, verifier_1_public_key) =
3636
generate_keys_from_secret(Network::Bitcoin, VERIFIER_1_SECRET);
3737

3838
let n_of_n_public_keys: Vec<PublicKey> = vec![verifier_0_public_key, verifier_1_public_key];

bridge/src/client/client.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
peg_in::{PegInDepositorStatus, PegInVerifierStatus},
2424
peg_out::{CommitmentMessageId, PegOutOperatorStatus},
2525
},
26-
scripts::generate_pay_to_pubkey_script_address
26+
scripts::generate_pay_to_pubkey_script_address,
2727
};
2828

2929
use bitvm::signatures::signing_winternitz::WinternitzSecret;
@@ -202,21 +202,13 @@ impl BitVMClient {
202202
}
203203
}
204204

205-
pub fn get_data(&self) -> &BitVMClientPublicData {
206-
&self.data
207-
}
205+
pub fn get_data(&self) -> &BitVMClientPublicData { &self.data }
208206

209-
pub async fn sync(&mut self) {
210-
self.read().await;
211-
}
207+
pub async fn sync(&mut self) { self.read().await; }
212208

213-
pub async fn sync_l2(&mut self) {
214-
self.read_from_l2().await;
215-
}
209+
pub async fn sync_l2(&mut self) { self.read_from_l2().await; }
216210

217-
pub async fn flush(&mut self) {
218-
self.save().await;
219-
}
211+
pub async fn flush(&mut self) { self.save().await; }
220212

221213
/*
222214
File syncing flow with data store
@@ -1102,7 +1094,6 @@ impl BitVMClient {
11021094
.unwrap()
11031095
.challenge(
11041096
&self.esplora,
1105-
self.depositor_context.as_ref().unwrap(),
11061097
crowdfundng_inputs,
11071098
&self.depositor_context.as_ref().unwrap().depositor_keypair,
11081099
output_script_pubkey,
@@ -1113,7 +1104,6 @@ impl BitVMClient {
11131104
.unwrap()
11141105
.challenge(
11151106
&self.esplora,
1116-
self.operator_context.as_ref().unwrap(),
11171107
crowdfundng_inputs,
11181108
&self.operator_context.as_ref().unwrap().operator_keypair,
11191109
output_script_pubkey,
@@ -1124,7 +1114,6 @@ impl BitVMClient {
11241114
.unwrap()
11251115
.challenge(
11261116
&self.esplora,
1127-
self.verifier_context.as_ref().unwrap(),
11281117
crowdfundng_inputs,
11291118
&self.verifier_context.as_ref().unwrap().verifier_keypair,
11301119
output_script_pubkey,
@@ -1135,7 +1124,6 @@ impl BitVMClient {
11351124
.unwrap()
11361125
.challenge(
11371126
&self.esplora,
1138-
self.withdrawer_context.as_ref().unwrap(),
11391127
crowdfundng_inputs,
11401128
&self.withdrawer_context.as_ref().unwrap().withdrawer_keypair,
11411129
output_script_pubkey,

bridge/src/connectors/connector_0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use bitcoin::{
2-
key::Secp256k1,
32
taproot::{TaprootBuilder, TaprootSpendInfo},
43
Address, Network, ScriptBuf, TxIn, XOnlyPublicKey,
54
};
5+
use secp256k1::SECP256K1;
66
use serde::{Deserialize, Serialize};
77

88
use super::{
@@ -60,7 +60,7 @@ impl TaprootConnector for Connector0 {
6060
.expect("Unable to add leaf 0")
6161
.add_leaf(1, self.generate_taproot_leaf_1_script())
6262
.expect("Unable to add leaf 1")
63-
.finalize(&Secp256k1::new(), self.n_of_n_taproot_public_key)
63+
.finalize(SECP256K1, self.n_of_n_taproot_public_key)
6464
.expect("Unable to finalize taproot")
6565
}
6666

bridge/src/connectors/connector_1.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
use std::collections::HashMap;
22

33
use bitcoin::{
4-
key::Secp256k1,
54
taproot::{TaprootBuilder, TaprootSpendInfo},
65
Address, Network, ScriptBuf, TxIn, XOnlyPublicKey,
76
};
87
use bitcoin_script::script;
8+
use secp256k1::SECP256K1;
99
use serde::{Deserialize, Serialize};
1010

1111
use crate::{
1212
graphs::peg_out::CommitmentMessageId,
13-
superblock::{SUPERBLOCK_HASH_MESSAGE_LENGTH, SUPERBLOCK_MESSAGE_LENGTH}
13+
superblock::{SUPERBLOCK_HASH_MESSAGE_LENGTH, SUPERBLOCK_MESSAGE_LENGTH},
1414
};
1515

16-
use bitvm::signatures::signing_winternitz::{winternitz_message_checksig_verify, WinternitzPublicKey};
16+
use bitvm::signatures::signing_winternitz::{
17+
winternitz_message_checksig_verify, WinternitzPublicKey,
18+
};
1719

1820
use super::{
1921
super::{
@@ -128,7 +130,7 @@ impl TaprootConnector for Connector1 {
128130
.expect("Unable to add leaf 1")
129131
.add_leaf(1, self.generate_taproot_leaf_2_script())
130132
.expect("Unable to add leaf 2")
131-
.finalize(&Secp256k1::new(), self.n_of_n_taproot_public_key)
133+
.finalize(SECP256K1, self.n_of_n_taproot_public_key)
132134
.expect("Unable to finalize taproot")
133135
}
134136

bridge/src/connectors/connector_2.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ use crate::{
44
constants::{N_SEQUENCE_FOR_LOCK_TIME, START_TIME_MESSAGE_LENGTH},
55
graphs::peg_out::CommitmentMessageId,
66
};
7+
use bitcoin::{
8+
taproot::{TaprootBuilder, TaprootSpendInfo},
9+
Address, Network, ScriptBuf, TxIn, XOnlyPublicKey,
10+
};
711
use bitvm::{
812
signatures::{
13+
signing_winternitz::{winternitz_message_checksig, WinternitzPublicKey, LOG_D},
914
utils::digits_to_number,
10-
signing_winternitz::{
11-
winternitz_message_checksig, WinternitzPublicKey, LOG_D,
12-
},
1315
},
14-
treepp::script
15-
};
16-
use bitcoin::{
17-
key::Secp256k1,
18-
taproot::{TaprootBuilder, TaprootSpendInfo},
19-
Address, Network, ScriptBuf, TxIn, XOnlyPublicKey,
16+
treepp::script,
2017
};
18+
use secp256k1::SECP256K1;
2119
use serde::{Deserialize, Serialize};
2220

2321
use super::{
@@ -102,7 +100,7 @@ impl TaprootConnector for Connector2 {
102100
.expect("Unable to add leaf 0")
103101
.add_leaf(1, self.generate_taproot_leaf_1_script())
104102
.expect("Unable to add leaf 1")
105-
.finalize(&Secp256k1::new(), self.n_of_n_taproot_public_key)
103+
.finalize(SECP256K1, self.n_of_n_taproot_public_key)
106104
.expect("Unable to finalize taproot")
107105
}
108106

0 commit comments

Comments
 (0)