From 2243682a749cddadacd415db9f4cdc11c94c3741 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Sat, 31 Aug 2024 07:10:30 +0000 Subject: [PATCH] Add option to override to payable --- .gas-snapshot | 22 +++++++++++----------- src/utils/Multicallable.sol | 12 ++++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 6f51bcf47..82b992772 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1040,18 +1040,18 @@ MinHeapLibTest:testMemHeapSmallestGas() (gas: 2985537) MinHeapLibTest:testMemHeapWriteAndReadFromStorage() (gas: 67756) MinHeapLibTest:testMemHeapWriteAndReadFromStorage2() (gas: 67774) MinHeapLibTest:test__codesize() (gas: 14576) -MulticallableTest:testMulticallableBenchmark() (gas: 30291) +MulticallableTest:testMulticallableBenchmark() (gas: 30286) MulticallableTest:testMulticallableOriginalBenchmark() (gas: 38715) -MulticallableTest:testMulticallablePreservesMsgSender() (gas: 11413) -MulticallableTest:testMulticallableReturnDataIsProperlyEncoded() (gas: 398368) -MulticallableTest:testMulticallableReturnDataIsProperlyEncoded(string,string,uint256) (runs: 317, μ: 250587, ~: 390621) -MulticallableTest:testMulticallableReturnDataIsProperlyEncoded(uint256,uint256,uint256,uint256) (runs: 317, μ: 249928, ~: 34427) -MulticallableTest:testMulticallableRevertWithCustomError() (gas: 11859) -MulticallableTest:testMulticallableRevertWithMessage() (gas: 13509) -MulticallableTest:testMulticallableRevertWithMessage(string) (runs: 317, μ: 14121, ~: 13970) -MulticallableTest:testMulticallableRevertWithNothing() (gas: 11766) -MulticallableTest:testMulticallableWithNoData() (gas: 6361) -MulticallableTest:test__codesize() (gas: 9857) +MulticallableTest:testMulticallablePreservesMsgSender() (gas: 11408) +MulticallableTest:testMulticallableReturnDataIsProperlyEncoded() (gas: 397972) +MulticallableTest:testMulticallableReturnDataIsProperlyEncoded(string,string,uint256) (runs: 317, μ: 234394, ~: 43539) +MulticallableTest:testMulticallableReturnDataIsProperlyEncoded(uint256,uint256,uint256,uint256) (runs: 317, μ: 245730, ~: 394794) +MulticallableTest:testMulticallableRevertWithCustomError() (gas: 11854) +MulticallableTest:testMulticallableRevertWithMessage() (gas: 13504) +MulticallableTest:testMulticallableRevertWithMessage(string) (runs: 317, μ: 14116, ~: 13965) +MulticallableTest:testMulticallableRevertWithNothing() (gas: 11761) +MulticallableTest:testMulticallableWithNoData() (gas: 6356) +MulticallableTest:test__codesize() (gas: 9855) OwnableRolesTest:testBytecodeSize() (gas: 350635) OwnableRolesTest:testGrantAndRemoveRolesDirect(address,uint256,uint256) (runs: 317, μ: 41493, ~: 42162) OwnableRolesTest:testGrantAndRevokeOrRenounceRoles(address,bool,bool,bool,uint256,uint256) (runs: 317, μ: 27815, ~: 20899) diff --git a/src/utils/Multicallable.sol b/src/utils/Multicallable.sol index 201424628..6acdf3121 100644 --- a/src/utils/Multicallable.sol +++ b/src/utils/Multicallable.sol @@ -23,12 +23,16 @@ abstract contract Multicallable { /// If any of the `delegatecall`s reverts, the entire context is reverted, /// and the error is bubbled up. /// - /// This function is deliberately made non-payable to guard against double-spending. - /// (See: https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong) - /// /// By default, this function directly returns the results and terminates the call context. /// If you need to add before and after actions to the multicall, please override this function. - function multicall(bytes[] calldata data) public virtual returns (bytes[] memory) { + function multicall(bytes[] calldata data) public payable virtual returns (bytes[] memory) { + // Revert if `msg.value` is non-zero by default to guard against double-spending. + // (See: https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong) + // + // If you really need to pass in a `msg.value`, then you will have to + // override this function and add in any relevant before and after checks. + if (msg.value != 0) revert(); + _multicallDirectReturn(_multicallInner(data)); }