Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -30,6 +30,9 @@ contract GenerateNUTBundle is Script {
/// @notice Version of the upgrade bundle.
string internal constant BUNDLE_VERSION = "1.0.0";

/// @notice EIP-7825 per-transaction gas limit cap (2 ** 24).
uint256 public constant MAX_TX_GAS_LIMIT = 16777216;

/// @notice Output containing generated transactions.
/// @param txns Array of Network Upgrade Transactions to execute.
struct Output {
Expand Down Expand Up @@ -113,7 +116,7 @@ contract GenerateNUTBundle is Script {
output_.txns[i] = txns[i];
}

_assertValidOutput(output_);
assertValidOutput(output_);

// Write transactions to artifact with metadata
NetworkUpgradeTxns.BundleMetadata memory metadata =
Expand All @@ -123,7 +126,7 @@ contract GenerateNUTBundle is Script {

/// @notice Asserts the output is valid.
/// @param _output The output to assert.
function _assertValidOutput(Output memory _output) internal pure {
function assertValidOutput(Output memory _output) public pure {
Comment thread
maurelian marked this conversation as resolved.
Outdated
uint256 transactionCount = UpgradeUtils.getTransactionCount();
uint256 txnsLength = _output.txns.length;
require(txnsLength == transactionCount, "GenerateNUTBundle: invalid transaction count");
Expand All @@ -132,7 +135,10 @@ contract GenerateNUTBundle is Script {
require(_output.txns[i].data.length > 0, "GenerateNUTBundle: invalid transaction data");
require(bytes(_output.txns[i].intent).length > 0, "GenerateNUTBundle: invalid transaction intent");
require(_output.txns[i].to != address(0), "GenerateNUTBundle: invalid transaction to");
require(_output.txns[i].gasLimit > 0, "GenerateNUTBundle: invalid transaction gasLimit");
require(
_output.txns[i].gasLimit > 0 && _output.txns[i].gasLimit <= MAX_TX_GAS_LIMIT,
"GenerateNUTBundle: invalid transaction gasLimit"
);

if (_output.txns[i].from == address(0)) {
// Transactions must have a from address except for ProxyAdmin and ConditionalDeployer upgrades
Expand Down
12 changes: 12 additions & 0 deletions packages/contracts-bedrock/test/scripts/GenerateNUTBundle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,16 @@ contract GenerateNUTBundleTest is Test {
string[] memory names = UpgradeUtils.getImplementationsNamesToUpgrade();
assertEq(names.length, structFieldCount, "Deployment list must equal Implementations struct field count");
}

/// @notice Tests that a transaction exceeding the per-transaction gas limit cap is rejected.
function testFuzz_assertValidOutput_gasLimitExceedsMax_reverts(uint256 _index, uint64 _gasLimit) public {
Comment thread
0xniha marked this conversation as resolved.
GenerateNUTBundle.Output memory output = script.run();

_index = bound(_index, 0, output.txns.length - 1);
_gasLimit = uint64(bound(_gasLimit, script.MAX_TX_GAS_LIMIT() + 1, type(uint64).max));
output.txns[_index].gasLimit = _gasLimit;

vm.expectRevert("GenerateNUTBundle: invalid transaction gasLimit");
script.assertValidOutput(output);
}
}
Loading