Skip to content

Commit

Permalink
Add missing proto definitions (#878)
Browse files Browse the repository at this point in the history
* feat: add missing proto definitions

* chore: buf lint

* chore: buf format

* chore: add missing lint directive, nit

* Add missing proto conversions (#879)

* feat: add missing proto conversions

* chore: remove foresight

* chore: nits, add tests placeholder

* fix: sane point conversion

* tests: add missing proto conversion tests (#899)

* tests: add some proto conversion tests

* tests: add missing conversion tests
  • Loading branch information
matteojug authored Nov 25, 2024
1 parent 7c26c93 commit 423939c
Show file tree
Hide file tree
Showing 12 changed files with 2,331 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protobufs/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ lint:
- MINIMAL
- BASIC
- ENUM_ZERO_VALUE_SUFFIX
- ENUM_VALUE_PREFIX
- FILE_LOWER_SNAKE_CASE
- RPC_REQUEST_RESPONSE_UNIQUE
- RPC_REQUEST_STANDARD_NAME
Expand Down
34 changes: 26 additions & 8 deletions protobufs/crypto/wsts/wsts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ message DkgEnd {
DkgStatus status = 3;
}

// Signature type
// This maps to this type <https://github.com/Trust-Machines/wsts/blob/ebd7d7775ad5e44cdbf4f5c1fb468bdf6c467265/src/net.rs#L373-L382>
message SignatureType {
oneof signature_type {
// FROST signature
FrostSignatureType frost = 1;
// BIP-340 Schnorr proof
SchnorrSignatureType schnorr = 2;
// BIP-341 Taproot style schnorr proof with a merkle root
TaprootSignatureType taproot = 3;
}
}

message FrostSignatureType {}

message SchnorrSignatureType {}

message TaprootSignatureType {
// Taproot merkle root. This field is optional
MerkleRoot merkle_root = 1;
}

// Nonce request message from coordinator to signers
// This maps to this type <https://github.com/Trust-Machines/wsts/blob/2d6cb87218bb8dd9ed0519356afe57a0b9a697cb/src/net.rs#L265-L280>
message NonceRequest {
Expand All @@ -113,10 +135,8 @@ message NonceRequest {
uint64 sign_iter_id = 3;
// The message to sign
bytes message = 4;
// Whether to make a taproot signature
bool is_taproot = 5;
// Taproot merkle root. This field is optional
MerkleRoot merkle_root = 6;
// What type of signature to create
SignatureType signature_type = 5;
}

// Nonce response message from signers to coordinator
Expand Down Expand Up @@ -151,10 +171,8 @@ message SignatureShareRequest {
repeated NonceResponse nonce_responses = 4;
// Bytes to sign.
bytes message = 5;
// Whether to make a taproot signature
bool is_taproot = 6;
// Taproot merkle root. This field is optional
MerkleRoot merkle_root = 7;
// What type of signature to create
SignatureType signature_type = 6;
}

// Signature share response message from signers to coordinator
Expand Down
129 changes: 129 additions & 0 deletions protobufs/stacks/signer/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
syntax = "proto3";

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/decisions.proto";
import "stacks/signer/v1/requests.proto";

// Messages exchanged between signers
message SignerMessage {
/// The bitcoin chain tip defining the signers view of the blockchain at the time the message was created
bitcoin.BitcoinBlockHash bitcoin_chain_tip = 1;
// The message payload
oneof payload {
/// A decision related to signer deposit
SignerDepositDecision signer_deposit_decision = 2;
// A decision related to signer withdrawal
SignerWithdrawalDecision signer_withdrawal_decision = 3;
// A request to sign a Stacks transaction
StacksTransactionSignRequest stacks_transaction_sign_request = 4;
// A signature of a Stacks transaction
StacksTransactionSignature stacks_transaction_signature = 5;
// A request to sign a Bitcoin transaction
BitcoinTransactionSignRequest bitcoin_transaction_sign_request = 6;
// An acknowledgment of a signed Bitcoin transaction
BitcoinTransactionSignAck bitcoin_transaction_sign_ack = 7;
// Contains all variants for DKG and WSTS signing rounds
WstsMessage wsts_message = 8;
// Information about a new sweep transaction
SweepTransactionInfo sweep_transaction_info = 9;
}
}

// Represents information about a deposit request being swept-in by a sweep transaction.
message SweptDeposit {
// The index of the deposit input in the sBTC sweep transaction.
uint32 input_index = 1;
// The Bitcoin txid of the deposit request UTXO being swept-in by this
// transaction.
bitcoin.BitcoinTxid deposit_request_txid = 2;
// The Bitcoin output index of the deposit request UTXO being swept-in by
// this transaction.
uint32 deposit_request_output_index = 3;
}

// Represents information about a withdrawal request being swept-out by a sweep transaction.
message SweptWithdrawal {
// The index of the withdrawal output in the sBTC sweep transaction.
uint32 output_index = 1;
// The public request id of the withdrawal request serviced by this
// transaction.
uint64 withdrawal_request_id = 2;
// The Stacks block hash of the Stacks block which included the withdrawal
// request transaction.
stacks.StacksBlockId withdrawal_request_block_hash = 3;
}

// Represents information about a new sweep transaction.
message SweepTransactionInfo {
// The Bitcoin transaction id of the sweep transaction.
bitcoin.BitcoinTxid txid = 1;
// The transaction id of the signer UTXO consumed by this transaction.
bitcoin.BitcoinTxid signer_prevout_txid = 2;
// The index of the signer UTXO consumed by this transaction.
uint32 signer_prevout_output_index = 3;
// The amount of the signer UTXO consumed by this transaction.
uint64 signer_prevout_amount = 4;
// The public key of the signer UTXO consumed by this transaction.
bytes signer_prevout_script_pubkey = 5;
// The total **output** amount of this transaction.
uint64 amount = 6;
// The fee paid for this transaction.
uint64 fee = 7;
// The virtual size of this transaction (in bytes).
uint32 vsize = 8;
// The Bitcoin block hash at which this transaction was created.
bitcoin.BitcoinBlockHash created_at_block_hash = 9;
// The market fee rate at the time of this transaction.
double market_fee_rate = 10;
// List of deposits which were swept-in by this transaction.
repeated SweptDeposit swept_deposits = 11;
// List of withdrawals which were swept-out by this transaction.
repeated SweptWithdrawal swept_withdrawals = 12;
}

// A wsts message.
message WstsMessage {
// The transaction ID this message relates to, will be a dummy ID for DKG messages
bitcoin.BitcoinTxid txid = 1;
// The wsts message
oneof inner {
// Tell signers to begin DKG by sending DKG public shares
crypto.wsts.DkgBegin dkg_begin = 2;
// Send DKG public shares
crypto.wsts.SignerDkgPublicShares signer_dkg_public_shares = 3;
// Tell signers to send DKG private shares
crypto.wsts.DkgPrivateBegin dkg_private_begin = 4;
// Send DKG private shares
crypto.wsts.DkgPrivateShares dkg_private_shares = 5;
// Tell signers to compute shares and send DKG end
crypto.wsts.DkgEndBegin dkg_end_begin = 6;
// Tell coordinator that DKG is complete
crypto.wsts.DkgEnd dkg_end = 7;
// Tell signers to send signing nonces
crypto.wsts.NonceRequest nonce_request = 8;
// Tell coordinator signing nonces
crypto.wsts.NonceResponse nonce_response = 9;
// Tell signers to construct signature shares
crypto.wsts.SignatureShareRequest signature_share_request = 10;
// Tell coordinator signature shares
crypto.wsts.SignatureShareResponse signature_share_response = 11;
}
}

// Wraps an inner type with a public key and a signature,
// allowing easy verification of the integrity of the inner data.
message Signed {
// The public key of the signer.
crypto.PublicKey signer_pub_key = 1;
// A signature over the hash of the inner structure.
bytes signature = 2;
// The signed structure.
oneof inner {
SignerMessage signer_message = 3;
}
}
27 changes: 24 additions & 3 deletions protobufs/stacks/signer/v1/requests.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ message StacksTransactionSignRequest {
// and a few other things.
crypto.Uint256 digest = 4;
// The transaction ID of the associated contract call transaction.
crypto.Uint256 txid = 5;
// The contract call transaction to sign.
oneof contract_call {
StacksTxid txid = 5;
// The contract transaction to sign.
oneof contract_tx {
// The `complete-deposit` contract call
CompleteDeposit complete_deposit = 6;
// The `accept-withdrawal-request` contract call
Expand All @@ -39,9 +39,30 @@ message StacksTransactionSignRequest {
RejectWithdrawal reject_withdrawal = 8;
// The `rotate-keys-wrapper` contract call
RotateKeys rotate_keys = 9;
// Ssmart contract deployment
SmartContract smart_contract = 10;
}
}

enum SmartContract {
SMART_CONTRACT_UNSPECIFIED = 0;
// The sbtc-registry contract. This contract needs to be deployed
// before any other contract.
SMART_CONTRACT_SBTC_REGISTRY = 1;
// The sbtc-token contract. This contract needs to be deployed right
// after the sbtc-registry contract.
SMART_CONTRACT_SBTC_TOKEN = 2;
// The sbtc-deposit contract. Can be deployed after the sbtc-token
// contract.
SMART_CONTRACT_SBTC_DEPOSIT = 3;
// The sbtc-withdrawal contract. Can be deployed after the sbtc-token
// contract.
SMART_CONTRACT_SBTC_WITHDRAWAL = 4;
// The sbtc-bootstrap-signers contract. Can be deployed after the
// sbtc-token contract.
SMART_CONTRACT_SBTC_BOOTSTRAP = 5;
}

// For making a `complete-deposit` contract call in the sbtc-deposit
// smart contract.
message CompleteDeposit {
Expand Down
1 change: 1 addition & 0 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ zeromq.workspace = true
hex.workspace = true
cfg-if = "1.0"
include_dir = "0.7.4"
polynomial = "0.2.6"

# Only for testing
mockall = { version = "0.12.1", optional = true }
Expand Down
1 change: 1 addition & 0 deletions signer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn compile_protos() {
"protobufs/stacks/common.proto",
"protobufs/stacks/signer/v1/decisions.proto",
"protobufs/stacks/signer/v1/requests.proto",
"protobufs/stacks/signer/v1/messages.proto",
]
.map(|path| workingdir.join(path));

Expand Down
Loading

0 comments on commit 423939c

Please sign in to comment.