Skip to content

Commit

Permalink
fixes min unbonding time validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Nov 26, 2024
1 parent cc6d93f commit 9269d3b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 31 deletions.
10 changes: 4 additions & 6 deletions covenant/covenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ func (ce *CovenantEmulator) AddCovenantSignatures(btcDels []*types.Delegation) (
continue
}

// 3. check unbonding time (staking time from unbonding tx) is larger than min unbonding time
// which is larger value from:
// - MinUnbondingTime
// - CheckpointFinalizationTimeout
// 3. check unbonding time (staking time from unbonding tx) is larger or equal
// to the minimum unbonding time in Babylon node parameters
unbondingTime := btcDel.UnbondingTime
minUnbondingTime := params.MinimumUnbondingTime()
if uint32(unbondingTime) <= minUnbondingTime {
minUnbondingTime := params.MinUnbondingTime
if uint32(unbondingTime) < minUnbondingTime {
ce.logger.Error("invalid unbonding time",
zap.Uint32("min_unbonding_time", minUnbondingTime),
zap.Uint16("got_unbonding_time", unbondingTime),
Expand Down
2 changes: 1 addition & 1 deletion covenant/covenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func FuzzAddCovenantSig(f *testing.F) {
require.NoError(t, err)
stakingTimeBlocks := uint32(testutil.RandRange(r, int(params.MinStakingTime), int(params.MaxStakingTime)))
stakingValue := int64(testutil.RandRange(r, int(params.MinStakingValue), int(params.MaxStakingValue)))
unbondingTime := uint16(params.MinimumUnbondingTime()) + 1
unbondingTime := uint16(params.MinUnbondingTime)
fpNum := datagen.RandomInt(r, 5) + 1
fpPks := testutil.GenBtcPublicKeys(r, t, int(fpNum))
testInfo := datagen.GenBTCStakingSlashingInfo(
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ require (
cosmossdk.io/math v1.4.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v0.17.1
// TODO: Release covenant-signer
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.0.0-20241122072853-f24b47aaa46b
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.1.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.17.1 h1:lyWGdR7B49qDw5pllLyTW/HAM5uQWXXPZefjFzy/Xy0=
github.com/babylonlabs-io/babylon v0.17.1/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.0.0-20241122072853-f24b47aaa46b h1:/v0YgkWITwFArI6/ovU1QyfbeGaE8GiojmY+z/rTdq8=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.0.0-20241122072853-f24b47aaa46b/go.mod h1:9lAyEcdpfS21bMLMEa8WjTyLVfwHJABRh5TmoxC9LKU=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.1.0 h1:3xzJyieVpYrv3io7C7nC7muCZQHq5DsWpmibPWNuxSA=
github.com/babylonlabs-io/covenant-emulator/covenant-signer v0.1.0/go.mod h1:9lAyEcdpfS21bMLMEa8WjTyLVfwHJABRh5TmoxC9LKU=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
3 changes: 3 additions & 0 deletions itest/babylon_node_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func NewBabylonNodeHandler(t *testing.T, covenantPk *types.BIP340PubKey) *Babylo
"--additional-sender-account",
"--min-staking-time-blocks=100",
"--min-staking-amount-sat=10000",
// default checkpoint finalization timeout is 20, so we set min unbonding time
// to be 1 block more
"--min-unbonding-time=21",
fmt.Sprintf("--slashing-pk-script=%s", hex.EncodeToString(pkScript)),
fmt.Sprintf("--covenant-pks=%s", covenantPk.MarshalHex()),
"--covenant-quorum=1",
Expand Down
2 changes: 1 addition & 1 deletion itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (tm *TestManager) InsertBTCDelegation(
delBtcPrivKey, delBtcPubKey, err := datagen.GenRandomBTCKeyPair(r)
require.NoError(t, err)

unbondingTime := uint16(tm.StakingParams.MinimumUnbondingTime()) + 1
unbondingTime := uint16(tm.StakingParams.MinUnbondingTime)
testStakingInfo := testutil.GenBTCStakingSlashingInfo(
r,
t,
Expand Down
6 changes: 3 additions & 3 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.1

toolchain go1.23.3

require github.com/babylonlabs-io/babylon v0.16.0
require github.com/babylonlabs-io/babylon v0.17.1

require (
cloud.google.com/go v0.112.1 // indirect
Expand All @@ -18,7 +18,7 @@ require (
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/math v1.4.0 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/tools/confix v0.1.2 // indirect
cosmossdk.io/x/circuit v0.1.1 // indirect
Expand Down Expand Up @@ -56,7 +56,7 @@ require (
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.14 // indirect
github.com/cometbft/cometbft v0.38.15 // indirect
github.com/cometbft/cometbft-db v0.15.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
cosmossdk.io/tools/confix v0.1.2 h1:2hoM1oFCNisd0ltSAAZw2i4ponARPmlhuNu3yy0VwI4=
Expand Down Expand Up @@ -264,8 +264,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.16.0 h1:SwCBwQLC3jRrvBR+jGzfUNstaCvzH1Mu6PTqQ6at+E0=
github.com/babylonlabs-io/babylon v0.16.0/go.mod h1:wEbfZ6NS/mDRP1ina17WB/4oNtpkFL9Z97bp8Ar6okQ=
github.com/babylonlabs-io/babylon v0.17.1 h1:lyWGdR7B49qDw5pllLyTW/HAM5uQWXXPZefjFzy/Xy0=
github.com/babylonlabs-io/babylon v0.17.1/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -362,8 +362,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/cometbft/cometbft v0.38.14 h1:ketYsx8uNLSm32GAMbm98SCSNTQ7Ek7VoZonSto+F/A=
github.com/cometbft/cometbft v0.38.14/go.mod h1:xdfvFic9BHPd/MXJZVRH79XK0iLLOkiMw3ynYNhuulk=
github.com/cometbft/cometbft v0.38.15 h1:5veFd8k1uXM27PBg9sMO3hAfRJ3vbh4OmmLf6cVrqXg=
github.com/cometbft/cometbft v0.38.15/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ=
github.com/cometbft/cometbft-db v0.15.0 h1:VLtsRt8udD4jHCyjvrsTBpgz83qne5hnL245AcPJVRk=
github.com/cometbft/cometbft-db v0.15.0/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
Expand Down
10 changes: 0 additions & 10 deletions types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,3 @@ type StakingParams struct {
// Maximum staking value required by babylon
MaxStakingValue btcutil.Amount
}

// MinimumUnbondingTime returns the minimum unbonding time. It is the bigger value from:
// - MinUnbondingTime
// - CheckpointFinalizationTimeout
func (p *StakingParams) MinimumUnbondingTime() uint32 {
return sdkmath.Max[uint32](
p.MinUnbondingTime,
p.FinalizationTimeoutBlocks,
)
}

0 comments on commit 9269d3b

Please sign in to comment.