Skip to content

Commit

Permalink
feat: add sol-style-malformed-revert locally (ethereum-optimism#12341)
Browse files Browse the repository at this point in the history
Adds sol-style-malformed-revert to local semgrep and fixes the
rule so that it actually works. Fixes a couple of findings that
the updated rule discovered.
  • Loading branch information
smartcontracts authored Oct 7, 2024
1 parent 35bbd80 commit 6d874d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .semgrep/sol-rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ rules:
- packages/contracts-bedrock/src/cannon/MIPS.sol
- packages/contracts-bedrock/src/cannon/MIPS2.sol
- packages/contracts-bedrock/src/cannon/libraries/MIPSMemory.sol

- id: sol-style-malformed-revert
languages: [solidity]
severity: ERROR
message: Revert statement style is malformed
patterns:
- pattern: revert($MSG);
- pattern-not: revert $ERR(...);
- focus-metavariable: $MSG
- pattern-not-regex: \"(\w+:\s[^"]+)\"
paths:
exclude:
- packages/contracts-bedrock/src/cannon/libraries/MIPSInstructions.sol
6 changes: 4 additions & 2 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,9 @@ contract Deploy is Deployer {
commands[1] = "-c";
commands[2] = string.concat("[[ -f ", filePath, " ]] && echo \"present\"");
if (Process.run(commands).length == 0) {
revert("Cannon prestate dump not found, generate it with `make cannon-prestate` in the monorepo root.");
revert(
"Deploy: cannon prestate dump not found, generate it with `make cannon-prestate` in the monorepo root"
);
}
commands[2] = string.concat("cat ", filePath, " | jq -r .pre");
mipsAbsolutePrestate_ = Claim.wrap(abi.decode(Process.run(commands), (bytes32)));
Expand All @@ -1310,7 +1312,7 @@ contract Deploy is Deployer {
commands[2] = string.concat("[[ -f ", filePath, " ]] && echo \"present\"");
if (Process.run(commands).length == 0) {
revert(
"MT-Cannon prestate dump not found, generate it with `make cannon-prestate-mt` in the monorepo root."
"Deploy: MT-Cannon prestate dump not found, generate it with `make cannon-prestate-mt` in the monorepo root"
);
}
commands[2] = string.concat("cat ", filePath, " | jq -r .pre");
Expand Down
4 changes: 3 additions & 1 deletion packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ contract DeployConfig is Script {
} catch { }
}
}
revert("l1StartingBlockTag must be a bytes32, string or uint256 or cannot fetch l1StartingBlockTag");
revert(
"DeployConfig: l1StartingBlockTag must be a bytes32, string or uint256 or cannot fetch l1StartingBlockTag"
);
}

function l2OutputOracleStartingTimestamp() public returns (uint256) {
Expand Down

0 comments on commit 6d874d5

Please sign in to comment.