Commit 6350976a authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: prevent deposits with too small gaslimit

The deposits sent to L2 should have a gas limit that at least
covers the intrinsic gas. If the deposits do not pay that much,
then it is possible for cause resource usage on L2 without
paying for it. This is not a critical bug because the user
would still need to pay for L1 inclusion.
parent 4f54bcdb
This diff is collapsed.
This diff is collapsed.
......@@ -371,6 +371,9 @@ contract OptimismPortal is Initializable, ResourceMetering, Semver {
);
}
// Prevent depositing transactions that have too small of a gas limit.
require(_gasLimit >= 21_000, "OptimismPortal: gas limit must cover instrinsic gas cost");
// Transform the from-address to its alias if the caller is a contract.
address from = msg.sender;
if (msg.sender != tx.origin) {
......
......@@ -52,13 +52,13 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
vm.recordLogs();
vm.prank(alice);
op.depositTransaction(
address(setter),
0,
10000,
false,
abi.encodeWithSelector(XDomainSetter.set.selector, 1)
);
op.depositTransaction({
_to: address(setter),
_value: 0,
_gasLimit: 21_000,
_isCreation: false,
_data: abi.encodeWithSelector(XDomainSetter.set.selector, 1)
});
// Simulate the operation of the `op-node` by parsing data
// from logs
......
......@@ -37,6 +37,21 @@ contract OptimismPortal_Test is Portal_Initializer {
op.depositTransaction(address(1), 1, 0, true, hex"");
}
/**
* @notice Prevent gasless deposits from being force processed in L2 by
* ensuring that they have a large enough gas limit set.
*/
function test_depositTransaction_smallGasLimit_reverts() external {
vm.expectRevert("OptimismPortal: gas limit must cover instrinsic gas cost");
op.depositTransaction({
_to: address(1),
_value: 0,
_gasLimit: 0,
_isCreation: false,
_data: hex""
});
}
// Test: depositTransaction should emit the correct log when an EOA deposits a tx with 0 value
function test_depositTransaction_noValueEOA_succeeds() external {
// EOA emulation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment