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

feat: add validation for complete-deposit transactions #545

Merged
merged 18 commits into from
Sep 24, 2024

Conversation

djordon
Copy link
Contributor

@djordon djordon commented Sep 18, 2024

Description

Closes #479.

Changes

  • Change the AsContractCall::validate function to have a different signature.
  • Implement the CompleteDepositV1::validate function.
  • Added some fields to the CompleteDepositV1 struct. These new parameters should be used in the contract call once feat: check against known burn hash when completing deposit #493 gets updated and lands.
  • Fix a bunch of random typos that I spotted.

Note that when #543 gets done we'll probably want to add another integration test, but the logic introduced here should be correct and won't need much updating (famous last words).

Testing Information

This PR adds integration tests that checks for each of the failure modes in the function.

Checklist:

  • I have performed a self-review of my code

@djordon djordon added the sbtc bootstrap signer The sBTC Bootstrap Signer. label Sep 18, 2024
@djordon
Copy link
Contributor Author

djordon commented Sep 18, 2024

These sporadic errors seem to be unrelated to the changes in this PR.

@djordon djordon changed the title feat: implement validate for complete-deposit transactions feat: add validation for complete-deposit transactions Sep 18, 2024
@djordon
Copy link
Contributor Author

djordon commented Sep 19, 2024

Ugh, I forgot to check the signer bitmap. Will update tomorrow.

There is no bitmap, I'm going to bed.

Copy link
Member

@cylewitruk cylewitruk left a comment

Choose a reason for hiding this comment

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

Some suggestions and one question so far. I've still got complete_deposit.rs integration tests to go through, but will toss these up for now 👍

signer/src/stacks/contracts.rs Show resolved Hide resolved
signer/src/stacks/contracts.rs Outdated Show resolved Hide resolved
signer/src/stacks/contracts.rs Show resolved Hide resolved
signer/src/stacks/contracts.rs Show resolved Hide resolved
@@ -30,6 +30,22 @@ pub struct SignerInfo {
pub signer_public_keys: BTreeSet<PublicKey>,
}

/// Generate a set of public keys for a group of signers
pub fn generate_signer_set<R>(rng: &mut R, num_signers: usize) -> Vec<PublicKey>
Copy link
Member

Choose a reason for hiding this comment

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

[Suggestion] I might call this something more like generate_signer_set_public_keys since you're only returning the public keys, or even something like this to be able to get it from any Vec<SignerInfo>.

pub trait SignerSetInfoExt {
    fn to_public_keys(&self) -> Vec<PublicKey> {
        ...
    }
}
impl SignerSetInfoExt for Vec<SignerInfo> {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops forgot to update. Hmmm, think I'll update this function name in #555 if you don't mind.

signer/src/transaction_signer.rs Outdated Show resolved Hide resolved
Copy link
Member

@cylewitruk cylewitruk left a comment

Choose a reason for hiding this comment

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

Couple more quick comments -- still reading through it :)

let db_num = DATABASE_NUM.fetch_add(1, Ordering::SeqCst);
let pg_store = testing::storage::new_test_database(db_num, true).await;
let mut rng = rand::rngs::StdRng::seed_from_u64(51);
let signatures_required = 3;
Copy link
Member

@cylewitruk cylewitruk Sep 23, 2024

Choose a reason for hiding this comment

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

[Question] So here we've got 3 (signatures_required), which I guess is just used to get the deposit requests, and the validate() call will use 2 (default in make_complete_deposit()), does this have any bearing on the test? I guess it shouldn't as long as this is higher than the 2 in the ReqContext, but do we need to test that scenario as well? (Not sure where this value will be coming from in test/mainnet or if this is even the area of code which should account for this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It affects the test by way of affecting which deposit requests are considered "accepted". I should at the very least note that fact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I noted this better in 2773454. I'm not too happy with it, but it is fairly unimportant for these tests so I didn't change too much.

signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
Copy link
Member

@cylewitruk cylewitruk left a comment

Choose a reason for hiding this comment

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

A couple more comments but otherwise I think it looks good 🙏


// Generate the transaction and corresponding request context.
let (mut complete_deposit_tx, ctx) = make_complete_deposit(&deposit_req, &sweep_tx, &chain_tip);
// Different: Okay, let's make sure we get the deployers do not match.
Copy link
Member

Choose a reason for hiding this comment

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

deployersrecipients

let (mut complete_deposit_tx, ctx) = make_complete_deposit(&deposit_req, &sweep_tx, &chain_tip);
// Different: The amount cannot exceed the amount in the deposit
// request.
complete_deposit_tx.amount = deposit_req.amount + 1000;
Copy link
Member

Choose a reason for hiding this comment

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

always better to just use 1 in situations like this imo as it proves the logic is sensitive (i.e. in a >= vs. > scenario)

@djordon djordon merged commit 7b7a5b3 into main Sep 24, 2024
3 checks passed
@djordon djordon deleted the 479-validate-complete-deposit-sign-requests branch September 24, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sbtc bootstrap signer The sBTC Bootstrap Signer.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Feature]: Validate complete-deposit-wrapper contract calls
2 participants