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 amount with signer key authorizations #4461

Merged
merged 19 commits into from
Mar 6, 2024

Conversation

hstove
Copy link
Contributor

@hstove hstove commented Feb 29, 2024

This PR implements some of the changes discussed in #4424.

The primary change is the addition of two fields to signer key authorization messages, which are validated either via a signature or a previously stored authorization. These fields are max-amount and auth-id. max-amount reflects the maximum amount of STX that can be used in that specific stacking action. The auth-id field is used to prevent replay attacks, which would allow a stacker to go beyond max-amount over multiple transactions.

Note that stack-extend doesn't verify the amount field in the authorization, because there are no additional STX added. In that function, the primary purpose of the authorization is around the number of reward cycles being extended.

stack-increase is also changed. It now includes the signer-key, along with the signature and related fields. Along with the same signature / authorization verifications that other stacking functions have, this function also checks to ensure that the signer-key parameter matches the signer-key for each updated cycle. This means that you cannot call stack-increase if you've called stack-extend with a different signer key.

In pox-4 there is also a new map, used-signer-key-authorizations, which tracks whether a (signer-key, pox-addr, reward-cycle, period, topic, max-amount, auth-id) tuple has been used.

@hstove hstove linked an issue Feb 29, 2024 that may be closed by this pull request
Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 96.74064% with 47 lines in your changes are missing coverage. Please review.

Project coverage is 83.20%. Comparing base (bf5a833) to head (c9d8f8d).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #4461      +/-   ##
==========================================
+ Coverage   83.17%   83.20%   +0.02%     
==========================================
  Files         451      451              
  Lines      324497   325724    +1227     
  Branches      318      323       +5     
==========================================
+ Hits       269908   271015    +1107     
- Misses      54581    54701     +120     
  Partials        8        8              
Files Coverage Δ
stacks-signer/src/main.rs 36.02% <100.00%> (+3.75%) ⬆️
...kslib/src/chainstate/nakamoto/coordinator/tests.rs 99.78% <100.00%> (+<0.01%) ⬆️
stackslib/src/chainstate/stacks/boot/mod.rs 94.76% <100.00%> (+0.03%) ⬆️
...tackslib/src/chainstate/stacks/boot/pox_4_tests.rs 99.67% <100.00%> (+0.13%) ⬆️
stackslib/src/net/tests/mod.rs 96.71% <100.00%> (+0.01%) ⬆️
...net/stacks-node/src/tests/nakamoto_integrations.rs 95.10% <100.00%> (+0.03%) ⬆️
stackslib/src/util_lib/signed_structured_data.rs 97.86% <98.41%> (+0.07%) ⬆️
stacks-signer/src/cli.rs 33.07% <0.00%> (-0.53%) ⬇️
stackslib/src/chainstate/stacks/boot/pox-4.clar 4.19% <0.00%> (-0.16%) ⬇️

... and 24 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf5a833...c9d8f8d. Read the comment docs.

@hstove hstove linked an issue Mar 4, 2024 that may be closed by this pull request
@saralab saralab marked this pull request as ready for review March 4, 2024 16:30
kantai
kantai previously approved these changes Mar 4, 2024
@hstove
Copy link
Contributor Author

hstove commented Mar 4, 2024

@kantai I just re-requested review after pushing some documentation improvements

jferrant
jferrant previously approved these changes Mar 4, 2024
Copy link
Collaborator

@jferrant jferrant left a comment

Choose a reason for hiding this comment

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

Nice! :D extensive testing is great.

kantai
kantai previously approved these changes Mar 5, 2024
@hstove hstove enabled auto-merge March 5, 2024 17:38
@hstove hstove added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Mar 5, 2024
@hstove hstove dismissed stale reviews from jferrant and kantai via 3f0931d March 5, 2024 18:27
Copy link
Collaborator

@setzeus setzeus left a comment

Choose a reason for hiding this comment

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

This is some great work here @hstove, good job on the thorough tests in pox_4_tests. Couldn't see anything in pox-4 or related works that called my attention.

LGTM.

Copy link
Member

@zone117x zone117x left a comment

Choose a reason for hiding this comment

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

If it's not too much of a hassle, could you add signer key to the pox4 increase synthetic event? If that's a pain we can do in a later PR

@hstove
Copy link
Contributor Author

hstove commented Mar 6, 2024

@zone117x good call and I should have caught that earlier. Let's get this merged and I made a new ticket: #4490

Merged via the queue into next with commit ed97e10 Mar 6, 2024
2 checks passed
@hstove hstove deleted the feat/signer-key-amount-auth branch March 7, 2024 00:13
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.

Add validation for STX amount in signer key authorizations Add signer-key to *-increase pox events
5 participants