fix: two-step fee recipient, checked fee arithmetic, slash floor, tok… - #151
Open
Helix-xi wants to merge 1 commit into
Open
fix: two-step fee recipient, checked fee arithmetic, slash floor, tok…#151Helix-xi wants to merge 1 commit into
Helix-xi wants to merge 1 commit into
Conversation
…en probe Closes stellar-vortex-protocol#30 - propose_fee_recipient / accept_fee_recipient two-step pattern replaces set_fee_recipient; admin proposes, new recipient must authorize to confirm, preventing silent misrouting from a typo'd address. Closes stellar-vortex-protocol#31 - fill_intent fee calculation uses checked_mul / checked_div with panic_with_error(FeeOverflow) on overflow, making the safety property visible in code rather than relying solely on Cargo.toml overflow-checks = true. Closes stellar-vortex-protocol#32 - slash_solver applies a .max(1) floor to slash_amount so a non-zero bond is never economically unpunished due to integer division rounding to zero on tiny bond values. Closes stellar-vortex-protocol#33 - add_allowed_dst_token calls token_client.decimals() as a lightweight SEP-41 interface probe before storing the allowance; non-token contracts trap and revert, surfacing the error at admin time rather than silently inside fill_intent later. Tests: add tests for all four fixes including fee overflow boundary, tiny bond slash floor via direct storage injection, non-token contract rejection, and updated admin_can_transfer_admin to use the new two-step propose/accept flow.
|
@Helix-xi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: two-step fee recipient, checked fee arithmetic, slash floor & SEP-41
token probe
Closes #30
Closes #31
Closes #32
Closes #33
──────────────────────────────────────────────────────────────────────────
Summary
This PR addresses four security and correctness issues identified in the
intent settlement contract.
──────────────────────────────────────────────────────────────────────────
#30 — Two-step fee recipient confirmation
set_fee_recipient has been replaced with a propose_fee_recipient /
accept_fee_recipient two-step pattern, mirroring the existing
transfer_admin flow. The admin proposes a new address, and that address
must explicitly authorize the handover before it becomes active. A typo'd
or unreachable address can no longer silently misroute every future
protocol fee and slash payment.
#31 — Explicit checked arithmetic for protocol fee calculation
The fee calculation in fill_intent (fill_amount * PROTOCOL_FEE_BPS /
10_000) now uses checked_mul / checked_div with a dedicated FeeOverflow
error, making the overflow-safety property visible in the code itself
rather than relying solely on the overflow-checks = true release profile
setting in Cargo.toml.
#32 — Minimum slash amount floor
slash_solver now applies .max(1) to the computed slash_amount. Without
this, a bond_amount below 10 (in the token's smallest unit) would round to
a zero slash via integer division, letting a failed fill go economically
unpunished. A non-zero bond now always produces a non-zero slash.
#33 — SEP-41 interface validation in add_allowed_dst_token
Before storing an allowlist entry, add_allowed_dst_token now calls
decimals() on the candidate address as a lightweight SEP-41 interface
probe. If the address doesn't implement the token interface the call traps
and reverts the transaction, surfacing the error at admin time rather than
silently allowing a non-token that would only fail later inside
fill_intent's transfer call.
──────────────────────────────────────────────────────────────────────────
Tests
i128::MAX / 5 + 1
exact boundary
injection to place a bond of 5, confirms slash ≥ 1
contract address, asserts failure and no storage write
real SAC passes the probe