From 59bb2c526d3aa9cbca33d414de01153cc58111bb Mon Sep 17 00:00:00 2001 From: 0xchin <77933451+0xChin@users.noreply.github.com> Date: Wed, 12 Nov 2025 17:12:37 -0300 Subject: [PATCH] fix: improve template validation checks --- src/template/RevShareUpgradeAndSetup.sol | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/template/RevShareUpgradeAndSetup.sol b/src/template/RevShareUpgradeAndSetup.sol index 47f109afc..2f4a7a88f 100644 --- a/src/template/RevShareUpgradeAndSetup.sol +++ b/src/template/RevShareUpgradeAndSetup.sol @@ -47,6 +47,7 @@ contract RevShareUpgradeAndSetup is OPCMTaskBase { // Load RevShareContractsUpgrader address from TOML REV_SHARE_UPGRADER = tomlContent.readAddress(".revShareUpgrader"); + require(REV_SHARE_UPGRADER != address(0), "RevShareContractsUpgrader address cannot be zero"); require(REV_SHARE_UPGRADER.code.length > 0, "RevShareContractsUpgrader has no code"); vm.label(REV_SHARE_UPGRADER, "RevShareContractsUpgrader"); @@ -70,6 +71,37 @@ contract RevShareUpgradeAndSetup is OPCMTaskBase { "Config arrays length mismatch" ); + // Validate individual configuration values and check for duplicates + for (uint256 i; i < portals.length; i++) { + // Validate portal address + require(portals[i] != address(0), string.concat("Portal address cannot be zero at index ", vm.toString(i))); + require(portals[i].code.length > 0, string.concat("Portal has no code at index ", vm.toString(i))); + + // Check for duplicate portals + for (uint256 j; j < i; j++) { + require(portals[i] != portals[j], string.concat("Duplicate portal address at index ", vm.toString(i))); + } + + // Validate chain fees recipient + require( + chainFeesRecipients[i] != address(0), + string.concat("Chain fees recipient cannot be zero at index ", vm.toString(i)) + ); + + // Validate L1 withdrawer recipient + require( + l1WithdrawerRecipients[i] != address(0), + string.concat("L1 withdrawer recipient cannot be zero at index ", vm.toString(i)) + ); + + // Validate gas limit bounds + require(gasLimits[i] > 0, string.concat("Gas limit must be greater than 0 at index ", vm.toString(i))); + require( + gasLimits[i] <= type(uint32).max, + string.concat("Gas limit exceeds uint32 max at index ", vm.toString(i)) + ); + } + // Construct RevShare configs array from flattened arrays for (uint256 i; i < portals.length; i++) { revShareConfigs.push(