Skip to content

Commit

Permalink
feat: add validation for complete-deposit transactions (#545)
Browse files Browse the repository at this point in the history
* Make the serde implementations transparent
* Add validation to the CompleteDepositV1 struct. Update the number of arguments that it needs.
* Update the AsContractCall::validation function to take in a context object.
* Add integration tests to the validation function
  • Loading branch information
djordon authored Sep 24, 2024
1 parent 4215333 commit 7b7a5b3
Show file tree
Hide file tree
Showing 18 changed files with 1,158 additions and 121 deletions.
3 changes: 2 additions & 1 deletion signer/src/bitcoin/zmq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ pub fn parse_bitcoin_core_message(message: ZmqMessage) -> Result<BitcoinCoreMess
}
// We do not implement parsing for any other message types but if
// we're here, then we probably have a valid message from
// bitcoin-core. Let's try to note the topic for easier debugging.
// bitcoin-core (we know `data` has three parts). Let's try to note
// the topic for easier debugging.
_ => {
let topic = core::str::from_utf8(data[0]).map(ToString::to_string);
Err(Error::BitcoinCoreZmqUnsupported(topic))
Expand Down
5 changes: 5 additions & 0 deletions signer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::borrow::Cow;

use blockstack_lib::types::chainstate::StacksBlockId;

use crate::stacks::contracts::DepositValidationError;
use crate::{codec, ecdsa, network};

/// Top-level signer error
Expand Down Expand Up @@ -103,6 +104,10 @@ pub enum Error {
#[error("could not decode Nakamoto block from tenure with block: {1}; {0}")]
DecodeNakamotoTenure(#[source] blockstack_lib::codec::Error, StacksBlockId),

/// Failed to validate the complete-deposit contract call transaction.
#[error("{0}")]
DepositValidation(#[from] Box<DepositValidationError>),

/// An error when serializing an object to JSON
#[error("{0}")]
JsonSerialize(#[source] serde_json::Error),
Expand Down
8 changes: 8 additions & 0 deletions signer/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::error::Error;

/// The public key type for the secp256k1 elliptic curve.
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PublicKey(secp256k1::PublicKey);

impl From<&secp256k1::PublicKey> for PublicKey {
Expand Down Expand Up @@ -182,6 +183,12 @@ impl From<&PublicKey> for stacks_common::util::secp256k1::Secp256k1PublicKey {
}
}

impl From<PublicKey> for stacks_common::util::secp256k1::Secp256k1PublicKey {
fn from(value: PublicKey) -> Self {
Self::from(&value)
}
}

impl From<&stacks_common::util::secp256k1::Secp256k1PublicKey> for PublicKey {
fn from(value: &stacks_common::util::secp256k1::Secp256k1PublicKey) -> Self {
let key = secp256k1::PublicKey::from_slice(&value.to_bytes_compressed())
Expand Down Expand Up @@ -231,6 +238,7 @@ impl std::fmt::Display for PublicKey {

/// A private key type for the secp256k1 elliptic curve.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
#[serde(transparent)]
pub struct PrivateKey(secp256k1::SecretKey);

impl FromStr for PrivateKey {
Expand Down
Loading

0 comments on commit 7b7a5b3

Please sign in to comment.