Skip to content

Commit

Permalink
feat(multicall): prevent double initiation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 24, 2023
1 parent 27629bc commit 828405a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BaseBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract contract BaseBundler is IMulticall {
/// @dev Locks the initiator so that the sender can uniquely be identified in callbacks.
/// @dev All functions delegatecalled must be `payable` if `msg.value` is non-zero.
function multicall(bytes[] memory data) external payable {
require(_initiator == UNSET_INITIATOR, ErrorsLib.INITIATED);

_initiator = msg.sender;

_multicall(data);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pragma solidity ^0.8.0;
library ErrorsLib {
/* STANDARD BUNDLERS */

/// @dev Thrown when a multicall is attempted while the bundler in an initiated execution context.
string internal constant INITIATED = "initiated";

/// @dev Thrown when a call is attempted while the bundler is not in an initiated execution context.
string internal constant UNINITIATED = "uninitiated";

Expand Down
27 changes: 27 additions & 0 deletions test/forge/BaseBundlerLocalTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {ErrorsLib} from "src/libraries/ErrorsLib.sol";

import "src/mocks/bundlers/BaseBundlerMock.sol";

import "./helpers/LocalTest.sol";

contract BaseBundlerLocalTest is LocalTest {
function setUp() public override {
super.setUp();

bundler = new BaseBundlerMock();
}

function testMulticallEmpty() public {
bundler.multicall(bundle);
}

function testNestedMulticall() public {
bundle.push(abi.encodeCall(BaseBundler.multicall, (callbackBundle)));

vm.expectRevert(bytes(ErrorsLib.INITIATED));
bundler.multicall(bundle);
}
}

0 comments on commit 828405a

Please sign in to comment.