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

staking: verify staking/slashing tx relationship in staking requests #46

Merged
merged 18 commits into from
Sep 5, 2024

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Aug 28, 2024

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:

  • fixing size of BTC staking contract (current it's 1.9MB)
  • making all tests use corresponding parameters in datagen

@maurolacy maurolacy force-pushed the main branch 2 times, most recently from ff1cb01 to 8cf2f3f Compare August 29, 2024 06:50
@maurolacy maurolacy force-pushed the main branch 2 times, most recently from 2d71351 to 94967db Compare August 29, 2024 07:00
@SebastianElvis
Copy link
Member Author

SebastianElvis commented Sep 3, 2024

Some debugging on the contract size: the contract size bloats due to taproot script utilities in Bitcoin library, specifically two things:

  • Usage of TaprootBuilder
  • Usage of p2tr

This is further due to that the process involves secp256k1 operations which are all implemented in C++. That's also the reason why twiggy shows that the dominator is data not some code paths.

Now trying to replace them with something else
UPDATE: fixed in 5deb5c5 (#46)

@SebastianElvis SebastianElvis changed the base branch from main to feat/full-validation September 3, 2024 07:44
@SebastianElvis SebastianElvis changed the title full validation on BTC delegations staking: verify staking/slashing tx relationship Sep 3, 2024
@SebastianElvis SebastianElvis changed the title staking: verify staking/slashing tx relationship staking: verify staking/slashing tx relationship in staking requests Sep 3, 2024
@SebastianElvis SebastianElvis marked this pull request as ready for review September 3, 2024 07:52
Copy link
Contributor

@gusin13 gusin13 left a comment

Choose a reason for hiding this comment

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

nice work!

contracts/btc-staking/src/queries.rs Show resolved Hide resolved
contracts/btc-staking/src/staking.rs Show resolved Hide resolved
@gusin13
Copy link
Contributor

gusin13 commented Sep 3, 2024

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:

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

i'd prefer opt2 as well i.e "merge in main", qq regarding that though - why do we need to enable/disable the validation, shouldn't it always be enabled?

@SebastianElvis
Copy link
Member Author

why do we need to enable/disable the validation, shouldn't it always be enabled?

There is a trade-off between

  • the overhead / gas cost of maintaining Babylon contracts
  • the trust assumption that a consumer chain made on Babylon

If we enable all verifications, then all operations on Babylon contracts will be quite expensive, but the integration is trustless. If we disable it, operations become cheaper but the consumer side trusts information sent from Babylon.

@SebastianElvis
Copy link
Member Author

SebastianElvis commented Sep 4, 2024

i'd prefer opt2 as well i.e "merge in main"

OK make sense, updated the CI to include a new feature full-validation in BTC staking contract. Now

  • By default this full-validation is false false meaning that contracts do not perform full validations. I modified test commands / CI to enable full validation when executing unit tests.
  • I also modified Cargo.toml such that cargo optimize will output both btc_staking.wasm and btc_staking-full-validation.wasm

Please take a look to see if this approach makes sense

image

@SebastianElvis
Copy link
Member Author

SebastianElvis commented Sep 5, 2024

After some offline discussions, it's better to have a single compiled wasm binary rather than compiling all of them. This is not trivial and created #55 for now. Merging this PR

@SebastianElvis SebastianElvis merged commit 187839b into feat/full-validation Sep 5, 2024
@SebastianElvis SebastianElvis deleted the full-validation branch September 5, 2024 01:15
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.

2 participants