Skip to content

Commit

Permalink
✨ Adds a means to bypass fixed addresses for LibMulticaller (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: 3commascapital <[email protected]>
  • Loading branch information
3commascapital and 3commascapital authored Apr 8, 2024
1 parent d11f6b7 commit 0f94bba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 52 deletions.
42 changes: 21 additions & 21 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
MulticallerTest:testMultiCallerWithSignerIncrementNonceSalt(uint256) (runs: 256, μ: 83320, ~: 82376)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSaltWithERC1271(uint256) (runs: 256, μ: 614873, ~: 614814)
MulticallerTest:testMulticallerCdFallback(string) (runs: 256, μ: 295907, ~: 281868)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSalt(uint256) (runs: 256, μ: 80096, ~: 82389)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSaltWithERC1271(uint256) (runs: 256, μ: 614013, ~: 614058)
MulticallerTest:testMulticallerCdFallback(string) (runs: 256, μ: 305244, ~: 301384)
MulticallerTest:testMulticallerForwardsMessageValue() (gas: 214013)
MulticallerTest:testMulticallerGetNames() (gas: 147637)
MulticallerTest:testMulticallerReentrancyGuard() (gas: 19980)
MulticallerTest:testMulticallerRefund(uint256) (runs: 256, μ: 170012, ~: 172026)
MulticallerTest:testMulticallerReentrancyGuard() (gas: 18392)
MulticallerTest:testMulticallerRefund(uint256) (runs: 256, μ: 169611, ~: 171890)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded() (gas: 122173)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(string,string,uint256) (runs: 256, μ: 506602, ~: 531965)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(string,string,uint256) (runs: 256, μ: 507252, ~: 500013)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(uint256,uint256,uint256,uint256) (runs: 256, μ: 122252, ~: 122252)
MulticallerTest:testMulticallerRevertWithCustomError() (gas: 35485)
MulticallerTest:testMulticallerRevertWithMessage() (gas: 38244)
MulticallerTest:testMulticallerRevertWithMessage(string) (runs: 256, μ: 38922, ~: 38644)
MulticallerTest:testMulticallerRevertWithNothing() (gas: 35306)
MulticallerTest:testMulticallerSenderDoesNotRevertWithoutMulticallerDeployed() (gas: 3423)
MulticallerTest:testMulticallerTargetGetMulticallerSender() (gas: 27448)
MulticallerTest:testMulticallerRevertWithCustomError() (gas: 32065)
MulticallerTest:testMulticallerRevertWithMessage() (gas: 34815)
MulticallerTest:testMulticallerRevertWithMessage(string) (runs: 256, μ: 35677, ~: 35747)
MulticallerTest:testMulticallerRevertWithNothing() (gas: 31886)
MulticallerTest:testMulticallerSenderDoesNotRevertWithoutMulticallerDeployed() (gas: 3463)
MulticallerTest:testMulticallerTargetGetMulticallerSender() (gas: 27523)
MulticallerTest:testMulticallerWithNoData() (gas: 16213)
MulticallerTest:testMulticallerWithSigner(uint256) (runs: 256, μ: 130354, ~: 119358)
MulticallerTest:testMulticallerWithSigner(uint256) (runs: 256, μ: 130160, ~: 119724)
MulticallerTest:testMulticallerWithSignerEIP712Domain() (gas: 12375)
MulticallerTest:testMulticallerWithSignerGetMulticallerSigner() (gas: 136389)
MulticallerTest:testMulticallerWithSignerInvalidateNonces(uint256) (runs: 256, μ: 80313, ~: 79643)
MulticallerTest:testMulticallerWithSignerInvalidateNoncesWithERC1271(uint256) (runs: 256, μ: 616631, ~: 616541)
MulticallerTest:testMulticallerWithSignerGetMulticallerSigner() (gas: 136504)
MulticallerTest:testMulticallerWithSignerInvalidateNonces(uint256) (runs: 256, μ: 81303, ~: 79648)
MulticallerTest:testMulticallerWithSignerInvalidateNoncesWithERC1271(uint256) (runs: 256, μ: 615724, ~: 616377)
MulticallerTest:testMulticallerWithSignerNonPayableFunctions() (gas: 48884)
MulticallerTest:testMulticallerWithSignerReentrancyGuard() (gas: 124909)
MulticallerTest:testMulticallerWithSignerRevert() (gas: 206240)
MulticallerTest:testMulticallerWithSignerWithERC1271(uint256) (runs: 256, μ: 657836, ~: 651346)
MulticallerTest:testMulticallerWithSignerWithNoData() (gas: 130147)
MulticallerTest:testMulticallerWithSignerReentrancyGuard() (gas: 123271)
MulticallerTest:testMulticallerWithSignerRevert() (gas: 200311)
MulticallerTest:testMulticallerWithSignerWithERC1271(uint256) (runs: 256, μ: 659458, ~: 651359)
MulticallerTest:testMulticallerWithSignerWithNoData() (gas: 128470)
MulticallerTest:testNastyCalldataRevert() (gas: 3420)
MulticallerTest:testOffsetTrick(uint256,uint256,uint256) (runs: 256, μ: 571, ~: 571)
MulticallerTest:test__codesize() (gas: 50276)
MulticallerTest:test__codesize() (gas: 50297)
TestPlus:test__codesize() (gas: 1102)
52 changes: 21 additions & 31 deletions src/LibMulticaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,14 @@ library LibMulticaller {
* @dev Returns the caller of `aggregateWithSender` on `MULTICALLER_WITH_SENDER`.
*/
function multicallerSender() internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x00)
if iszero(staticcall(gas(), MULTICALLER_WITH_SENDER, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
result := mload(0x00)
}
return multicallerGetAt(MULTICALLER_WITH_SENDER);
}

/**
* @dev Returns the signer of `aggregateWithSigner` on `MULTICALLER_WITH_SIGNER`.
*/
function multicallerSigner() internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x00)
if iszero(staticcall(gas(), MULTICALLER_WITH_SIGNER, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
result := mload(0x00)
}
return multicallerGetAt(MULTICALLER_WITH_SIGNER);
}

/**
Expand All @@ -66,31 +52,35 @@ library LibMulticaller {
* Otherwise, returns `msg.sender`.
*/
function sender() internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, caller())
let withSender := MULTICALLER_WITH_SENDER
if eq(caller(), withSender) {
if iszero(staticcall(gas(), withSender, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
result := mload(0x00)
}
return getAt(MULTICALLER_WITH_SENDER);
}

/**
* @dev Returns the caller of `aggregateWithSigner` on `MULTICALLER_WITH_SIGNER`,
* if the current context's `msg.sender` is `MULTICALLER_WITH_SIGNER`.
* Otherwise, returns `msg.sender`.
*/
function signer() internal view returns (address result) {
function signer() internal view returns (address) {
return getAt(MULTICALLER_WITH_SIGNER);
}

function multicallerGetAt(address loc) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x00)
if iszero(staticcall(gas(), loc, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
result := mload(0x00)
}
}

function getAt(address loc) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, caller())
let withSigner := MULTICALLER_WITH_SIGNER
if eq(caller(), withSigner) {
if iszero(staticcall(gas(), withSigner, codesize(), 0x00, 0x00, 0x20)) {
if eq(caller(), loc) {
if iszero(staticcall(gas(), loc, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
Expand Down

0 comments on commit 0f94bba

Please sign in to comment.