Skip to content

Commit

Permalink
Fix Keystone Solidity issues (#14565)
Browse files Browse the repository at this point in the history
* Remove forge from mock contract

* Remove console and fix MaliciousRevertingReceiver for coverage 🤔
  • Loading branch information
DeividasK authored Sep 25, 2024
1 parent 8b01661 commit 8c9bd82
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {IRouter} from "../interfaces/IRouter.sol";
import {MaliciousReportReceiver} from "./mocks/MaliciousReportReceiver.sol";
import {MaliciousRevertingReceiver} from "./mocks/MaliciousRevertingReceiver.sol";
import {KeystoneForwarder} from "../KeystoneForwarder.sol";
import {console} from "forge-std/console.sol";

contract KeystoneForwarder_ReportTest is BaseTest {
event MessageReceived(bytes metadata, bytes[] mercuryReports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ pragma solidity 0.8.24;

import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/interfaces/IERC165.sol";
import {IReceiver} from "../../interfaces/IReceiver.sol";
import {Test} from "forge-std/Test.sol";

/// A malicious receiver that uses max allowed for ERC165 checks and consumes all gas in `onReport()`
/// Causes parent Forwarder contract to revert if it doesn't handle gas tracking accurately
contract MaliciousRevertingReceiver is IReceiver, IERC165, Test {
contract MaliciousRevertingReceiver is IReceiver, IERC165 {
function onReport(bytes calldata, bytes calldata) external view override {
// consumes about 63/64 of all gas available
uint256 targetGasRemaining = 200;
Expand All @@ -16,8 +15,7 @@ contract MaliciousRevertingReceiver is IReceiver, IERC165, Test {

function supportsInterface(bytes4 interfaceId) public pure override returns (bool) {
// Consume up to the maximum amount of gas that can be consumed in this check
// This loop consumes roughly 29_000 gas
for (uint256 i = 0; i < 670; i++) {}
for (uint256 i = 0; i < 500; i++) {}

return interfaceId == type(IReceiver).interfaceId || interfaceId == type(IERC165).interfaceId;
}
Expand Down

0 comments on commit 8c9bd82

Please sign in to comment.