-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change KeystoneForwarder routing gas accounting (#14543)
* Add additional tests with malicious receivers * Fix capability type * Fix lint errors * Add changesets * Make go lint happy * Additional improvements to forwarder gas accounting * Undo forwarder logic constant change * Update gethwrappers * Use the right variable * Update gethwrappers --------- Co-authored-by: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com>
- Loading branch information
1 parent
700dd7c
commit c4fa565
Showing
9 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
#internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/contracts': patch | ||
--- | ||
|
||
#internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
contracts/src/v0.8/keystone/test/mocks/MaliciousReportReceiver.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/interfaces/IERC165.sol"; | ||
import {IReceiver} from "../../interfaces/IReceiver.sol"; | ||
|
||
contract MaliciousReportReceiver is IReceiver, IERC165 { | ||
event MessageReceived(bytes metadata, bytes[] mercuryReports); | ||
bytes public latestReport; | ||
|
||
function onReport(bytes calldata metadata, bytes calldata rawReport) external { | ||
// Exhaust all gas that was provided | ||
for (uint256 i = 0; i < 1_000_000_000; i++) { | ||
bytes[] memory mercuryReports = abi.decode(rawReport, (bytes[])); | ||
latestReport = rawReport; | ||
emit MessageReceived(metadata, mercuryReports); | ||
} | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { | ||
return interfaceId == type(IReceiver).interfaceId || interfaceId == type(IERC165).interfaceId; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
contracts/src/v0.8/keystone/test/mocks/MaliciousRevertingReceiver.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
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 { | ||
function onReport(bytes calldata, bytes calldata) external view override { | ||
// consumes about 63/64 of all gas available | ||
uint256 targetGasRemaining = 200; | ||
for (uint256 i = 0; gasleft() > targetGasRemaining; i++) {} | ||
} | ||
|
||
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++) {} | ||
|
||
return interfaceId == type(IReceiver).interfaceId || interfaceId == type(IERC165).interfaceId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
core/gethwrappers/keystone/generation/generated-wrapper-dependency-versions-do-not-edit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
GETH_VERSION: 1.13.8 | ||
capabilities_registry: ../../../contracts/solc/v0.8.24/CapabilitiesRegistry/CapabilitiesRegistry.abi ../../../contracts/solc/v0.8.24/CapabilitiesRegistry/CapabilitiesRegistry.bin cb3e79280a928979bc37de154b12b876996bdbe10f1827e683ee2bfa7a429a6c | ||
feeds_consumer: ../../../contracts/solc/v0.8.24/KeystoneFeedsConsumer/KeystoneFeedsConsumer.abi ../../../contracts/solc/v0.8.24/KeystoneFeedsConsumer/KeystoneFeedsConsumer.bin 6ac5b12eff3b022a35c3c40d5ed0285bf9bfec0e3669a4b12307332a216048ca | ||
forwarder: ../../../contracts/solc/v0.8.24/KeystoneForwarder/KeystoneForwarder.abi ../../../contracts/solc/v0.8.24/KeystoneForwarder/KeystoneForwarder.bin 0da2ce239c9d4521005428f2d42a67dbee2ae6dd7160fd9e4f4322fb51d4f6ba | ||
forwarder: ../../../contracts/solc/v0.8.24/KeystoneForwarder/KeystoneForwarder.abi ../../../contracts/solc/v0.8.24/KeystoneForwarder/KeystoneForwarder.bin 03911334d0c88f8ee8ee2d9832fd312bc8a48c824fcda5c807585af2d0e6a148 | ||
ocr3_capability: ../../../contracts/solc/v0.8.24/OCR3Capability/OCR3Capability.abi ../../../contracts/solc/v0.8.24/OCR3Capability/OCR3Capability.bin 2a6bfae30ccf38327fc7e78605a226839dfa0ce5a1a22e0414b91d24c35b3a53 |