Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate reject-withdrawal-request #1336

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions protobufs/stacks/signer/v1/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";

package stacks.signer.v1;

import "stacks/common.proto";

// An identifier for a withdrawal request, comprised of the Stacks
// transaction ID, the Stacks block ID that included the transaction, and
// the request-id generated by the clarity contract for the withdrawal
// request.
message QualifiedRequestId {
// The ID that was generated in the clarity contract call for the
// withdrawal request.
uint64 request_id = 1;
// The txid that generated the request.
stacks.StacksTxid txid = 2;
// The Stacks block ID that includes the transaction that generated
// the request.
stacks.StacksBlockId block_hash = 3;
}

// Describes the fees for a transaction.
message Fees {
// The total fee paid in sats for the transaction.
uint64 total = 1;
// The fee rate paid in sats per virtual byte.
double rate = 2;
}
25 changes: 1 addition & 24 deletions protobufs/stacks/signer/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package stacks.signer.v1;
import "bitcoin/bitcoin.proto";
import "crypto/common.proto";
import "crypto/wsts/wsts.proto";
import "stacks/common.proto";
import "stacks/signer/v1/common.proto";
import "stacks/signer/v1/decisions.proto";
import "stacks/signer/v1/requests.proto";

Expand Down Expand Up @@ -110,26 +110,3 @@ message TxRequestIds {
// transaction.
repeated QualifiedRequestId withdrawals = 2;
}

// An identifier for a withdrawal request, comprised of the Stacks
// transaction ID, the Stacks block ID that included the transaction, and
// the request-id generated by the clarity contract for the withdrawal
// request.
message QualifiedRequestId {
// The ID that was generated in the clarity contract call for the
// withdrawal request.
uint64 request_id = 1;
// The txid that generated the request.
stacks.StacksTxid txid = 2;
// The Stacks block ID that includes the transaction that generated
// the request.
stacks.StacksBlockId block_hash = 3;
}

// Describes the fees for a transaction.
message Fees {
// The total fee paid in sats for the transaction.
uint64 total = 1;
// The fee rate paid in sats per virtual byte.
double rate = 2;
}
3 changes: 2 additions & 1 deletion protobufs/stacks/signer/v1/requests.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package stacks.signer.v1;
import "bitcoin/bitcoin.proto";
import "crypto/common.proto";
import "stacks/common.proto";
import "stacks/signer/v1/common.proto";

// Represents a request to sign a Stacks transaction.
message StacksTransactionSignRequest {
Expand Down Expand Up @@ -108,7 +109,7 @@ message RejectWithdrawal {
// The ID of the withdrawal request generated by the
// `initiate-withdrawal-request` function in the sbtc-withdrawal smart
// contract.
uint64 request_id = 1;
QualifiedRequestId id = 1;
// A bitmap of how the signers voted. The length of the list must be less
// than or equal to 128. Here, we assume that a true implies that the
// associated signer voted *against* the withdrawal.
Expand Down
1 change: 1 addition & 0 deletions sbtc/src/testing/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub struct Faucet {
}

/// Helper struct for representing an address we control on bitcoin.
#[derive(Clone)]
pub struct Recipient {
/// The public/private key pair
pub keypair: secp256k1::Keypair,
Expand Down
1 change: 1 addition & 0 deletions signer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn compile_protos() {
"protobufs/crypto/wsts/state.proto",
"protobufs/crypto/wsts/wsts.proto",
"protobufs/stacks/common.proto",
"protobufs/stacks/signer/v1/common.proto",
"protobufs/stacks/signer/v1/decisions.proto",
"protobufs/stacks/signer/v1/requests.proto",
"protobufs/stacks/signer/v1/messages.proto",
Expand Down
6 changes: 6 additions & 0 deletions signer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::keys::PublicKeyXOnly;
use crate::stacks::contracts::DepositValidationError;
use crate::stacks::contracts::RotateKeysValidationError;
use crate::stacks::contracts::WithdrawalAcceptValidationError;
use crate::stacks::contracts::WithdrawalRejectValidationError;
use crate::storage::model::SigHash;
use crate::wsts_state_machine::StateMachineId;

Expand Down Expand Up @@ -575,6 +576,11 @@ pub enum Error {
#[error("withdrawal accept validation error: {0}")]
WithdrawalAcceptValidation(#[source] Box<WithdrawalAcceptValidationError>),

/// The error for when the request to sign a withdrawal-reject
/// transaction fails at the validation step.
#[error("withdrawal reject validation error: {0}")]
WithdrawalRejectValidation(#[source] Box<WithdrawalRejectValidationError>),

/// WSTS error.
#[error("WSTS error: {0}")]
Wsts(#[source] wsts::state_machine::signer::Error),
Expand Down
4 changes: 2 additions & 2 deletions signer/src/proto/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl TryFrom<proto::AcceptWithdrawal> for AcceptWithdrawalV1 {
impl From<RejectWithdrawalV1> for proto::RejectWithdrawal {
fn from(value: RejectWithdrawalV1) -> Self {
proto::RejectWithdrawal {
request_id: value.request_id,
id: Some(value.id.into()),
signer_bitmap: value.signer_bitmap.iter().map(|e| *e).collect(),
deployer: Some(value.deployer.into()),
}
Expand All @@ -478,7 +478,7 @@ impl TryFrom<proto::RejectWithdrawal> for RejectWithdrawalV1 {
});

Ok(RejectWithdrawalV1 {
request_id: value.request_id,
id: value.id.required()?.try_into()?,
signer_bitmap,
deployer: value.deployer.required()?.try_into()?,
})
Expand Down
60 changes: 30 additions & 30 deletions signer/src/proto/generated/stacks.signer.v1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
// This file is @generated by prost-build.
/// An identifier for a withdrawal request, comprised of the Stacks
/// transaction ID, the Stacks block ID that included the transaction, and
/// the request-id generated by the clarity contract for the withdrawal
/// request.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct QualifiedRequestId {
/// The ID that was generated in the clarity contract call for the
/// withdrawal request.
#[prost(uint64, tag = "1")]
pub request_id: u64,
/// The txid that generated the request.
#[prost(message, optional, tag = "2")]
pub txid: ::core::option::Option<super::super::StacksTxid>,
/// The Stacks block ID that includes the transaction that generated
/// the request.
#[prost(message, optional, tag = "3")]
pub block_hash: ::core::option::Option<super::super::StacksBlockId>,
}
/// Describes the fees for a transaction.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Fees {
/// The total fee paid in sats for the transaction.
#[prost(uint64, tag = "1")]
pub total: u64,
/// The fee rate paid in sats per virtual byte.
#[prost(double, tag = "2")]
pub rate: f64,
}
/// Represents a decision to accept or reject a deposit request.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct SignerDepositDecision {
Expand Down Expand Up @@ -166,8 +194,8 @@ pub struct RejectWithdrawal {
/// The ID of the withdrawal request generated by the
/// `initiate-withdrawal-request` function in the sbtc-withdrawal smart
/// contract.
#[prost(uint64, tag = "1")]
pub request_id: u64,
#[prost(message, optional, tag = "1")]
pub id: ::core::option::Option<QualifiedRequestId>,
/// A bitmap of how the signers voted. The length of the list must be less
/// than or equal to 128. Here, we assume that a true implies that the
/// associated signer voted *against* the withdrawal.
Expand Down Expand Up @@ -399,31 +427,3 @@ pub struct TxRequestIds {
#[prost(message, repeated, tag = "2")]
pub withdrawals: ::prost::alloc::vec::Vec<QualifiedRequestId>,
}
/// An identifier for a withdrawal request, comprised of the Stacks
/// transaction ID, the Stacks block ID that included the transaction, and
/// the request-id generated by the clarity contract for the withdrawal
/// request.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct QualifiedRequestId {
/// The ID that was generated in the clarity contract call for the
/// withdrawal request.
#[prost(uint64, tag = "1")]
pub request_id: u64,
/// The txid that generated the request.
#[prost(message, optional, tag = "2")]
pub txid: ::core::option::Option<super::super::StacksTxid>,
/// The Stacks block ID that includes the transaction that generated
/// the request.
#[prost(message, optional, tag = "3")]
pub block_hash: ::core::option::Option<super::super::StacksBlockId>,
}
/// Describes the fees for a transaction.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Fees {
/// The total fee paid in sats for the transaction.
#[prost(uint64, tag = "1")]
pub total: u64,
/// The fee rate paid in sats per virtual byte.
#[prost(double, tag = "2")]
pub rate: f64,
}
Loading
Loading