Skip to content
Open
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
2 changes: 1 addition & 1 deletion contracts/mock-btc-light-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mock-btc-light-client"
version = "0.1.0"
version = "0.2.0"
edition.workspace = true
publish.workspace = true

Expand Down
16 changes: 16 additions & 0 deletions contracts/mock-btc-light-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ pub struct ProofArgs {
pub confirmations: u64,
}

#[near(serializers = [borsh])]
pub struct ProofArgsV2 {
pub tx_id: H256,
pub tx_block_blockhash: H256,
pub tx_index: u64,
pub merkle_proof: Vec<H256>,
pub coinbase_tx_id: H256,
pub coinbase_merkle_proof: Vec<H256>,
pub confirmations: u64,
}

impl<'de> Deserialize<'de> for H256 {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -82,6 +93,11 @@ impl Contract {
true
}

#[allow(unused_variables)]
pub fn verify_transaction_inclusion_v2(&self, #[serializer(borsh)] args: ProofArgsV2) -> bool {
true
}

pub fn get_last_block_height(&self) -> u32 {
// Return a reasonable mock block height for Zcash testnet
1000
Expand Down
2 changes: 1 addition & 1 deletion contracts/satoshi-bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "satoshi-bridge"
version = "0.7.5"
version = "0.8.0"
edition.workspace = true
publish.workspace = true
repository.workspace = true
Expand Down
16 changes: 16 additions & 0 deletions contracts/satoshi-bridge/src/api/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
) -> Promise {
require!(
deposit_msg.safe_deposit.is_none(),
Expand Down Expand Up @@ -68,6 +70,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
PendingUTXOInfo {
tx_id,
utxo_storage_key,
Expand Down Expand Up @@ -103,6 +107,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
) -> Promise {
require!(
env::attached_deposit() >= self.required_balance_for_safe_deposit(),
Expand Down Expand Up @@ -145,6 +151,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
PendingUTXOInfo {
tx_id,
utxo_storage_key,
Expand Down Expand Up @@ -175,6 +183,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
) -> Promise {
let btc_pending_info = self.internal_unwrap_btc_pending_info(&tx_id);
btc_pending_info.assert_withdraw_related_pending_verify_tx();
Expand All @@ -193,6 +203,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
btc_pending_info,
)
}
Expand Down Expand Up @@ -276,6 +288,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
) -> Promise {
let btc_pending_info = self.internal_unwrap_btc_pending_info(&tx_id);
btc_pending_info.assert_active_utxo_management_related_pending_verify_tx();
Expand All @@ -294,6 +308,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
btc_pending_info,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
btc_pending_info: &BTCPendingInfo,
) -> Promise {
let config = self.internal_config();
Expand All @@ -22,6 +24,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
confirmations,
)
.then(
Expand Down
8 changes: 8 additions & 0 deletions contracts/satoshi-bridge/src/btc_light_client/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
pending_utxo_info: PendingUTXOInfo,
deposit_msg: DepositMsg,
) -> Promise {
Expand All @@ -35,6 +37,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
confirmations,
);

Expand Down Expand Up @@ -74,6 +78,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
pending_utxo_info: PendingUTXOInfo,
recipient_id: AccountId,
deposit_msg: SafeDepositMsg,
Expand All @@ -86,6 +92,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
confirmations,
);

Expand Down
26 changes: 21 additions & 5 deletions contracts/satoshi-bridge/src/btc_light_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@ impl FromStr for H256 {
}

#[near(serializers = [borsh])]
pub struct ProofArgs {
pub struct ProofArgsV2 {
pub tx_id: H256,
pub tx_block_blockhash: H256,
pub tx_index: u64,
pub merkle_proof: Vec<H256>,
pub coinbase_tx_id: H256,
pub coinbase_merkle_proof: Vec<H256>,
pub confirmations: u64,
}

impl ProofArgs {
impl ProofArgsV2 {
pub fn new(
tx_id: String,
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
confirmations: u64,
) -> Self {
ProofArgs {
ProofArgsV2 {
tx_id: tx_id.parse().expect("Invalid tx_id"),
tx_block_blockhash: tx_block_blockhash
.parse()
Expand All @@ -61,6 +65,14 @@ impl ProofArgs {
.unwrap_or_else(|_| env::panic_str("Invalid merkle_proof: {v:?}"))
})
.collect(),
coinbase_tx_id: coinbase_tx_id.parse().expect("Invalid coinbase_tx_id"),
coinbase_merkle_proof: coinbase_merkle_proof
.into_iter()
.map(|v| {
v.parse()
.unwrap_or_else(|_| env::panic_str("Invalid coinbase_merkle_proof: {v:?}"))
})
.collect(),
confirmations,
}
}
Expand Down Expand Up @@ -110,7 +122,7 @@ impl Serialize for H256 {

#[ext_contract(ext_btc_light_client)]
pub trait BtcLightClient {
fn verify_transaction_inclusion(&self, #[serializer(borsh)] args: ProofArgs) -> bool;
fn verify_transaction_inclusion_v2(&self, #[serializer(borsh)] args: ProofArgsV2) -> bool;
fn get_last_block_height(&self) -> u32;
}

Expand All @@ -122,15 +134,19 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
confirmations: u64,
) -> Promise {
ext_btc_light_client::ext(btc_light_client_account_id)
.with_static_gas(GAS_FOR_VERIFY_TRANSACTION_INCLUSION)
.verify_transaction_inclusion(ProofArgs::new(
.verify_transaction_inclusion_v2(ProofArgsV2::new(
tx_id.clone(),
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
confirmations,
))
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/satoshi-bridge/src/btc_light_client/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ impl Contract {
tx_block_blockhash: String,
tx_index: u64,
merkle_proof: Vec<String>,
coinbase_tx_id: String,
coinbase_merkle_proof: Vec<String>,
btc_pending_info: &BTCPendingInfo,
) -> Promise {
let config = self.internal_config();
Expand All @@ -23,6 +25,8 @@ impl Contract {
tx_block_blockhash,
tx_index,
merkle_proof,
coinbase_tx_id,
coinbase_merkle_proof,
confirmations,
)
.then(
Expand Down
6 changes: 6 additions & 0 deletions contracts/satoshi-bridge/tests/setup/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ impl Context {
"tx_block_blockhash": tx_block_blockhash,
"tx_index": tx_index,
"merkle_proof": merkle_proof,
"coinbase_tx_id": "0000000000000000000000000000000000000000000000000000000000000000",
"coinbase_merkle_proof": merkle_proof,
}))
.max_gas()
.transact()
Expand Down Expand Up @@ -865,6 +867,8 @@ impl Context {
"tx_block_blockhash": tx_block_blockhash,
"tx_index": tx_index,
"merkle_proof": merkle_proof,
"coinbase_tx_id": "0000000000000000000000000000000000000000000000000000000000000000",
"coinbase_merkle_proof": merkle_proof,
}))
.max_gas()
.transact()
Expand All @@ -886,6 +890,8 @@ impl Context {
"tx_block_blockhash": tx_block_blockhash,
"tx_index": tx_index,
"merkle_proof": merkle_proof,
"coinbase_tx_id": "0000000000000000000000000000000000000000000000000000000000000000",
"coinbase_merkle_proof": merkle_proof,
}))
.max_gas()
.transact()
Expand Down
Loading