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: validate stacks fees #1430

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AshtonStephens
Copy link
Contributor

@AshtonStephens AshtonStephens commented Feb 24, 2025

Description

Closes #1439

This PR is from another PR (#1392) that got split up to separate Bitcoin and Stacks behavior.

Changes

  • Adds a configuration parameter to the signer that prevents the signer from signing Stacks transactions that exceed that fee.
  • Adds tests that ensure the configuration and fee enforcement work.

Testing Information

unit and integration tests

Checklist:

  • I have performed a self-review of my code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@AshtonStephens AshtonStephens marked this pull request as ready for review February 24, 2025 12:57
@AshtonStephens
Copy link
Contributor Author

Only adding Mateo and Daniel because you two were the active reviewers of #1392

@AshtonStephens
Copy link
Contributor Author

Existing comments on this code can be found in the original PR of which this is half:

@AshtonStephens AshtonStephens self-assigned this Feb 24, 2025
@cylewitruk
Copy link
Member

This LGTM, but I'll let @djordon or @matteojug approve since I didn't spend much time on the previous PR.

Copy link
Collaborator

@djordon djordon left a comment

Choose a reason for hiding this comment

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

Largely looks good. We need to get those child tickets sorted out. Also, we need to figure out when to update the immunefi branch.

Comment on lines +1014 to +1023
#[test]
fn zero_values_for_nonzero_fields_fail_in_signer_config() {
fn test_one(field: &str) {
clear_env();
std::env::set_var(format!("SIGNER_SIGNER__{}", field.to_uppercase()), "0");
let _ = Settings::new_from_default_config()
.expect_err(&format!("Value for {field} must be non zero"));
}
test_one("stacks_fees_max_ustx");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should combine this test with the one below to something like this

#[test_case("dkg_max_duration" ; "dkg_max_duration")]
#[test_case("bitcoin_presign_request_max_duration" ; "bitcoin_presign_request_max_duration")]
#[test_case("signer_round_max_duration" ; "signer_round_max_duration")]
#[test_case("stacks_fees_max_ustx" ; "stacks_fees_max_ustx")]
fn zero_values_for_nonzero_fields_fail_in_signer_config(field: &str) {
    clear_env();

    std::env::set_var(format!("SIGNER_SIGNER__{}", field.to_uppercase()), "0");

    Settings::new_from_default_config()
        .expect_err("value for must be non zero");
}

You'll probably need to add use test_case::test_case near the top of the tests module.

#
# Required: false
# Environment: SIGNER_SIGNER__STACKS_FEES_MAX_USTX
stacks_fees_max_ustx = 1500000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this stay commented, since we don't want to give the impression that signers should set it unless they need to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not even sure we want this block here, we usually don't add the ones with a default we may want to "silently" change in this file (not even commented out)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, let's remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed everywhere.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well we want it in the default.toml, just not in the mainnet or devenv ones.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, you can keep it in the devenv one too, just not the mainnet one.

Comment on lines 174 to 176
# The maximum fee in microSTX that a signer will accept for a Stacks transaction.
# If the coordinator suggests a fee higher than this value for a transaction the
# signer will reject it.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should mention that this value must be greater than zero.

#
# Required: false
# Environment: SIGNER_SIGNER__STACKS_FEES_MAX_USTX
stacks_fees_max_ustx = 1500000
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not even sure we want this block here, we usually don't add the ones with a default we may want to "silently" change in this file (not even commented out)

@djordon djordon changed the title Add configurable stacks fee cap feat: validate stacks fee cap Feb 26, 2025
@djordon djordon changed the title feat: validate stacks fee cap feat: validate stacks fees Feb 26, 2025
@djordon djordon mentioned this pull request Feb 26, 2025
6 tasks
@djordon djordon self-assigned this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

[Bug]: Validate the coordinator proposed stacks fees
4 participants