Skip to content

Commit

Permalink
btcstaking: presigning unbonding tx (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis authored Dec 6, 2023
1 parent 83d72c6 commit 1dfc9c8
Show file tree
Hide file tree
Showing 30 changed files with 1,862 additions and 2,430 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/docker/docker v23.0.1+incompatible
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/hashicorp/go-metrics v0.5.1
Expand Down Expand Up @@ -161,7 +162,6 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/cli v23.0.1+incompatible // indirect
github.com/docker/docker v23.0.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/dot v1.6.0 // indirect
Expand Down
35 changes: 17 additions & 18 deletions proto/babylon/btcstaking/v1/btcstaking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,24 @@ message BTCUndelegation {
// It is partially signed by SK corresponding to btc_pk, but not signed by
// validator or covenant yet.
bytes slashing_tx = 3 [ (gogoproto.customtype) = "BTCSlashingTx" ];
// delegator_unbonding_sig is the signature on the unbonding tx
// by the delegator (i.e., SK corresponding to btc_pk).
// It effectively proves that the delegator wants to unbond and thus
// Babylon will consider this BTC delegation unbonded. Delegator's BTC
// on Bitcoin will be unbonded after timelock
bytes delegator_unbonding_sig = 4 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
// delegator_slashing_sig is the signature on the slashing tx
// by the delegator (i.e., SK corresponding to btc_pk).
// It will be a part of the witness for the unbonding tx output.
bytes delegator_slashing_sig = 4 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
bytes delegator_slashing_sig = 5 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
// covenant_slashing_sigs is a list of adaptor signatures on the slashing tx
// by each covenant member
// It will be a part of the witness for the staking tx output.
repeated CovenantAdaptorSignatures covenant_slashing_sigs = 5;
repeated CovenantAdaptorSignatures covenant_slashing_sigs = 6;
// covenant_unbonding_sig_list is the list of signatures on the unbonding tx
// by covenant members
// It must be provided after processing undelagate message by Babylon
repeated SignatureInfo covenant_unbonding_sig_list = 6;
repeated SignatureInfo covenant_unbonding_sig_list = 7;
}


Expand Down Expand Up @@ -151,28 +157,21 @@ message BTCDelegatorDelegationIndex {
repeated bytes staking_tx_hash_list = 1;
}

// BTCDelegationStatus is the status of a delegation. There are two possible state
// transition paths:
// 1. PENDING -> ACTIVE -> UNBONDED - this is the typical path when timelock of staking
// transaction expires.
// 2. PENDING _> ACTIVE -> UNBONDING -> UNBONDED - this is the path when staker requests undelegation through
// MsgBTCUndelegate message.
// BTCDelegationStatus is the status of a delegation. The state transition path is
// PENDING -> ACTIVE -> UNBONDED with two possibilities:
// 1. the typical path when timelock of staking transaction expires.
// 2. the path when staker requests early undelegation through MsgBTCUndelegate message.
enum BTCDelegationStatus {
// PENDING defines a delegation that is waiting for a covenant signature to become active.
// PENDING defines a delegation that is waiting for covenant signatures to become active.
PENDING = 0;
// ACTIVE defines a delegation that has voting power
ACTIVE = 1;
// UNBONDING defines a delegation that is being unbonded i.e it received an unbonding tx
// from staker, but not yet received signatures from validator and covenant.
// Delegation in this state already lost its voting power.
UNBONDING = 2;
// UNBONDED defines a delegation no longer has voting power:
// - either reaching the end of staking transaction timelock
// - or receiving unbonding tx and then receiving signatures from validator and covenant for this
// unbonding tx.
UNBONDED = 3;
// - or receiving unbonding tx with signatures from staker and covenant committee
UNBONDED = 2;
// ANY is any of the above status
ANY = 4;
ANY = 3;
}

// SignatureInfo is a BIP-340 signature together with its signer's BIP-340 PK
Expand Down
103 changes: 48 additions & 55 deletions proto/babylon/btcstaking/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@ import "babylon/btcstaking/v1/pop.proto";
option go_package = "github.com/babylonchain/babylon/x/btcstaking/types";

// Msg defines the Msg service.
// TODO: handle unbonding tx with full witness
service Msg {
option (cosmos.msg.v1.service) = true;

// CreateBTCValidator creates a new BTC validator
rpc CreateBTCValidator(MsgCreateBTCValidator) returns (MsgCreateBTCValidatorResponse);
// CreateBTCDelegation creates a new BTC delegation
rpc CreateBTCDelegation(MsgCreateBTCDelegation) returns (MsgCreateBTCDelegationResponse);
// BtcUndelegate undelegates funds from exsitng btc delegation
rpc BTCUndelegate(MsgBTCUndelegate) returns (MsgBTCUndelegateResponse);
// AddCovenantSig handles a signature from covenant for slashing tx of staking tx for delegation
rpc AddCovenantSig(MsgAddCovenantSig) returns (MsgAddCovenantSigResponse);
// AddCovenantUnbondingSigs handles two signatures from covenant for:
// - unbonding tx submitted to babylon by staker
// - slashing tx corresponding to unbonding tx submitted to babylon by staker
rpc AddCovenantUnbondingSigs(MsgAddCovenantUnbondingSigs) returns (MsgAddCovenantUnbondingSigsResponse);
// AddCovenantSigs handles signatures from a covenant member
rpc AddCovenantSigs(MsgAddCovenantSigs) returns (MsgAddCovenantSigsResponse);
// UpdateParams updates the btcstaking module parameters.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// BTCUndelegate handles a signature on unbonding tx from its delegator
rpc BTCUndelegate(MsgBTCUndelegate) returns (MsgBTCUndelegateResponse);
}

// MsgCreateBTCValidator is the message for creating a BTC validator
Expand Down Expand Up @@ -79,40 +76,32 @@ message MsgCreateBTCDelegation {
// slashing_tx is the slashing tx
// Note that the tx itself does not contain signatures, which are off-chain.
bytes slashing_tx = 9 [ (gogoproto.customtype) = "BTCSlashingTx" ];
// delegator_sig is the signature on the slashing tx by the delegator (i.e., SK corresponding to btc_pk).
// delegator_slashing_sig is the signature on the slashing tx by the delegator (i.e., SK corresponding to btc_pk).
// It will be a part of the witness for the staking tx output.
// The staking tx output further needs signatures from covenant and validator in
// order to be spendable.
bytes delegator_sig = 10 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
}
// MsgCreateBTCDelegationResponse is the response for MsgCreateBTCDelegation
message MsgCreateBTCDelegationResponse {}
bytes delegator_slashing_sig = 10 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];

// MsgBTCUndelegate is the message undelegating existing and active delegation
message MsgBTCUndelegate {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1;
/// fields related to on-demand unbonding
// unbonding_tx is bitcoin unbonding transaction i.e transaction that spends
// staking output and sends it to the unbonding output
bytes unbonding_tx = 2;
bytes unbonding_tx = 11;
// unbonding_time is the time lock used in unbonding transaction
uint32 unbonding_time = 3;
uint32 unbonding_time = 12;
// unbonding_value is amount of satoshis locked in unbonding output.
// NOTE: staking_value and unbonding_value could be different because of the difference between the fee for staking tx and that for unbonding
int64 unbonding_value = 4;
// slashing_tx is the slashing tx which slash unbonding contract
int64 unbonding_value = 13;
// unbonding_slashing_tx is the slashing tx which slash unbonding contract
// Note that the tx itself does not contain signatures, which are off-chain.
bytes slashing_tx = 5 [ (gogoproto.customtype) = "BTCSlashingTx" ];
// delegator_slashing_sig is the signature on the slashing tx by the delegator (i.e., SK corresponding to btc_pk).
bytes delegator_slashing_sig = 6 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
bytes unbonding_slashing_tx = 14 [ (gogoproto.customtype) = "BTCSlashingTx" ];
// delegator_unbonding_slashing_sig is the signature on the slashing tx by the delegator (i.e., SK corresponding to btc_pk).
bytes delegator_unbonding_slashing_sig = 15 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
}
// MsgCreateBTCDelegationResponse is the response for MsgCreateBTCDelegation
message MsgCreateBTCDelegationResponse {}

// MsgBtcUndelegateResponse is the response for MsgBtcUndelegate
message MsgBTCUndelegateResponse {}

// MsgAddCovenantSig is the message for handling a signature from covenant
message MsgAddCovenantSig {
// MsgAddCovenantSigs is the message for handling signatures from a covenant member
message MsgAddCovenantSigs {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1;
Expand All @@ -124,10 +113,36 @@ message MsgAddCovenantSig {
// sigs is a list of adaptor signatures of the covenant
// the order of sigs should respect the order of validators
// of the corresponding delegation
repeated bytes sigs = 4;
repeated bytes slashing_tx_sigs = 4;
// unbonding_tx_sig is the signature of the covenant on the unbonding tx submitted to babylon
// the signature follows encoding in BIP-340 spec
bytes unbonding_tx_sig = 5 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
// slashing_unbonding_tx_sigs is a list of adaptor signatures of the covenant
// on slashing tx corresponding to unbonding tx submitted to babylon
// the order of sigs should respect the order of validators
// of the corresponding delegation
repeated bytes slashing_unbonding_tx_sigs = 6;
}
// MsgAddCovenantSigResponse is the response for MsgAddCovenantSig
message MsgAddCovenantSigResponse {}
// MsgAddCovenantSigsResponse is the response for MsgAddCovenantSigs
message MsgAddCovenantSigsResponse {}


// MsgBTCUndelegate is the message for handling signature on unbonding tx
// from its delegator. This signature effectively proves that the delegator
// wants to unbond this BTC delegation
message MsgBTCUndelegate {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1;
// staking_tx_hash is the hash of the staking tx.
// It uniquely identifies a BTC delegation
string staking_tx_hash = 2;
// unbonding_tx_sig is the signature of the staker on the unbonding tx submitted to babylon
// the signature follows encoding in BIP-340 spec
bytes unbonding_tx_sig = 3 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
}
// MsgBTCUndelegateResponse is the response for MsgBTCUndelegate
message MsgBTCUndelegateResponse {}

// MsgUpdateParams defines a message for updating btcstaking module parameters.
message MsgUpdateParams {
Expand All @@ -147,25 +162,3 @@ message MsgUpdateParams {

// MsgUpdateParamsResponse is the response to the MsgUpdateParams message.
message MsgUpdateParamsResponse {}

// MsgAddCovenantUnbondingSigs is the message for handling a signature from covenant
message MsgAddCovenantUnbondingSigs {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1;
// pk is the BTC public key of the covenant member
bytes pk = 2 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340PubKey" ];
// staking_tx_hash is the hash of the staking tx.
// (val_pk, del_pk, staking_tx_hash) uniquely identifies a BTC delegation
string staking_tx_hash = 3;
// unbonding_tx_sig is the signature of the covenant on the unbonding tx submitted to babylon
// the signature follows encoding in BIP-340 spec
bytes unbonding_tx_sig = 4 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340Signature" ];
// slashing_unbonding_tx_sigs is a list of adaptor signatures of the covenant
// on slashing tx corresponding to unbonding tx submitted to babylon
// the order of sigs should respect the order of validators
// of the corresponding delegation
repeated bytes slashing_unbonding_tx_sigs = 5;
}
// MsgAddCovenantSigResponse is the response for MsgAddCovenantSig
message MsgAddCovenantUnbondingSigsResponse {}
Loading

0 comments on commit 1dfc9c8

Please sign in to comment.