forked from 0xMiden/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(pswap): follow-ups for #3000 (AssetAmount + NonZeroU32, parsing, MASM asserts, file split, zero-amount fix) #4
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
Open
VAIBHAVJINDAL3012
wants to merge
14
commits into
next
Choose a base branch
from
vaibhav/pswap-refactor
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8d78bf
refactor(pswap): switch public APIs to AssetAmount and NonZeroU32
VAIBHAVJINDAL3012 cf8fee4
refactor(pswap): harden PswapNoteAttachment parsing
VAIBHAVJINDAL3012 a29e336
feat(pswap.masm): assert num_words==1 and depth fits in u32 in get_cu…
VAIBHAVJINDAL3012 54d07fa
refactor(pswap): split into submodule, introduce OrderId, expose Asse…
VAIBHAVJINDAL3012 a1b07eb
fix(pswap): reject zero offered/requested amounts in PswapNote::build
VAIBHAVJINDAL3012 6bafbf2
fix(pswap): reject wrong-faucet fill assets in execute; pin reconstru…
VAIBHAVJINDAL3012 259c048
chore(pswap): apply nightly rustfmt to follow-up changes
VAIBHAVJINDAL3012 0565c0f
review(pswap): apply PR feedback on docs, types, and panic surface
VAIBHAVJINDAL3012 ca43a6f
fix(pswap): remove .expect on NoteAssets::new in From<PswapNote> for …
VAIBHAVJINDAL3012 420bc00
review(pswap): take Option<AssetAmount> in execute; misc cleanups
VAIBHAVJINDAL3012 5ccde28
docs(pswap): refresh execute_full_fill doc to use new param names
VAIBHAVJINDAL3012 0682994
refactor(pswap): script() and script_root() return Result instead of …
VAIBHAVJINDAL3012 157eef5
docs(pswap): expand SAFETY comments on the two unreachable!() sites
VAIBHAVJINDAL3012 c816401
simplify(pswap): use .unwrap() instead of .unwrap_or_else(|_| unreach…
VAIBHAVJINDAL3012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ const EXEC_AMT_REQUESTED_NOTE_FILL = 9 | |
| # write the word at PARENT_ATTACHMENT_PTR, read back only the depth at DEPTH_OFFSET. | ||
| const PARENT_ATTACHMENT_PTR = 0 | ||
| const PARENT_ATTACHMENT_DEPTH_OFFSET = 2 | ||
| const PSWAP_ATTACHMENT_NUM_WORDS = 1 | ||
|
|
||
| # ERRORS | ||
| # ================================================================================================= | ||
|
|
@@ -106,6 +107,8 @@ const ERR_PSWAP_FILL_EXCEEDS_REQUESTED="PSWAP fill amount exceeds requested amou | |
| const ERR_PSWAP_FILL_SUM_OVERFLOW="PSWAP account_fill + note_fill overflows u64" | ||
| const ERR_PSWAP_NOT_VALID_ASSET_AMOUNT="PSWAP computed amount exceeds max fungible asset amount" | ||
| const ERR_PSWAP_PAYOUT_OVERFLOW="PSWAP payout quotient does not fit in u64" | ||
| const ERR_PSWAP_ATTACHMENT_WRONG_NUM_WORDS="PSWAP attachment must encode exactly one word" | ||
| const ERR_PSWAP_ATTACHMENT_DEPTH_NOT_U32="PSWAP attachment depth must fit in u32" | ||
|
|
||
| # U64 VALIDATION | ||
| # ================================================================================================= | ||
|
|
@@ -493,9 +496,13 @@ proc get_order_id | |
| end | ||
|
|
||
| #! Returns current_depth = parent_depth + 1, where parent_depth is the depth carried in the | ||
| #! consumed PSWAP note's PswapAttachment word at offset PARENT_ATTACHMENT_DEPTH_OFFSET if such an | ||
| #! attachment exists, or 0 if not (i.e., the parent is the original PSWAP, with scheme none() | ||
| #! or NetworkAccountTarget). | ||
| #! consumed PSWAP note's PswapAttachment word at offset PARENT_ATTACHMENT_DEPTH_OFFSET if such | ||
| #! an attachment exists, or 0 if not. | ||
| #! | ||
| #! The initial (depth-0) PSWAP carries no PSWAP_ATTACHMENT_SCHEME attachment; only payback P2IDs | ||
| #! and remainder PSWAPs do. So `is_found = false` here means we are consuming the original PSWAP | ||
| #! (or one carrying only an unrelated scheme like NetworkAccountTarget) and the next round is | ||
| #! depth 1. | ||
| #! | ||
| #! Inputs: [] | ||
| #! Outputs: [current_depth] | ||
|
|
@@ -514,11 +521,17 @@ proc get_current_depth | |
| exec.active_note::write_attachment_to_memory | ||
| # => [num_words] | ||
|
|
||
| drop | ||
| eq.PSWAP_ATTACHMENT_NUM_WORDS | ||
| assert.err=ERR_PSWAP_ATTACHMENT_WRONG_NUM_WORDS | ||
| # => [] | ||
|
|
||
| loc_load.PARENT_ATTACHMENT_DEPTH_OFFSET | ||
| # => [parent_depth] | ||
| dup u32split drop | ||
| # => [hi, parent_depth] | ||
|
|
||
| assertz.err=ERR_PSWAP_ATTACHMENT_DEPTH_NOT_U32 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line after # => |
||
| # => [parent_depth] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this long comment |
||
| else | ||
| drop push.0 | ||
| # => [0] | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attachment-length guard runs after the unsafe write.
write_attachment_to_memoryhas already copied the payload into a 4-local buffer beforenum_words == 1is asserted, so a forged multi-word PSWAP attachment can still clobber adjacent local memory and only then fail. If there is no length-only probe, this needs a scratch region sized for the maximum attachment length or another pre-write bound check; the current check does not provide the protection described in the comment.🤖 Prompt for AI Agents