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

fix(protocol): check proposer param must be msg.sender in PreconfRouter #18851

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "src/layer1/based/ITaikoInbox.sol";
/// @title IPreconfRouter
/// @custom:security-contact [email protected]
interface IPreconfRouter {
error InvalidParams();
error NotTheOperator();
error ProposerIsNotTheSender();

Expand Down
dantaik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ contract PreconfRouter is EssentialContract, IPreconfRouter {
external
returns (ITaikoInbox.BatchMetadata memory meta_)
{
// Make sure the proposer must be the msg.sender itself.
ITaikoInbox.BatchParams memory batchParams =
abi.decode(_batchParams, (ITaikoInbox.BatchParams));
require(msg.sender == batchParams.proposer, InvalidParams());

// Sender must be the selected operator for the epoch
address selectedOperator =
IPreconfWhitelist(resolve(LibStrings.B_PRECONF_WHITELIST, false)).getOperatorForEpoch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ contract InboxTest_EtherAsBond is InboxTestBase {
// function test_inbox_exceeding_ether_balance() external {
// vm.warp(1_000_000);
// vm.deal(Alice, 0.5 ether);

// uint256 depositAmount = 1 ether;

// vm.prank(Alice);
// vm.expectRevert();
// inbox.depositBond{ value: depositAmount }(depositAmount);
Expand Down
56 changes: 54 additions & 2 deletions packages/protocol/test/layer1/preconf/router/RouterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,65 @@ contract RouterTest is RouterTestBase {
// Warp to arbitrary slot in epoch 2
vm.warp(epochTwoStart + 2 * LibPreconfConstants.SECONDS_IN_SLOT);

ITaikoInbox.BatchParams memory batchParams;
batchParams.proposer = David;

// Prank as David (not the selected operator) and propose blocks
vm.prank(David);
vm.expectRevert(IPreconfRouter.NotTheOperator.selector);
router.proposePreconfedBlocks("", "", "");
router.proposePreconfedBlocks("", abi.encode(batchParams), "");
}

function test_proposePreconfedBlocks_proposerNotSender() external {
address[] memory operators = new address[](1);
operators[0] = Bob;
addOperators(operators);

// Setup mock beacon for operator selection
vm.chainId(1);
uint256 epochOneStart = LibPreconfConstants.getGenesisTimestamp(block.chainid);
// Current epoch
uint256 epochTwoStart = epochOneStart + LibPreconfConstants.SECONDS_IN_EPOCH;

MockBeaconBlockRoot mockBeacon = new MockBeaconBlockRoot();
bytes32 mockRoot = bytes32(uint256(1)); // This will select Carol

address beaconBlockRootContract = LibPreconfConstants.getBeaconBlockRootContract();
vm.etch(beaconBlockRootContract, address(mockBeacon).code);
MockBeaconBlockRoot(payable(beaconBlockRootContract)).set(
epochOneStart + LibPreconfConstants.SECONDS_IN_SLOT, mockRoot
);

// Setup block params
ITaikoInbox.BlockParams[] memory blockParams = new ITaikoInbox.BlockParams[](1);
blockParams[0] = ITaikoInbox.BlockParams({ numTransactions: 1, timeShift: 1 });

ITaikoInbox.BlobParams memory blobParams;

// Create batch params with DIFFERENT proposer than sender
ITaikoInbox.BatchParams memory params = ITaikoInbox.BatchParams({
proposer: Carol, // Set different proposer than sender (Carol)
coinbase: address(0),
parentMetaHash: bytes32(0),
anchorBlockId: 0,
anchorInput: bytes32(0),
lastBlockTimestamp: uint64(block.timestamp),
revertIfNotFirstProposal: false,
signalSlots: new bytes32[](0),
blobParams: blobParams,
blocks: blockParams
});

// Warp to arbitrary slot in epoch 2
vm.warp(epochTwoStart + 2 * LibPreconfConstants.SECONDS_IN_SLOT);

// Prank as Carol (selected operator) and propose blocks
vm.prank(Carol);
vm.expectRevert(IPreconfRouter.NotTheOperator.selector);
router.proposePreconfedBlocks("", abi.encode(params), "");
}

function test_proposePreconfedBlocks_InvalidProposerParam() external {
address[] memory operators = new address[](3);
operators[0] = Bob;
operators[1] = Carol;
Expand Down Expand Up @@ -138,7 +190,7 @@ contract RouterTest is RouterTestBase {

// Prank as Carol (selected operator) and propose blocks
vm.prank(Carol);
vm.expectRevert(IPreconfRouter.ProposerIsNotTheSender.selector);
vm.expectRevert(IPreconfRouter.InvalidParams.selector);
router.proposePreconfedBlocks("", abi.encode(params), "");
}
}