⚡️ STL Optimizations#259
Conversation
|
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 #157 |
|
ok ok ok |
|
The test fails for 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 |
| and( | ||
| // Set success to whether the call reverted, if not we check it either | ||
| // returned exactly 1 (can't just be non-zero data), or had no return data. | ||
| or(eq(mload(0x00), 1), iszero(returndatasize())), |
There was a problem hiding this comment.
wait how is it safe to remove the gt(returndatasize(), 31)) check
There was a problem hiding this comment.
Before the call, we store the 4-byte selector at 0x00.
// Equivalent to `mstore(0x00, 0x0000000000000000000000000000000000000000000000000000000023b872dd)`
mstore(0x00, 0x23b872dd)Since the selector 0x23b872dd does not end with byte 0x01
(e.g. 0x11223301)…
the only way for the memory slot at 0x00 to be equal to 1 is for the call to write 0x0000000000000000000000000000000000000000000000000000000000000001 to 0x00, which gives a returndatasize() that is at least 32.
This can be applied for the other selectors too (0xa9059cbb, 0x095ea7b3).
There was a problem hiding this comment.
oh what the fuck this is genius
|
This is unreadable |
Description
Changes:
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:
forge snapshot?npm run lint?forge test?Pull requests with an incomplete checklist will be thrown out.