Skip to content

Commit

Permalink
add readonly address (#11906)
Browse files Browse the repository at this point in the history
* add readonly address

* add unit test, rebase and address comments
  • Loading branch information
shileiwill authored Feb 7, 2024
1 parent 97ecb9e commit 7eb5600
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 26 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {AutomationRegistryBase2_2} from "../v2_2/AutomationRegistryBase2_2.sol";
import {AutomationRegistryLogicA2_2} from "../v2_2/AutomationRegistryLogicA2_2.sol";
import {AutomationRegistryLogicB2_2} from "../v2_2/AutomationRegistryLogicB2_2.sol";
import {IAutomationRegistryMaster} from "../interfaces/v2_2/IAutomationRegistryMaster.sol";
import {AutomationCompatibleInterface} from "../../interfaces/AutomationCompatibleInterface.sol";

contract AutomationRegistry2_2_SetUp is BaseTest {
address internal constant LINK_ETH_FEED = 0x1111111111111111111111111111111111111110;
address internal constant FAST_GAS_FEED = 0x1111111111111111111111111111111111111112;
address internal constant LINK_TOKEN = 0x1111111111111111111111111111111111111113;
address internal constant ZERO_ADDRESS = address(0);

// Signer private keys used for these test
uint256 internal constant PRIVATE0 = 0x7b2e97fe057e6de99d6872a2ef2abf52c9b4469bc848c2465ac3fcd8d336e81d;
Expand Down Expand Up @@ -50,7 +52,8 @@ contract AutomationRegistry2_2_SetUp is BaseTest {
LINK_TOKEN,
LINK_ETH_FEED,
FAST_GAS_FEED,
address(forwarderLogic)
address(forwarderLogic),
ZERO_ADDRESS
);
AutomationRegistryLogicA2_2 logicA2_2 = new AutomationRegistryLogicA2_2(logicB2_2);
IAutomationRegistryMaster registry2_2 = IAutomationRegistryMaster(
Expand All @@ -72,6 +75,22 @@ contract AutomationRegistry2_2_LatestConfigDetails is AutomationRegistry2_2_SetU
}
}

contract AutomationRegistry2_2_CheckUpkeep is AutomationRegistry2_2_SetUp {
function testPreventExecutionOnCheckUpkeep() public {
IAutomationRegistryMaster registry = IAutomationRegistryMaster(
address(deployRegistry2_2(AutomationRegistryBase2_2.Mode(0)))
);

uint256 id = 1;
bytes memory triggerData = abi.encodePacked("trigger_data");

// The tx.origin is the DEFAULT_SENDER (0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38) of foundry
// Expecting a revert since the tx.origin is not address(0)
vm.expectRevert(abi.encodeWithSelector(IAutomationRegistryMaster.OnlySimulatedBackend.selector));
registry.checkUpkeep(id, triggerData);
}
}

contract AutomationRegistry2_2_SetConfig is AutomationRegistry2_2_SetUp {
event ConfigSet(
uint32 previousConfigBlockNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
logicA.getLinkAddress(),
logicA.getLinkNativeFeedAddress(),
logicA.getFastGasFeedAddress(),
logicA.getAutomationForwarderLogic()
logicA.getAutomationForwarderLogic(),
logicA.getAllowedReadOnlyAddress()
)
Chainable(address(logicA))
{}
Expand Down Expand Up @@ -195,7 +196,9 @@ contract AutomationRegistry2_2 is AutomationRegistryBase2_2, OCR2Abstract, Chain
function simulatePerformUpkeep(
uint256 id,
bytes calldata performData
) external cannotExecute returns (bool success, uint256 gasUsed) {
) external returns (bool success, uint256 gasUsed) {
_preventExecution();

if (s_hotVars.paused) revert RegistryPaused();
Upkeep memory upkeep = s_upkeep[id];
(success, gasUsed) = _performUpkeep(upkeep.forwarder, upkeep.performGas, performData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contra
import {Address} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol";
import {ArbGasInfo} from "../../../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol";
import {OVM_GasPriceOracle} from "../../../vendor/@eth-optimism/contracts/v0.8.9/contracts/L2/predeploys/OVM_GasPriceOracle.sol";
import {ExecutionPrevention} from "../../ExecutionPrevention.sol";
import {ArbSys} from "../../../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbSys.sol";
import {StreamsLookupCompatibleInterface} from "../../interfaces/StreamsLookupCompatibleInterface.sol";
import {ILogAutomation, Log} from "../../interfaces/ILogAutomation.sol";
Expand All @@ -21,7 +20,7 @@ import {UpkeepFormat} from "../../interfaces/UpkeepTranscoderInterface.sol";
* AutomationRegistry and AutomationRegistryLogic
* @dev all errors, events, and internal functions should live here
*/
abstract contract AutomationRegistryBase2_2 is ConfirmedOwner, ExecutionPrevention {
abstract contract AutomationRegistryBase2_2 is ConfirmedOwner {
using Address for address;
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
Expand Down Expand Up @@ -69,6 +68,7 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner, ExecutionPreventi
AggregatorV3Interface internal immutable i_fastGasFeed;
Mode internal immutable i_mode;
address internal immutable i_automationForwarderLogic;
address internal immutable i_allowedReadOnlyAddress;

/**
* @dev - The storage is gas optimised for one and only one function - transmit. All the storage accessed in transmit
Expand Down Expand Up @@ -138,6 +138,7 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner, ExecutionPreventi
error OnlyCallableByProposedPayee();
error OnlyCallableByUpkeepPrivilegeManager();
error OnlyPausedUpkeep();
error OnlySimulatedBackend();
error OnlyUnpausedUpkeep();
error ParameterLengthError();
error PaymentGreaterThanAllLINK();
Expand Down Expand Up @@ -449,19 +450,23 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner, ExecutionPreventi
* @param link address of the LINK Token
* @param linkNativeFeed address of the LINK/Native price feed
* @param fastGasFeed address of the Fast Gas price feed
* @param automationForwarderLogic the address of automation forwarder logic
* @param allowedReadOnlyAddress the address of the allowed read only address
*/
constructor(
Mode mode,
address link,
address linkNativeFeed,
address fastGasFeed,
address automationForwarderLogic
address automationForwarderLogic,
address allowedReadOnlyAddress
) ConfirmedOwner(msg.sender) {
i_mode = mode;
i_link = LinkTokenInterface(link);
i_linkNativeFeed = AggregatorV3Interface(linkNativeFeed);
i_fastGasFeed = AggregatorV3Interface(fastGasFeed);
i_automationForwarderLogic = automationForwarderLogic;
i_allowedReadOnlyAddress = allowedReadOnlyAddress;
}

// ================================================================
Expand Down Expand Up @@ -962,4 +967,13 @@ abstract contract AutomationRegistryBase2_2 is ConfirmedOwner, ExecutionPreventi
_;
s_hotVars.reentrancyGuard = false;
}

/**
* @notice only allows a pre-configured address to initiate offchain read
*/
function _preventExecution() internal view {
if (tx.origin != i_allowedReadOnlyAddress) {
revert OnlySimulatedBackend();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
logicB.getLinkAddress(),
logicB.getLinkNativeFeedAddress(),
logicB.getFastGasFeedAddress(),
logicB.getAutomationForwarderLogic()
logicB.getAutomationForwarderLogic(),
logicB.getAllowedReadOnlyAddress()
)
Chainable(address(logicB))
{}
Expand All @@ -49,7 +50,6 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
bytes memory triggerData
)
public
cannotExecute
returns (
bool upkeepNeeded,
bytes memory performData,
Expand All @@ -60,6 +60,8 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
uint256 linkNative
)
{
_preventExecution();

Trigger triggerType = _getTriggerType(id);
HotVars memory hotVars = s_hotVars;
Upkeep memory upkeep = s_upkeep[id];
Expand Down Expand Up @@ -172,7 +174,6 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
bytes calldata extraData
)
external
cannotExecute
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
bytes memory payload = abi.encodeWithSelector(CHECK_CALLBACK_SELECTOR, values, extraData);
Expand All @@ -190,9 +191,10 @@ contract AutomationRegistryLogicA2_2 is AutomationRegistryBase2_2, Chainable {
bytes memory payload
)
public
cannotExecute
returns (bool upkeepNeeded, bytes memory performData, UpkeepFailureReason upkeepFailureReason, uint256 gasUsed)
{
_preventExecution();

Upkeep memory upkeep = s_upkeep[id];
gasUsed = gasleft();
(bool success, bytes memory result) = upkeep.forwarder.getTarget().call{gas: s_storage.checkGasLimit}(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ contract AutomationRegistryLogicB2_2 is AutomationRegistryBase2_2 {
address link,
address linkNativeFeed,
address fastGasFeed,
address automationForwarderLogic
) AutomationRegistryBase2_2(mode, link, linkNativeFeed, fastGasFeed, automationForwarderLogic) {}
address automationForwarderLogic,
address allowedReadOnlyAddress
)
AutomationRegistryBase2_2(mode, link, linkNativeFeed, fastGasFeed, automationForwarderLogic, allowedReadOnlyAddress)
{}

// ================================================================
// | UPKEEP MANAGEMENT |
Expand Down Expand Up @@ -300,6 +303,10 @@ contract AutomationRegistryLogicB2_2 is AutomationRegistryBase2_2 {
return i_automationForwarderLogic;
}

function getAllowedReadOnlyAddress() external view returns (address) {
return i_allowedReadOnlyAddress;
}

function upkeepTranscoderVersion() public pure returns (UpkeepFormat) {
return UPKEEP_TRANSCODER_VERSION_BASE;
}
Expand Down
5 changes: 5 additions & 0 deletions contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ describe('AutomationRegistry2_2', () => {
linkToken.address,
linkEthFeed.address,
gasPriceFeed.address,
zeroAddress,
)

arbRegistry = await deployRegistry22(
Expand All @@ -907,6 +908,7 @@ describe('AutomationRegistry2_2', () => {
linkToken.address,
linkEthFeed.address,
gasPriceFeed.address,
zeroAddress,
)

opRegistry = await deployRegistry22(
Expand All @@ -915,6 +917,7 @@ describe('AutomationRegistry2_2', () => {
linkToken.address,
linkEthFeed.address,
gasPriceFeed.address,
zeroAddress,
)

mgRegistry = await deployRegistry22(
Expand All @@ -923,6 +926,7 @@ describe('AutomationRegistry2_2', () => {
linkToken.address,
linkEthFeed.address,
gasPriceFeed.address,
zeroAddress,
)

blankRegistry = await deployRegistry22(
Expand All @@ -931,6 +935,7 @@ describe('AutomationRegistry2_2', () => {
linkToken.address,
linkEthFeed.address,
gasPriceFeed.address,
zeroAddress,
)

registryConditionalOverhead = await registry.getConditionalGasOverhead()
Expand Down
12 changes: 11 additions & 1 deletion contracts/test/v0.8/automation/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const deployRegistry22 = async (
link: Parameters<AutomationRegistryLogicBFactory['deploy']>[1],
linkNative: Parameters<AutomationRegistryLogicBFactory['deploy']>[2],
fastgas: Parameters<AutomationRegistryLogicBFactory['deploy']>[3],
allowedReadOnlyAddress: Parameters<
AutomationRegistryLogicBFactory['deploy']
>[4],
): Promise<IAutomationRegistry> => {
const logicBFactory = await ethers.getContractFactory(
'AutomationRegistryLogicB2_2',
Expand All @@ -55,7 +58,14 @@ export const deployRegistry22 = async (
const forwarderLogic = await forwarderLogicFactory.connect(from).deploy()
const logicB = await logicBFactory
.connect(from)
.deploy(mode, link, linkNative, fastgas, forwarderLogic.address)
.deploy(
mode,
link,
linkNative,
fastgas,
forwarderLogic.address,
allowedReadOnlyAddress,
)
const logicA = await logicAFactory.connect(from).deploy(logicB.address)
const master = await registryFactory.connect(from).deploy(logicA.address)
return IAutomationRegistryMasterFactory.connect(master.address, from)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ flux_aggregator_wrapper: ../../contracts/solc/v0.6/FluxAggregator/FluxAggregator
gas_wrapper: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.bin 4a5dcdac486d18fcd58e3488c15c1710ae76b977556a3f3191bd269a4bc75723
gas_wrapper_mock: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.bin a9b08f18da59125c6fc305855710241f3d35161b8b9f3e3f635a7b1d5c6da9c8
i_keeper_registry_master_wrapper_2_1: ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.abi ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.bin 6501bb9bcf5048bab2737b00685c6984a24867e234ddf5b60a65904eee9a4ebc
i_keeper_registry_master_wrapper_2_2: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.bin 37aabed3df4c1ab6ac63def4aa8e251da975bbbb15a8bcf1c22ff7467d70f70f
i_keeper_registry_master_wrapper_2_2: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.bin 297e3b22f8087dc79bb76e06b8e605ee855c1ba60466bdc4b3a879dc633d4fd3
i_log_automation: ../../contracts/solc/v0.8.16/ILogAutomation/ILogAutomation.abi ../../contracts/solc/v0.8.16/ILogAutomation/ILogAutomation.bin 296beccb6af655d6fc3a6e676b244831cce2da6688d3afc4f21f8738ae59e03e
keeper_consumer_performance_wrapper: ../../contracts/solc/v0.8.16/KeeperConsumerPerformance/KeeperConsumerPerformance.abi ../../contracts/solc/v0.8.16/KeeperConsumerPerformance/KeeperConsumerPerformance.bin eeda39f5d3e1c8ffa0fb6cd1803731b98a4bc262d41833458e3fe8b40933ae90
keeper_consumer_wrapper: ../../contracts/solc/v0.8.16/KeeperConsumer/KeeperConsumer.abi ../../contracts/solc/v0.8.16/KeeperConsumer/KeeperConsumer.bin 2c6163b145082fbab74b7343577a9cec8fda8b0da9daccf2a82581b1f5a84b83
Expand All @@ -34,16 +34,16 @@ keeper_registrar_wrapper2_0: ../../contracts/solc/v0.8.6/KeeperRegistrar2_0/Keep
keeper_registry_logic1_3: ../../contracts/solc/v0.8.6/KeeperRegistryLogic1_3/KeeperRegistryLogic1_3.abi ../../contracts/solc/v0.8.6/KeeperRegistryLogic1_3/KeeperRegistryLogic1_3.bin 903f8b9c8e25425ca6d0b81b89e339d695a83630bfbfa24a6f3b38869676bc5a
keeper_registry_logic2_0: ../../contracts/solc/v0.8.6/KeeperRegistryLogic2_0/KeeperRegistryLogic2_0.abi ../../contracts/solc/v0.8.6/KeeperRegistryLogic2_0/KeeperRegistryLogic2_0.bin d69d2bc8e4844293dbc2d45abcddc50b84c88554ecccfa4fa77c0ca45ec80871
keeper_registry_logic_a_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1/KeeperRegistryLogicA2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1/KeeperRegistryLogicA2_1.bin 77481ab75c9aa86a62a7b2a708599b5ea1a6346ed1c0def6d4826e7ae523f1ee
keeper_registry_logic_a_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.bin 29cb8ca92fe15bc851c52e3bbf109cece5d485bf0840bcccebf5b03055b64730
keeper_registry_logic_a_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.bin 89a18aa7b49178520a7195cef1c2f1069a600c17a62c0efc92a4ee365b39eca1
keeper_registry_logic_b_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistryLogicB2_1/KeeperRegistryLogicB2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistryLogicB2_1/KeeperRegistryLogicB2_1.bin 467d10741a04601b136553a2b1c6ab37f2a65d809366faf03180a22ff26be215
keeper_registry_logic_b_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.bin e0f5a9e7f83ad6098fa6a7605a49275e98904a1c3826fe3f757a6542fcf38169
keeper_registry_logic_b_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.bin c775e0bb87a7e6d04ac36312d7dea65162a71777556edb41b0d1060c67f61d20
keeper_registry_wrapper1_1: ../../contracts/solc/v0.7/KeeperRegistry1_1/KeeperRegistry1_1.abi ../../contracts/solc/v0.7/KeeperRegistry1_1/KeeperRegistry1_1.bin 6ce079f2738f015f7374673a2816e8e9787143d00b780ea7652c8aa9ad9e1e20
keeper_registry_wrapper1_1_mock: ../../contracts/solc/v0.7/KeeperRegistry1_1Mock/KeeperRegistry1_1Mock.abi ../../contracts/solc/v0.7/KeeperRegistry1_1Mock/KeeperRegistry1_1Mock.bin 98ddb3680e86359de3b5d17e648253ba29a84703f087a1b52237824003a8c6df
keeper_registry_wrapper1_2: ../../contracts/solc/v0.8.6/KeeperRegistry1_2/KeeperRegistry1_2.abi ../../contracts/solc/v0.8.6/KeeperRegistry1_2/KeeperRegistry1_2.bin a40ff877dd7c280f984cbbb2b428e160662b0c295e881d5f778f941c0088ca22
keeper_registry_wrapper1_3: ../../contracts/solc/v0.8.6/KeeperRegistry1_3/KeeperRegistry1_3.abi ../../contracts/solc/v0.8.6/KeeperRegistry1_3/KeeperRegistry1_3.bin d4dc760b767ae274ee25c4a604ea371e1fa603a7b6421b69efb2088ad9e8abb3
keeper_registry_wrapper2_0: ../../contracts/solc/v0.8.6/KeeperRegistry2_0/KeeperRegistry2_0.abi ../../contracts/solc/v0.8.6/KeeperRegistry2_0/KeeperRegistry2_0.bin c32dea7d5ef66b7c58ddc84ddf69aa44df1b3ae8601fbc271c95be4ff5853056
keeper_registry_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistry2_1/KeeperRegistry2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistry2_1/KeeperRegistry2_1.bin 604e4a0cd980c713929b523b999462a3aa0ed06f96ff563a4c8566cf59c8445b
keeper_registry_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.bin 320d599d74c49fe773f60f5cbe939363918d9eaeb9963da294616300c55dabbf
keeper_registry_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.bin 55c423335ec7fe67ae99be7a9f617740946abeccf86b2eed03b77d447f0ca8b4
keepers_vrf_consumer: ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.abi ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.bin fa75572e689c9e84705c63e8dbe1b7b8aa1a8fe82d66356c4873d024bb9166e8
log_emitter: ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.abi ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.bin 4b129ab93432c95ff9143f0631323e189887668889e0b36ccccf18a571e41ccf
log_triggered_streams_lookup_wrapper: ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.abi ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.bin f8da43a927c1a66238a9f4fd5d5dd7e280e361daa0444da1f7f79498ace901e1
Expand Down

0 comments on commit 7eb5600

Please sign in to comment.