-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: different publishers for sequencer and prover feat: sequencer publisher uses forwarder contract
- Loading branch information
1 parent
1c7d208
commit 02060aa
Showing
67 changed files
with
2,834 additions
and
2,081 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
import {Ownable} from "@oz/access/Ownable.sol"; | ||
import {Address} from "@oz/utils/Address.sol"; | ||
import {IForwarder} from "./interfaces/IForwarder.sol"; | ||
|
||
contract Forwarder is Ownable, IForwarder { | ||
using Address for address; | ||
|
||
constructor(address __owner) Ownable(__owner) {} | ||
|
||
function forward(address[] calldata _to, bytes[] calldata _data) external override onlyOwner { | ||
require( | ||
_to.length == _data.length, IForwarder.ForwarderLengthMismatch(_to.length, _data.length) | ||
); | ||
for (uint256 i = 0; i < _to.length; i++) { | ||
_to[i].functionCall(_data[i]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
interface IForwarder { | ||
error ForwarderLengthMismatch(uint256 toLength, uint256 dataLength); // 3a2aeb4d | ||
|
||
function forward(address[] calldata _to, bytes[] calldata _data) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {Forwarder} from "../src/periphery/Forwarder.sol"; | ||
import {IForwarder} from "../src/periphery/interfaces/IForwarder.sol"; | ||
import {TestERC20} from "@aztec/mock/TestERC20.sol"; | ||
import {Ownable} from "@oz/access/Ownable.sol"; | ||
// solhint-disable comprehensive-interface | ||
|
||
contract ForwarderTest is Test { | ||
Forwarder public forwarder; | ||
TestERC20 public token1; | ||
TestERC20 public token2; | ||
address public owner; | ||
address public user; | ||
|
||
function setUp() public { | ||
owner = makeAddr("owner"); | ||
user = makeAddr("user"); | ||
|
||
vm.prank(owner); | ||
forwarder = new Forwarder(owner); | ||
|
||
token1 = new TestERC20("Token1", "TK1", address(forwarder)); | ||
token2 = new TestERC20("Token2", "TK2", address(forwarder)); | ||
} | ||
|
||
function testForward() public { | ||
// Setup test data | ||
address[] memory targets = new address[](2); | ||
targets[0] = address(token1); | ||
targets[1] = address(token2); | ||
|
||
bytes[] memory data = new bytes[](2); | ||
data[0] = abi.encodeCall(TestERC20.mint, (address(this), 100)); | ||
data[1] = abi.encodeCall(TestERC20.mint, (address(this), 200)); | ||
|
||
// Execute forward call | ||
vm.prank(owner); | ||
forwarder.forward(targets, data); | ||
|
||
// Verify results | ||
assertEq(token1.balanceOf(address(this)), 100); | ||
assertEq(token2.balanceOf(address(this)), 200); | ||
} | ||
|
||
function testRevertWhenNotOwner(address _user) public { | ||
address[] memory targets = new address[](1); | ||
bytes[] memory data = new bytes[](1); | ||
|
||
vm.assume(_user != owner); | ||
vm.prank(_user); | ||
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, _user)); | ||
forwarder.forward(targets, data); | ||
} | ||
|
||
function testRevertWhenLengthMismatch() public { | ||
address[] memory targets = new address[](2); | ||
bytes[] memory data = new bytes[](1); | ||
|
||
vm.prank(owner); | ||
vm.expectRevert(abi.encodeWithSelector(IForwarder.ForwarderLengthMismatch.selector, 2, 1)); | ||
forwarder.forward(targets, data); | ||
} | ||
|
||
function testRevertWhenCallToInvalidAddress(address _invalidAddress) public { | ||
vm.assume(_invalidAddress != address(token1)); | ||
vm.assume(_invalidAddress != address(token2)); | ||
vm.assume(_invalidAddress != address(forwarder)); | ||
|
||
address[] memory targets = new address[](1); | ||
targets[0] = _invalidAddress; | ||
|
||
bytes[] memory data = new bytes[](1); | ||
data[0] = hex"12345678"; | ||
|
||
vm.prank(owner); | ||
vm.expectRevert(); | ||
forwarder.forward(targets, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.