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

hotfix: Invalid minUnbondingTime for verifying inclusion proof #289

Merged
merged 5 commits into from
Nov 22, 2024

Conversation

gitferry
Copy link
Member

The bug is caused due to setting params.MinStakingTime to the btcstaking module's keeper method VerifyInclusionProofAndGetHeight other than params.MinUnbondingTime. In the fix, we remove minUnbondingTime from the parameter list of VerifyInclusionProofAndGetHeight as it should retrieve the parameter within the method.

This PR also added comprehensive tests for VerifyInclusionProofAndGetHeight

@gitferry gitferry marked this pull request as ready for review November 21, 2024 15:53
@gitferry gitferry requested a review from a team as a code owner November 21, 2024 15:53
@gitferry gitferry requested review from KonradStaniec and RafilxTenfen and removed request for a team November 21, 2024 15:53
@RafilxTenfen
Copy link
Contributor

I am a little bit confused:

  • The getBTCDelWithParams returns the delegation in question and the versioned parameters respected to create the same delegation
  • To verify the inclusion proof we look at the last params stored at the x/btcstaking
  • To update the voting power distribution we only count for the delegation end height - the versioned parameters used at the btc delegation creation

Why do we not use the latest parameter to update the voting power dist as well?

@@ -315,7 +314,6 @@ func (ms msgServer) AddBTCDelegationInclusionProof(
btcutil.NewTx(stakingTx),
btccParams.BtcConfirmationDepth,
btcDel.StakingTime,
minUnbondingTime,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @RafilxTenfen comment is valid here - #289 (comment), ie we should pass here the params.MinUnbondingTimeBlocks from the params used when creating the delegation, not retrieve latest one from the store inside the function

@gitferry gitferry force-pushed the hotfix/set-min-staking-time-for-unbonding branch from 56f7516 to 85689cb Compare November 22, 2024 02:07
@gitferry
Copy link
Member Author

@RafilxTenfen @KonradStaniec good point, thanks guys! I forgot we are using versioned params. Fixed in 85689cb. Added a note there and relevant test

@@ -215,14 +215,14 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre
btcutil.NewTx(parsedMsg.StakingTx.Transaction),
btccParams.BtcConfirmationDepth,
uint32(parsedMsg.StakingTime),
vp.Params.MinStakingTimeBlocks,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you double check the tests ?

I have changed this back locally to vp.Params.MinStakingTimeBlocks and run the tests, and they did not catch this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's because the tests are for VerifyInclusionProofAndGetHeight. Seems we need to have a special case for testing CreateBTCDelegation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In d729190 I added a happy case to TestDoNotAllowDelegationWithoutFinalityProvider so that if you change vp.Params.MinStakingTimeBlocks, the test won't pass. But I don't think it's comprehensive enough. We can create an issue to add comprehensive test for CreateBTCDelegation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed that we don't have a validation rule to ensure minStakingTime > minUnbondingTime in params. I think this rule is important. Otherwise, the verification will never pass if the user choose to stake with minStakingTime:

	// ensure staking tx's timelock has more than unbonding BTC blocks left
	if btcTip.Height+minUnbondingTime >= endHeight {
		return nil, types.ErrInvalidStakingTx.
			Wrapf("staking tx's timelock has no more than unbonding(=%d) blocks left", minUnbondingTime)
	}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I don't think it's comprehensive enough. We can create an issue to add comprehensive test for CreateBTCDelegation

Sure, lets create issue for this 👍

@gitferry gitferry merged commit 07dc0d1 into main Nov 22, 2024
19 checks passed
@gitferry gitferry deleted the hotfix/set-min-staking-time-for-unbonding branch November 22, 2024 05:18
gitferry added a commit that referenced this pull request Nov 22, 2024
The bug is caused due to setting `params.MinStakingTime` to the
btcstaking module's keeper method `VerifyInclusionProofAndGetHeight`
other than `params.MinUnbondingTime`. In the fix, we remove
`minUnbondingTime` from the parameter list of
`VerifyInclusionProofAndGetHeight` as it should retrieve the parameter
within the method.

This PR also added comprehensive tests for
`VerifyInclusionProofAndGetHeight`
gitferry added a commit that referenced this pull request Nov 22, 2024
…289) (#290)

The bug is caused due to setting `params.MinStakingTime` to the
btcstaking module's keeper method `VerifyInclusionProofAndGetHeight`
other than `params.MinUnbondingTime`. In the fix, we remove
`minUnbondingTime` from the parameter list of
`VerifyInclusionProofAndGetHeight` as it should retrieve the parameter
within the method.

This PR also added comprehensive tests for
`VerifyInclusionProofAndGetHeight`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants