solmate
solmate copied to clipboard
⚡️ STL Optimizations
Description
Changes:
- Assembly reverts for #157.
- Optimized the success checks.
- Removed redundant
mstore(0x60, 0)s.
You can try copypasta the revert assembly into something like Remix and verify it.
Checklist
Ensure you completed all of the steps below before submitting your pull request:
- [x] Ran
forge snapshot? - [x] Ran
npm run lint? - [x] Ran
forge test?
Pull requests with an incomplete checklist will be thrown out.
I like it. If we can't get t11s to accept custom errors, let's use assemblored reverts.
I like it. If we can't get t11s to accept custom errors, let's use assemblored reverts.
lol i opened the issue to do reverts in asm https://github.com/Rari-Capital/solmate/issues/157
ok ok ok
The test fails for ERC1155Test::testFailFuzzSafeBatchTransferInsufficientBalance for certain rare fuzz cases.
You can try the following:
function testFailFuzzSafeBatchTransferInsufficientBalanceRareCase() public {
uint256[] memory ids = new uint256[](2);
ids[0] = 0;
ids[1] = 0;
uint256[] memory mintAmounts = new uint256[](2);
mintAmounts[0] = type(uint256).max - 2;
mintAmounts[1] = 2;
uint256[] memory transferAmounts = new uint256[](2);
transferAmounts[0] = type(uint256).max - 2;
transferAmounts[1] = 2;
testFailFuzzSafeBatchTransferInsufficientBalance(
address(0xABCD),
ids,
mintAmounts,
transferAmounts,
bytes(""),
bytes("")
);
}
The fix is to simply add a continue line in the fuzz test like so:
for (uint256 i = 0; i < minLength; i++) {
uint256 id = ids[i];
uint256 remainingMintAmountForId = type(uint256).max - userMintAmounts[from][id];
if (mintAmounts[i] == remainingMintAmountForId) continue; // To mitigate the rare case.
uint256 mintAmount = bound(mintAmounts[i], 0, remainingMintAmountForId);
uint256 transferAmount = bound(transferAmounts[i], mintAmount + 1, type(uint256).max);
normalizedIds[i] = id;
normalizedMintAmounts[i] = mintAmount;
normalizedTransferAmounts[i] = transferAmount;
userMintAmounts[from][id] += mintAmount;
}
Lemme know if you want to add this line into the fuzz test, although it is not related to the PR.
Note that we need 4 mstores for the reverts, as the scratch space may be dirty from those special tricks.
This is unreadable