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

EPIC: Add full validations #7

Open
maurolacy opened this issue Jul 31, 2024 · 1 comment
Open

EPIC: Add full validations #7

maurolacy opened this issue Jul 31, 2024 · 1 comment
Labels
bug Something isn't working integration-readiness

Comments

@maurolacy
Copy link
Collaborator

@maurolacy cloned issue babylonchain/babylon-contract#84 on 2024-05-03:

After basic validations (#82), let's complete the validation logic after the original Go code.

Related to #82. Also, likely requires #76.

@SebastianElvis SebastianElvis self-assigned this Aug 23, 2024
@SebastianElvis SebastianElvis added the bug Something isn't working label Aug 26, 2024
SebastianElvis added a commit that referenced this issue Sep 5, 2024
…46)

First step of #7 

This PR adds verification on the relationship between staking/slashing
tx in staking requests using
`babylon_btcstaking::tx_verify::check_transactions`. This also involves
further refactoring of datagen library, and a bug fix in taproot pk
script generation where we mistakenly used secp256k1 FFI that bloats
contract size.

NOTE: this PR still results in a wasm contract slightly bigger than the
standard 800 KB. There are two ways to go ahead before optimisation is
in place:

1. merge it into a feature branch for full validation for now, optimise
in subsequent PRs, or
2. merge it into `main`, but before that add a Rust feature to allow to
enable/disable the full validation

I'm inclined to 2 but open to other ideas cc @maurolacy @gusin13 

---

TODOs before ready:

- [x] fixing size of BTC staking contract (current it's 1.9MB)
- [x] making all tests use corresponding parameters in
[datagen](https://github.com/babylonlabs-io/babylon-contract/blob/647b1f4f16a8b37f3d5a11a543cdb093f2d7d830/datagen/utils/btcstaking.go)
@SebastianElvis
Copy link
Member

SebastianElvis commented Sep 5, 2024

After #46 and #56, most of the reality checks are done (feature flag for lite/full version, correctness of BTC staking library, etc..).

The following includes the missing verification rules. Those will be picked up later.

Finality provider registration request

  • Verify PoP

BTC delegation request

  • Ensure staking tx is included the BTC light client
  • Ensure staking tx is k-deep
  • Ensure staking tx timelock has more than w BTC blocks left
  • Verify PoP
  • Verify covenant signatures over slashing tx
  • Ensure unbonding time is max(min_unbonding_time, w)
  • Ensure unbonding tx is spending the given staking tx
  • Ensure consistency bweteen unbonding tx and unbonding slashing tx
  • Verify staker's signature over slashing path of unbonding tx
  • Verify covenant signatures over unbonding slashing tx
  • Ensure unbonding tx fee is not too low

BTC undelegation request

  • Ensure BTC delegation is active
  • Verify staker's signature over the unbonding tx

Slashed BTC delegation

  • Ensure BTC delegation is active
  • Ensure the SK corresponds to a FP PK that the delegation restakes to

SebastianElvis added a commit that referenced this issue Sep 9, 2024
Part of #7 

This PR adds verifications on staker's signature over the slashing tx in
BTC delegation requests. This includes:

- replacing rust secp256k1 with k256 for verifying Schnorr signatures
and key pairs. This prevents bloating wasm binary size
- adding an assertion ensuring the full validation version of btc
staking contract is less than 1 MB. This checks whether rust-bitcoin
stuff bloats the contract size or not.
- verifying staker's Schnorr signature over its slashing tx in
`handle_btc_delegation` (the version with `full-validation` feature)
- fixing `datagen` to use 1st FP's secret key for generating pub rand
commit and finality sig
SebastianElvis added a commit that referenced this issue Sep 9, 2024
@SebastianElvis SebastianElvis changed the title Add full validations EPIC: Add full validations Sep 9, 2024
SebastianElvis added a commit that referenced this issue Sep 16, 2024
Part of #7 

This PR implements the full validation of unbonded/slashed BTC
delegations.
SebastianElvis added a commit that referenced this issue Sep 16, 2024
Part of #7 

This PR adds more verification rules to a newly active BTC delegation:

- ensure that all covenant signatures over {slashing, unbonding,
unbonding slashing} txs are valid
- ensure that the unbonding tx is spending the staking tx
- ensure that the unbonding tx and unbonding slashing tx are consistent
@SebastianElvis SebastianElvis removed their assignment Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working integration-readiness
Projects
None yet
Development

No branches or pull requests

2 participants