Skip to content

Commit

Permalink
fix proposer check
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 30, 2025
1 parent d55f386 commit ef8e92c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
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
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
58 changes: 55 additions & 3 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,16 @@ 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 {
function test_proposePreconfedBlocks_InvalidProposerParam() external {
address[] memory operators = new address[](3);
operators[0] = Bob;
operators[1] = Carol;
Expand Down Expand Up @@ -138,7 +141,56 @@ 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), "");
}

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), "");
}
}

0 comments on commit ef8e92c

Please sign in to comment.