Merged
Conversation
Vectorized
commented
Sep 25, 2024
Comment on lines
+262
to
+300
| let from_ := shl(96, from) | ||
| if iszero(eq(caller(), _PERMIT2)) { | ||
| // Compute the allowance slot and load its value. | ||
| mstore(0x20, caller()) | ||
| mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) | ||
| let allowanceSlot := keccak256(0x0c, 0x34) | ||
| let allowance_ := sload(allowanceSlot) | ||
| // If the allowance is not the maximum uint256 value. | ||
| if not(allowance_) { | ||
| // Revert if the amount to be transferred exceeds the allowance. | ||
| if gt(amount, allowance_) { | ||
| mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. | ||
| revert(0x1c, 0x04) | ||
| } | ||
| // Subtract and store the updated allowance. | ||
| sstore(allowanceSlot, sub(allowance_, amount)) | ||
| } | ||
| } | ||
| // Compute the balance slot and load its value. | ||
| mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) | ||
| let fromBalanceSlot := keccak256(0x0c, 0x20) | ||
| let fromBalance := sload(fromBalanceSlot) | ||
| // Revert if insufficient balance. | ||
| if gt(amount, fromBalance) { | ||
| mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. | ||
| revert(0x1c, 0x04) | ||
| } | ||
| // Subtract and store the updated allowance. | ||
| sstore(allowanceSlot, sub(allowance_, amount)) | ||
| // Subtract and store the updated balance. | ||
| sstore(fromBalanceSlot, sub(fromBalance, amount)) | ||
| // Compute the balance slot of `to`. | ||
| mstore(0x00, to) | ||
| let toBalanceSlot := keccak256(0x0c, 0x20) | ||
| // Add and store the updated balance of `to`. | ||
| // Will not overflow because the sum of all user balances | ||
| // cannot exceed the maximum uint256 value. | ||
| sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) | ||
| // Emit the {Transfer} event. | ||
| mstore(0x20, amount) | ||
| log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) |
Owner
Author
There was a problem hiding this comment.
This chunk of code is the same for both branches, with the only exception being that for the _givePermit2InfiniteAllowance() branch, if msg.sender == _PERMIT2, the allowance logic will be skipped.
Vectorized
commented
Sep 25, 2024
Comment on lines
+384
to
+388
| // If `spender == _PERMIT2 && value != type(uint256).max`. | ||
| if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(value)))) { | ||
| mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. | ||
| revert(0x1c, 0x04) | ||
| } |
Owner
Author
There was a problem hiding this comment.
This expression's equivalence has been verified with Halmos.
Vectorized
commented
Sep 25, 2024
| let allowance_ := sload(allowanceSlot) | ||
| // If the allowance is not the maximum uint256 value. | ||
| if add(allowance_, 1) { | ||
| if not(allowance_) { |
Owner
Author
There was a problem hiding this comment.
This expression's equivalence has been verified with Halmos.
Vectorized
commented
Sep 25, 2024
Comment on lines
+189
to
+193
| // If `spender == _PERMIT2 && amount != type(uint256).max`. | ||
| if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) { | ||
| mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. | ||
| revert(0x1c, 0x04) | ||
| } |
Owner
Author
There was a problem hiding this comment.
This expression's equivalence has been verified with Halmos.
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.
Description
✨
Confidence level is 99.999%.
transferFromlogic is duplicated in a super left-curved way.Checklist
Ensure you completed all of the steps below before submitting your pull request:
forge fmt?forge test?Pull requests with an incomplete checklist will be thrown out.