Skip to content
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

♻️ 4337 compat #27

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
MulticallerTest:testMultiCallerWithSignerIncrementNonceSalt(uint256) (runs: 256, μ: 79322, ~: 79715)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSaltWithERC1271(uint256) (runs: 256, μ: 580309, ~: 580357)
MulticallerTest:testMulticallerCdFallback(string) (runs: 256, μ: 307259, ~: 304409)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSalt(uint256) (runs: 256, μ: 80066, ~: 81872)
MulticallerTest:testMultiCallerWithSignerIncrementNonceSaltWithERC1271(uint256) (runs: 256, μ: 580304, ~: 580357)
MulticallerTest:testMulticallerCdFallback(string) (runs: 256, μ: 306501, ~: 301746)
MulticallerTest:testMulticallerForwardsMessageValue() (gas: 214013)
MulticallerTest:testMulticallerGetNames() (gas: 147637)
MulticallerTest:testMulticallerReentrancyGuard() (gas: 19980)
MulticallerTest:testMulticallerRefund(uint256) (runs: 256, μ: 169771, ~: 171995)
MulticallerTest:testMulticallerRefund(uint256) (runs: 256, μ: 169898, ~: 172026)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded() (gas: 122173)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(string,string,uint256) (runs: 256, μ: 512926, ~: 500013)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(string,string,uint256) (runs: 256, μ: 520631, ~: 527233)
MulticallerTest:testMulticallerReturnDataIsProperlyEncoded(uint256,uint256,uint256,uint256) (runs: 256, μ: 122252, ~: 122252)
MulticallerTest:testMulticallerRevertWithCustomError() (gas: 35485)
MulticallerTest:testMulticallerRevertWithMessage() (gas: 38244)
MulticallerTest:testMulticallerRevertWithMessage(string) (runs: 256, μ: 39110, ~: 39181)
MulticallerTest:testMulticallerRevertWithMessage(string) (runs: 256, μ: 39122, ~: 39181)
MulticallerTest:testMulticallerRevertWithNothing() (gas: 35306)
MulticallerTest:testMulticallerSenderDoesNotRevertWithoutMulticallerDeployed() (gas: 3423)
MulticallerTest:testMulticallerTargetGetMulticallerSender() (gas: 27448)
MulticallerTest:testMulticallerWithNoData() (gas: 16213)
MulticallerTest:testMulticallerWithSigner(uint256) (runs: 256, μ: 130308, ~: 124653)
MulticallerTest:testMulticallerWithSigner(uint256) (runs: 256, μ: 127763, ~: 118802)
MulticallerTest:testMulticallerWithSignerEIP712Domain() (gas: 12375)
MulticallerTest:testMulticallerWithSignerGetMulticallerSigner() (gas: 135610)
MulticallerTest:testMulticallerWithSignerInvalidateNonces(uint256) (runs: 256, μ: 79852, ~: 79617)
MulticallerTest:testMulticallerWithSignerInvalidateNoncesWithERC1271(uint256) (runs: 256, μ: 585389, ~: 584777)
MulticallerTest:testMulticallerWithSignerInvalidateNonces(uint256) (runs: 256, μ: 79498, ~: 77716)
MulticallerTest:testMulticallerWithSignerInvalidateNoncesWithERC1271(uint256) (runs: 256, μ: 584890, ~: 584632)
MulticallerTest:testMulticallerWithSignerNonPayableFunctions() (gas: 48884)
MulticallerTest:testMulticallerWithSignerReentrancyGuard() (gas: 124037)
MulticallerTest:testMulticallerWithSignerRevert() (gas: 203818)
MulticallerTest:testMulticallerWithSignerWithERC1271(uint256) (runs: 256, μ: 613529, ~: 601479)
MulticallerTest:testMulticallerWithSignerWithERC1271(uint256) (runs: 256, μ: 613068, ~: 601565)
MulticallerTest:testMulticallerWithSignerWithNoData() (gas: 128593)
MulticallerTest:testNastyCalldataRevert() (gas: 3420)
MulticallerTest:testOffsetTrick(uint256,uint256,uint256) (runs: 256, μ: 571, ~: 571)
MulticallerTest:test__codesize() (gas: 49539)
MulticallerTest:test__codesize() (gas: 49524)
TestPlus:test__codesize() (gas: 1102)
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Library to read the multicaller contracts.
#### `MULTICALLER`
```solidity
address internal constant MULTICALLER =
0x000000000000FddAde488c25f238b061829fE2Bf;
0x0000000000002Bdbf1Bf3279983603Ec279CC6dF;
```

The address of the multicaller contract.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ Enables "forwarding" of `msg.sender` to the contracts called.
## Deployments

- Ethereum
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://etherscan.io/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://etherscan.io/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://etherscan.io/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://etherscan.io/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Goerli
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://goerli.etherscan.io/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://goerli.etherscan.io/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://goerli.etherscan.io/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://goerli.etherscan.io/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Sepolia
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://sepolia.etherscan.io/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://sepolia.etherscan.io/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://sepolia.etherscan.io/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://sepolia.etherscan.io/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Polygon
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://polygonscan.com/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://polygonscan.com/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://polygonscan.com/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://polygonscan.com/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Mumbai
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://mumbai.polygonscan.com/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://mumbai.polygonscan.com/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://mumbai.polygonscan.com/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://mumbai.polygonscan.com/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Optimism
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://optimistic.etherscan.io/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://optimistic.etherscan.io/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://optimistic.etherscan.io/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://optimistic.etherscan.io/address/0x0000000000005e17F9eA3651537Cffda3946E0be)
- Arbitrum
- Multicaller: [`0x000000000000FddAde488c25f238b061829fE2Bf`](https://arbiscan.io/address/0x000000000000FddAde488c25f238b061829fE2Bf)
- Multicaller: [`0x0000000000002Bdbf1Bf3279983603Ec279CC6dF`](https://arbiscan.io/address/0x0000000000002Bdbf1Bf3279983603Ec279CC6dF)
- MulticallerWithSender: [`0x00000000002Fd5Aeb385D324B580FCa7c83823A0`](https://arbiscan.io/address/0x00000000002Fd5Aeb385D324B580FCa7c83823A0)
- MulticallerWithSigner: [`0x0000000000005e17F9eA3651537Cffda3946E0be`](https://arbiscan.io/address/0x0000000000005e17F9eA3651537Cffda3946E0be)

Expand Down
26 changes: 13 additions & 13 deletions src/LibMulticaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library LibMulticaller {
/**
* @dev The address of the multicaller contract.
*/
address internal constant MULTICALLER = 0x000000000000FddAde488c25f238b061829fE2Bf;
address internal constant MULTICALLER = 0x0000000000002Bdbf1Bf3279983603Ec279CC6dF;

/**
* @dev The address of the multicaller with sender contract.
Expand All @@ -39,8 +39,8 @@ library LibMulticaller {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x00)
if iszero(staticcall(gas(), MULTICALLER_WITH_SENDER, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), MULTICALLER_WITH_SENDER, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
result := mload(0x00)
}
Expand All @@ -53,8 +53,8 @@ library LibMulticaller {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x00)
if iszero(staticcall(gas(), MULTICALLER_WITH_SIGNER, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), MULTICALLER_WITH_SIGNER, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
result := mload(0x00)
}
Expand All @@ -71,8 +71,8 @@ library LibMulticaller {
mstore(0x00, caller())
let withSender := MULTICALLER_WITH_SENDER
if eq(caller(), withSender) {
if iszero(staticcall(gas(), withSender, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), withSender, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
result := mload(0x00)
Expand All @@ -90,8 +90,8 @@ library LibMulticaller {
mstore(0x00, caller())
let withSigner := MULTICALLER_WITH_SIGNER
if eq(caller(), withSigner) {
if iszero(staticcall(gas(), withSigner, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), withSigner, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
result := mload(0x00)
Expand All @@ -111,14 +111,14 @@ library LibMulticaller {
mstore(0x00, caller())
let withSender := MULTICALLER_WITH_SENDER
if eq(caller(), withSender) {
if iszero(staticcall(gas(), withSender, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), withSender, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
let withSigner := MULTICALLER_WITH_SIGNER
if eq(caller(), withSigner) {
if iszero(staticcall(gas(), withSigner, gas(), 0x00, 0x00, 0x20)) {
revert(0x00, 0x00) // For better gas estimation.
if iszero(staticcall(gas(), withSigner, codesize(), 0x00, 0x00, 0x20)) {
revert(codesize(), codesize()) // For better gas estimation.
}
}
result := mload(0x00)
Expand Down
6 changes: 4 additions & 2 deletions src/Multicaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ contract Multicaller {
// If `refundTo` is `address(1)`, replace it with the `msg.sender`.
refundTo := xor(refundTo, mul(eq(refundTo, 1), xor(refundTo, caller())))
// Transfer the ETH and check if it succeeded or not.
if iszero(call(100000, refundTo, selfbalance(), gas(), 0x00, gas(), 0x00)) {
if iszero(
call(100000, refundTo, selfbalance(), codesize(), 0x00, codesize(), 0x00)
) {
mstore(0x00, refundTo) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
// We can directly use `SELFDESTRUCT` in the contract creation.
// Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
if iszero(create(selfbalance(), 0x0b, 0x16)) {
// Coerce gas estimation to provide enough gas for the `create` above.
returndatacopy(gas(), returndatasize(), shr(20, gas()))
revert(codesize(), codesize())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MulticallerEtcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ library MulticallerEtcher {
* @dev The initcode for the multicaller.
*/
bytes internal constant MULTICALLER_INITCODE =
hex"60808060405234610016576102c2908161001c8239f35b600080fdfe60806040526004361015610015575b3661020657005b6000803560e01c63991f255f1461002c575061000e565b60803660031901126100aa5767ffffffffffffffff6004358181116100b5576100599036906004016100b9565b916024358181116100b1576100729036906004016100b9565b916044359081116100ad5761008b9036906004016100b9565b6064359690959194906001600160a01b03881688036100aa57506100ef565b80fd5b8580fd5b8480fd5b8280fd5b9181601f840112156100ea5782359167ffffffffffffffff83116100ea576020808501948460051b0101116100ea57565b600080fd5b959390949295606093871487871416156101f957869360409761016f575b505050505080610125575b5060206000526020526000f35b47156101185733811860018214021860005a81804785620186a0f1610118576000526073600b5360ff6020536016600b47f015610163575b38610118565b5a60141c3d5a3e61015d565b8794919395979160051b9384878737848601945b835188019087810182359081602080950182376000808093838a8c603f19918291010135908c8b0101355af1156101f0578287523d90523d908583013e603f601f19913d010116930196898689146101dd57509692610183565b975050505091505001923880808061010d565b503d81803e3d90fd5b633b800a463d526004601cfd5b3d356366e0daa08160e01c1461021a573d3dfd5b193d5260043d815b36811061024357600080808581305af43d82803e1561023f573d90f35b3d90fd5b8035821a92600180920193801561026057815301905b9091610222565b503d19815283820193607f90353d1a81811115610281575b16010190610259565b83810138843961027856fea2646970667358221220475c7e84428e39945ebf8b420dcd0c625dc8a74107d1248537385a34092200dd64736f6c63430008120033";
hex"60808060405234610016576102b9908161001c8239f35b600080fdfe60806040526004361015610015575b366101fd57005b6000803560e01c63991f255f1461002c575061000e565b60803660031901126100aa5767ffffffffffffffff6004358181116100b5576100599036906004016100b9565b916024358181116100b1576100729036906004016100b9565b916044359081116100ad5761008b9036906004016100b9565b6064359690959194906001600160a01b03881688036100aa57506100ef565b80fd5b8580fd5b8480fd5b8280fd5b9181601f840112156100ea5782359167ffffffffffffffff83116100ea576020808501948460051b0101116100ea57565b600080fd5b959390949295606093871487871416156101f0578693604097610166575b505050505080610125575b5060206000526020526000f35b47156101185733811860018214021860003881804785620186a0f1610118576000526073600b5360ff6020536016600b47f0156101625738610118565b3838fd5b8794919395979160051b9384878737848601945b835188019087810182359081602080950182376000808093838a8c603f19918291010135908c8b0101355af1156101e7578287523d90523d908583013e603f601f19913d010116930196898689146101d45750969261017a565b975050505091505001923880808061010d565b503d81803e3d90fd5b633b800a463d526004601cfd5b3d356366e0daa08160e01c14610211573d3dfd5b193d5260043d815b36811061023a57600080808581305af43d82803e15610236573d90f35b3d90fd5b8035821a92600180920193801561025757815301905b9091610219565b503d19815283820193607f90353d1a81811115610278575b16010190610250565b83810138843961026f56fea26469706673582212200dfa3a85cbd068a99fd4d5051615c4bde5995f9e1dd4a095bb55fc5af681c44064736f6c63430008120033";

/**
* @dev The salt for the multicaller to be deployed via
* 0age's immutable create2 factory.
*/
bytes32 internal constant MULTICALLER_CREATE2_SALT =
0x0000000000000000000000000000000000000000b7c5353a611fca026b57d5cc;
0x0000000000000000000000000000000000000000ef4834b251a91000a916248a;

/**
* @dev The initcode for the multicaller with sender.
Expand Down