From 1e89a63b0eb568f11034c6e357ded1764632b00e Mon Sep 17 00:00:00 2001 From: Rens Rooimans Date: Fri, 6 Oct 2023 19:33:08 +0200 Subject: [PATCH] Enable Solhint (#10869) * enable solhint for /shared/ folder add others to ignore file add solhint to CICD * add chainlink-solidity ruleset * reduce ignore scope & fix interface folder issues * rm unused imports * clean /libraries * set no-unused-import to error * allow 968 warnings, the number we currently have * fix second layer imports * contracts/v0.8: fix solhint warnings for vrf contracts (#10875) * rm no-inline-assembly rule --------- Co-authored-by: Makram --- .github/workflows/solidity.yml | 2 + CODEOWNERS | 4 +- contracts/.solhint.json | 39 +++++++++++++++++- contracts/.solhintignore | 33 ++++++++++++++- contracts/package.json | 4 +- contracts/pnpm-lock.yaml | 9 ++++ contracts/scripts/native_solc_compile_all_vrf | 1 + contracts/src/v0.8/automation/KeeperBase.sol | 1 + .../src/v0.8/automation/KeeperCompatible.sol | 3 ++ .../interfaces/KeeperCompatibleInterface.sol | 1 + .../v1_2/KeeperRegistryInterface1_2.sol | 4 ++ .../automation/v1_3/KeeperRegistry1_3.sol | 2 +- .../automation/v1_3/KeeperRegistryBase1_3.sol | 2 +- .../automation/v2_0/KeeperRegistry2_0.sol | 2 +- .../automation/v2_0/KeeperRegistryBase2_0.sol | 1 - .../v2_0/KeeperRegistryLogic2_0.sol | 1 + .../automation/v2_1/AutomationUtils2_1.sol | 2 +- .../automation/v2_1/KeeperRegistry2_1.sol | 1 - .../automation/v2_1/KeeperRegistryBase2_1.sol | 2 +- .../automation/v2_1/UpkeepTranscoder4_0.sol | 1 - contracts/src/v0.8/dev/BlockhashStore.sol | 7 +++- .../v0.8/dev/VRFConsumerBaseV2Upgradeable.sol | 7 +++- .../dev/VRFSubscriptionBalanceMonitor.sol | 14 ++++--- .../dev/interfaces/IVRFCoordinatorV2Plus.sol | 4 +- .../IVRFCoordinatorV2PlusInternal.sol | 5 ++- .../dev/vrf/BatchVRFCoordinatorV2Plus.sol | 7 +++- contracts/src/v0.8/dev/vrf/BlockhashStore.sol | 7 +++- .../src/v0.8/dev/vrf/SubscriptionAPI.sol | 14 ++++--- .../v0.8/dev/vrf/TrustedBlockhashStore.sol | 6 +-- .../v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol | 7 ++-- .../src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol | 35 ++++++++++------ .../src/v0.8/dev/vrf/VRFV2PlusWrapper.sol | 41 +++++++++++++------ .../dev/vrf/VRFV2PlusWrapperConsumerBase.sol | 10 ++++- .../testhelpers/ExposedVRFCoordinatorV2_5.sol | 4 +- .../VRFConsumerV2PlusUpgradeableExample.sol | 13 ++++-- .../VRFCoordinatorV2PlusUpgradedVersion.sol | 36 ++++++++++------ .../VRFCoordinatorV2Plus_V2Example.sol | 9 ++-- .../VRFMaliciousConsumerV2Plus.sol | 19 +++++---- .../testhelpers/VRFV2PlusConsumerExample.sol | 16 ++++++-- .../VRFV2PlusExternalSubOwnerExample.sol | 17 +++++--- .../VRFV2PlusLoadTestWithMetrics.sol | 19 +++++---- .../VRFV2PlusMaliciousMigrator.sol | 10 ++--- .../testhelpers/VRFV2PlusRevertingExample.sol | 17 +++++--- .../VRFV2PlusSingleConsumerExample.sol | 17 +++++--- .../VRFV2PlusWrapperConsumerExample.sol | 8 +++- .../VRFV2PlusWrapperLoadTestConsumer.sol | 24 +++++++---- .../dev/v0_0_0/FunctionsBillingRegistry.sol | 1 - .../dev/v1_0_0/FunctionsCoordinator.sol | 1 - .../functions/dev/v1_0_0/FunctionsRouter.sol | 2 - .../dev/v1_0_0/FunctionsSubscriptions.sol | 3 -- .../v1_0_0/libraries/FunctionsResponse.sol | 2 - .../FunctionsBillingRegistryMigration.sol | 2 - .../FunctionsBillingRegistryOriginal.sol | 2 - .../interfaces/AggregatorV2V3Interface.sol | 4 +- .../v0.8/interfaces/FeedRegistryInterface.sol | 2 +- .../src/v0.8/interfaces/OperatorInterface.sol | 4 +- .../arbitrum/ArbitrumSequencerUptimeFeed.sol | 2 - .../optimism/OptimismSequencerUptimeFeed.sol | 1 - contracts/src/v0.8/libraries/ByteUtil.sol | 8 ++-- contracts/src/v0.8/libraries/Common.sol | 2 +- .../v0.8/libraries/test/ByteUtilTest.t.sol | 40 +++++++++--------- .../src/v0.8/llo-feeds/RewardManager.sol | 3 +- contracts/src/v0.8/llo-feeds/Verifier.sol | 2 +- .../test/fee-manager/BaseFeeManager.t.sol | 1 - .../test/fee-manager/FeeManager.general.t.sol | 3 -- .../FeeManager.getFeeAndReward.t.sol | 3 -- .../fee-manager/FeeManager.processFee.t.sol | 2 - .../FeeManager.processFeeBulk.t.sol | 3 -- .../llo-feeds/test/gas/Gas_VerifierTest.t.sol | 1 - .../RewardManager.general.t.sol | 1 - .../RewardManager.payRecipients.t.sol | 1 - .../RewardManager.setRecipients.t.sol | 1 - ...RewardManager.updateRewardRecipients.t.sol | 1 - .../verifier/VerifierActivateConfigTest.t.sol | 1 - .../verifier/VerifierDeactivateFeedTest.t.sol | 1 - .../VerifierProxyConstructorTest.t.sol | 1 - .../VerifierProxyInitializeVerifierTest.t.sol | 2 - .../VerifierProxySetVerifierTest.t.sol | 1 - .../test/verifier/VerifierProxyTest.t.sol | 4 -- .../VerifierProxyUnsetVerifierTest.t.sol | 1 - .../VerifierSetConfigFromSourceTest.t.sol | 2 - .../test/verifier/VerifierSetConfigTest.t.sol | 1 - .../test/verifier/VerifierTest.t.sol | 1 - .../verifier/VerifierTestBillingReport.t.sol | 3 -- .../verifier/VerifierUnsetConfigTest.t.sol | 3 +- .../src/v0.8/shared/access/ConfirmedOwner.sol | 2 +- .../access/ConfirmedOwnerWithProposal.sol | 6 ++- .../access/SimpleReadAccessController.sol | 3 +- .../access/SimpleWriteAccessController.sol | 17 ++++---- .../src/v0.8/shared/interfaces/IWERC20.sol | 2 +- .../src/v0.8/shared/mocks/WERC20Mock.sol | 7 ++-- .../src/v0.8/shared/ocr2/OCR2Abstract.sol | 3 ++ .../test/token/ERC677/BurnMintERC677.t.sol | 1 - .../token/ERC20/IOptimismMintableERC20.sol | 1 + .../shared/token/ERC677/BurnMintERC677.sol | 1 + .../src/v0.8/shared/token/ERC677/ERC677.sol | 2 +- .../src/v0.8/vrf/BatchBlockhashStore.sol | 6 ++- .../src/v0.8/vrf/BatchVRFCoordinatorV2.sol | 7 +++- contracts/src/v0.8/vrf/VRF.sol | 33 ++++++++++++++- contracts/src/v0.8/vrf/VRFConsumerBase.sol | 10 ++++- contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol | 2 + contracts/src/v0.8/vrf/VRFCoordinatorV2.sol | 30 +++++++++----- contracts/src/v0.8/vrf/VRFOwner.sol | 7 +++- contracts/src/v0.8/vrf/VRFRequestIDBase.sol | 2 + contracts/src/v0.8/vrf/VRFV2Wrapper.sol | 40 ++++++++++++------ .../src/v0.8/vrf/VRFV2WrapperConsumerBase.sol | 9 +++- .../vrfv2plus_malicious_migrator.go | 16 ++++---- ...rapper-dependency-versions-do-not-edit.txt | 2 +- 108 files changed, 531 insertions(+), 285 deletions(-) diff --git a/.github/workflows/solidity.yml b/.github/workflows/solidity.yml index 0e7ff30545d..6e0233962ef 100644 --- a/.github/workflows/solidity.yml +++ b/.github/workflows/solidity.yml @@ -106,6 +106,8 @@ jobs: uses: ./.github/actions/setup-nodejs - name: Run pnpm lint run: pnpm lint + - name: Run solhint + run: pnpm solhint - name: Collect Metrics id: collect-gha-metrics uses: smartcontractkit/push-gha-metrics-action@d2c2b7bdc9012651230b2608a1bcb0c48538b6ec diff --git a/CODEOWNERS b/CODEOWNERS index e922010aefd..c49affb8aab 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -67,12 +67,12 @@ core/scripts/gateway @bolekk @pinebit /operator-ui/ @DeividasK @jkongie # Contracts -/contracts/ @se3000 @connorwstein +/contracts/ @se3000 @connorwstein @RensR /contracts/**/*Keeper* @smartcontractkit/keepers /contracts/**/*Upkeep* @smartcontractkit/keepers /contracts/**/*Functions* @smartcontractkit/functions /contracts/src/v0.8/functions @smartcontractkit/functions -contracts/test/v0.8/functions @smartcontractkit/functions +/contracts/test/v0.8/functions @smartcontractkit/functions /contracts/src/v0.8/llo-feeds @austinborn @Fletch153 # Tests diff --git a/contracts/.solhint.json b/contracts/.solhint.json index ad3ab97846d..3b69ca6a7f2 100644 --- a/contracts/.solhint.json +++ b/contracts/.solhint.json @@ -1,7 +1,42 @@ { "extends": "solhint:recommended", - "plugins": ["prettier"], + "plugins": ["prettier", "chainlink-solidity"], "rules": { - "prettier/prettier": "error" + "compiler-version": ["off", "^0.8.0"], + "const-name-snakecase": "off", + "constructor-syntax": "error", + "var-name-mixedcase": "off", + "func-named-parameters": "off", + "immutable-vars-naming": "off", + "no-inline-assembly": "off", + "no-unused-import": "error", + "func-visibility": [ + "error", + { + "ignoreConstructors": true + } + ], + "not-rely-on-time": "off", + "prettier/prettier": [ + "off", + { + "endOfLine": "auto" + } + ], + "no-empty-blocks": "off", + "quotes": ["error", "double"], + "reason-string": [ + "warn", + { + "maxLength": 64 + } + ], + "chainlink-solidity/prefix-internal-functions-with-underscore": "warn", + "chainlink-solidity/prefix-private-functions-with-underscore": "warn", + "chainlink-solidity/prefix-storage-variables-with-s-underscore": "warn", + "chainlink-solidity/prefix-immutable-variables-with-i": "warn", + "chainlink-solidity/all-caps-constant-storage-variables": "warn", + "chainlink-solidity/no-hardhat-imports": "warn", + "chainlink-solidity/inherited-constructor-args-not-in-contract-definition": "warn" } } diff --git a/contracts/.solhintignore b/contracts/.solhintignore index c2658d7d1b3..88ad92c6b87 100644 --- a/contracts/.solhintignore +++ b/contracts/.solhintignore @@ -1 +1,32 @@ -node_modules/ +# 368 warnings +#./src/v0.8/automation +# 302 warnings +#./src/v0.8/dev +# 91 warnings +#./src/v0.8/functions +# 91 warnings +#./src/v0.8/l2ep/dev +# 116 warnings +#./src/v0.8/vrf + +# Temp ignore the following files as they contain issues. +./src/v0.8/ChainlinkClient.sol +./src/v0.8/Flags.sol +./src/v0.8/KeepersVRFConsumer.sol +./src/v0.8/PermissionedForwardProxy.sol +./src/v0.8/ValidatorProxy.sol +./src/v0.8/Chainlink.sol +./src/v0.8/ChainSpecificUtil.sol + + +# Ignore tests, this should not be the long term plan but is OK in the short term +./src/v0.8/**/*.t.sol +./src/v0.8/mocks +./src/v0.8/tests +./src/v0.8/llo-feeds/test +./src/v0.8/vrf/testhelpers +./src/v0.8/functions/tests + +# Always ignore vendor +./src/v0.8/vendor +./node_modules/ \ No newline at end of file diff --git a/contracts/package.json b/contracts/package.json index dbe47be5221..65cc873f34f 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -17,7 +17,8 @@ "coverage": "hardhat coverage", "prepublishOnly": "pnpm compile && ./scripts/prepublish_generate_abi_folder", "publish-beta": "pnpm publish --tag beta", - "publish-prod": "npm dist-tag add @chainlink/contracts@0.8.0 latest" + "publish-prod": "npm dist-tag add @chainlink/contracts@0.8.0 latest", + "solhint": "solhint --max-warnings 593 \"./src/v0.8/**/*.sol\"" }, "files": [ "src/", @@ -73,6 +74,7 @@ "prettier-plugin-solidity": "1.1.3", "rlp": "^2.2.7", "solhint": "^3.6.2", + "solhint-plugin-chainlink-solidity": "git+https://github.com/smartcontractkit/chainlink-solhint-rules.git", "solhint-plugin-prettier": "^0.0.5", "solidity-coverage": "^0.8.4", "ts-node": "^10.9.1", diff --git a/contracts/pnpm-lock.yaml b/contracts/pnpm-lock.yaml index b7179be4c60..33b8099a86d 100644 --- a/contracts/pnpm-lock.yaml +++ b/contracts/pnpm-lock.yaml @@ -148,6 +148,9 @@ devDependencies: solhint: specifier: ^3.6.2 version: 3.6.2 + solhint-plugin-chainlink-solidity: + specifier: git+https://github.com/smartcontractkit/chainlink-solhint-rules.git + version: github.com/smartcontractkit/chainlink-solhint-rules/6229ce5d3cc3e4a2454411bebc887c5ca240dcf2 solhint-plugin-prettier: specifier: ^0.0.5 version: 0.0.5(prettier-plugin-solidity@1.1.3)(prettier@3.0.3) @@ -12600,3 +12603,9 @@ packages: bn.js: 4.12.0 ethereumjs-util: 6.2.1 dev: true + + github.com/smartcontractkit/chainlink-solhint-rules/6229ce5d3cc3e4a2454411bebc887c5ca240dcf2: + resolution: {tarball: https://codeload.github.com/smartcontractkit/chainlink-solhint-rules/tar.gz/6229ce5d3cc3e4a2454411bebc887c5ca240dcf2} + name: '@chainlink/solhint-plugin-chainlink-solidity' + version: 1.0.1 + dev: true diff --git a/contracts/scripts/native_solc_compile_all_vrf b/contracts/scripts/native_solc_compile_all_vrf index 49666bde7f6..fd9f1b91539 100755 --- a/contracts/scripts/native_solc_compile_all_vrf +++ b/contracts/scripts/native_solc_compile_all_vrf @@ -54,6 +54,7 @@ compileContract vrf/testhelpers/VRFCoordinatorV2TestHelper.sol compileContractAltOpts vrf/VRFCoordinatorV2.sol 10000 compileContract mocks/VRFCoordinatorV2Mock.sol compileContract vrf/VRFOwner.sol +compileContract dev/VRFSubscriptionBalanceMonitor.sol # VRF V2Plus compileContract dev/interfaces/IVRFCoordinatorV2PlusInternal.sol diff --git a/contracts/src/v0.8/automation/KeeperBase.sol b/contracts/src/v0.8/automation/KeeperBase.sol index 448d4deacea..0e050d4aff3 100644 --- a/contracts/src/v0.8/automation/KeeperBase.sol +++ b/contracts/src/v0.8/automation/KeeperBase.sol @@ -3,4 +3,5 @@ * @notice This is a deprecated interface. Please use AutomationBase directly. */ pragma solidity ^0.8.0; +// solhint-disable-next-line no-unused-import import {AutomationBase as KeeperBase} from "./AutomationBase.sol"; diff --git a/contracts/src/v0.8/automation/KeeperCompatible.sol b/contracts/src/v0.8/automation/KeeperCompatible.sol index f5263eda7b9..6379fe526be 100644 --- a/contracts/src/v0.8/automation/KeeperCompatible.sol +++ b/contracts/src/v0.8/automation/KeeperCompatible.sol @@ -3,6 +3,9 @@ * @notice This is a deprecated interface. Please use AutomationCompatible directly. */ pragma solidity ^0.8.0; +// solhint-disable-next-line no-unused-import import {AutomationCompatible as KeeperCompatible} from "./AutomationCompatible.sol"; +// solhint-disable-next-line no-unused-import import {AutomationBase as KeeperBase} from "./AutomationBase.sol"; +// solhint-disable-next-line no-unused-import import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "./interfaces/AutomationCompatibleInterface.sol"; diff --git a/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol b/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol index d316722313e..b5ba8196c74 100644 --- a/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol +++ b/contracts/src/v0.8/automation/interfaces/KeeperCompatibleInterface.sol @@ -3,4 +3,5 @@ * @notice This is a deprecated interface. Please use AutomationCompatibleInterface directly. */ pragma solidity ^0.8.0; +// solhint-disable-next-line no-unused-import import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "./AutomationCompatibleInterface.sol"; diff --git a/contracts/src/v0.8/automation/interfaces/v1_2/KeeperRegistryInterface1_2.sol b/contracts/src/v0.8/automation/interfaces/v1_2/KeeperRegistryInterface1_2.sol index 124e279ab40..01f70ae9c7d 100644 --- a/contracts/src/v0.8/automation/interfaces/v1_2/KeeperRegistryInterface1_2.sol +++ b/contracts/src/v0.8/automation/interfaces/v1_2/KeeperRegistryInterface1_2.sol @@ -3,7 +3,11 @@ * @notice This is a deprecated interface. Please use AutomationRegistryInterface1_2 directly. */ pragma solidity ^0.8.0; +// solhint-disable-next-line no-unused-import import {Config, State} from "./AutomationRegistryInterface1_2.sol"; +// solhint-disable-next-line no-unused-import import {AutomationRegistryBaseInterface as KeeperRegistryBaseInterface} from "./AutomationRegistryInterface1_2.sol"; +// solhint-disable-next-line no-unused-import import {AutomationRegistryInterface as KeeperRegistryInterface} from "./AutomationRegistryInterface1_2.sol"; +// solhint-disable-next-line no-unused-import import {AutomationRegistryExecutableInterface as KeeperRegistryExecutableInterface} from "./AutomationRegistryInterface1_2.sol"; diff --git a/contracts/src/v0.8/automation/v1_3/KeeperRegistry1_3.sol b/contracts/src/v0.8/automation/v1_3/KeeperRegistry1_3.sol index c40f79f85b4..dbef8d77d19 100644 --- a/contracts/src/v0.8/automation/v1_3/KeeperRegistry1_3.sol +++ b/contracts/src/v0.8/automation/v1_3/KeeperRegistry1_3.sol @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "./KeeperRegistryBase1_3.sol"; import "./KeeperRegistryLogic1_3.sol"; -import {AutomationRegistryExecutableInterface} from "../interfaces/v1_3/AutomationRegistryInterface1_3.sol"; +import {AutomationRegistryExecutableInterface, State} from "../interfaces/v1_3/AutomationRegistryInterface1_3.sol"; import "../interfaces/MigratableKeeperRegistryInterface.sol"; import "../../interfaces/TypeAndVersionInterface.sol"; import "../../shared/interfaces/IERC677Receiver.sol"; diff --git a/contracts/src/v0.8/automation/v1_3/KeeperRegistryBase1_3.sol b/contracts/src/v0.8/automation/v1_3/KeeperRegistryBase1_3.sol index d63f6f40e88..6328b651671 100644 --- a/contracts/src/v0.8/automation/v1_3/KeeperRegistryBase1_3.sol +++ b/contracts/src/v0.8/automation/v1_3/KeeperRegistryBase1_3.sol @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "../../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol"; import "../../vendor/@eth-optimism/contracts/v0.8.6/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; import "../ExecutionPrevention.sol"; -import {Config, State, Upkeep} from "../interfaces/v1_3/AutomationRegistryInterface1_3.sol"; +import {Config, Upkeep} from "../interfaces/v1_3/AutomationRegistryInterface1_3.sol"; import "../../shared/access/ConfirmedOwner.sol"; import "../../interfaces/AggregatorV3Interface.sol"; import "../../shared/interfaces/LinkTokenInterface.sol"; diff --git a/contracts/src/v0.8/automation/v2_0/KeeperRegistry2_0.sol b/contracts/src/v0.8/automation/v2_0/KeeperRegistry2_0.sol index 34781f18258..7db02e72e73 100644 --- a/contracts/src/v0.8/automation/v2_0/KeeperRegistry2_0.sol +++ b/contracts/src/v0.8/automation/v2_0/KeeperRegistry2_0.sol @@ -5,7 +5,7 @@ import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/proxy/Proxy.sol"; import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol"; import "./KeeperRegistryBase2_0.sol"; -import {AutomationRegistryExecutableInterface, UpkeepInfo} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; +import {AutomationRegistryExecutableInterface, UpkeepInfo, State, OnchainConfig, UpkeepFailureReason} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; import "../interfaces/MigratableKeeperRegistryInterface.sol"; import "../interfaces/MigratableKeeperRegistryInterfaceV2.sol"; import "../../shared/interfaces/IERC677Receiver.sol"; diff --git a/contracts/src/v0.8/automation/v2_0/KeeperRegistryBase2_0.sol b/contracts/src/v0.8/automation/v2_0/KeeperRegistryBase2_0.sol index c1e9a279f84..14e9b204475 100644 --- a/contracts/src/v0.8/automation/v2_0/KeeperRegistryBase2_0.sol +++ b/contracts/src/v0.8/automation/v2_0/KeeperRegistryBase2_0.sol @@ -6,7 +6,6 @@ import "../../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol"; import "../../vendor/@eth-optimism/contracts/v0.8.6/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; import {ArbSys} from "../../vendor/@arbitrum/nitro-contracts/src/precompiles/ArbSys.sol"; import "../ExecutionPrevention.sol"; -import {OnchainConfig, State, UpkeepFailureReason} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; import "../../shared/access/ConfirmedOwner.sol"; import "../../interfaces/AggregatorV3Interface.sol"; import "../../shared/interfaces/LinkTokenInterface.sol"; diff --git a/contracts/src/v0.8/automation/v2_0/KeeperRegistryLogic2_0.sol b/contracts/src/v0.8/automation/v2_0/KeeperRegistryLogic2_0.sol index 7e6134a178f..7eacc3cb61e 100644 --- a/contracts/src/v0.8/automation/v2_0/KeeperRegistryLogic2_0.sol +++ b/contracts/src/v0.8/automation/v2_0/KeeperRegistryLogic2_0.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.6; import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol"; import "./KeeperRegistryBase2_0.sol"; +import {UpkeepFailureReason} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; import "../interfaces/MigratableKeeperRegistryInterfaceV2.sol"; import "../interfaces/UpkeepTranscoderInterfaceV2.sol"; diff --git a/contracts/src/v0.8/automation/v2_1/AutomationUtils2_1.sol b/contracts/src/v0.8/automation/v2_1/AutomationUtils2_1.sol index ed19b450d8b..f6ba913b2fb 100644 --- a/contracts/src/v0.8/automation/v2_1/AutomationUtils2_1.sol +++ b/contracts/src/v0.8/automation/v2_1/AutomationUtils2_1.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.16; import {KeeperRegistryBase2_1} from "./KeeperRegistryBase2_1.sol"; -import {ILogAutomation, Log} from "../interfaces/ILogAutomation.sol"; +import {Log} from "../interfaces/ILogAutomation.sol"; /** * @notice this file exposes structs that are otherwise internal to the automation registry diff --git a/contracts/src/v0.8/automation/v2_1/KeeperRegistry2_1.sol b/contracts/src/v0.8/automation/v2_1/KeeperRegistry2_1.sol index bb287c3c731..2f96df6d572 100644 --- a/contracts/src/v0.8/automation/v2_1/KeeperRegistry2_1.sol +++ b/contracts/src/v0.8/automation/v2_1/KeeperRegistry2_1.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; import {Address} from "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol"; -import {Proxy} from "../../vendor/openzeppelin-solidity/v4.7.3/contracts/proxy/Proxy.sol"; import {KeeperRegistryBase2_1} from "./KeeperRegistryBase2_1.sol"; import {KeeperRegistryLogicB2_1} from "./KeeperRegistryLogicB2_1.sol"; import {Chainable} from "../Chainable.sol"; diff --git a/contracts/src/v0.8/automation/v2_1/KeeperRegistryBase2_1.sol b/contracts/src/v0.8/automation/v2_1/KeeperRegistryBase2_1.sol index 86942f3108d..f5d89de5467 100644 --- a/contracts/src/v0.8/automation/v2_1/KeeperRegistryBase2_1.sol +++ b/contracts/src/v0.8/automation/v2_1/KeeperRegistryBase2_1.sol @@ -14,7 +14,7 @@ import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; import {KeeperCompatibleInterface} from "../interfaces/KeeperCompatibleInterface.sol"; -import {UpkeepTranscoderInterface, UpkeepFormat} from "../interfaces/UpkeepTranscoderInterface.sol"; +import {UpkeepFormat} from "../interfaces/UpkeepTranscoderInterface.sol"; /** * @notice Base Keeper Registry contract, contains shared logic between diff --git a/contracts/src/v0.8/automation/v2_1/UpkeepTranscoder4_0.sol b/contracts/src/v0.8/automation/v2_1/UpkeepTranscoder4_0.sol index 727a3dd33ad..53b681d4cc1 100644 --- a/contracts/src/v0.8/automation/v2_1/UpkeepTranscoder4_0.sol +++ b/contracts/src/v0.8/automation/v2_1/UpkeepTranscoder4_0.sol @@ -6,7 +6,6 @@ import {UpkeepTranscoderInterfaceV2} from "../interfaces/UpkeepTranscoderInterfa import {TypeAndVersionInterface} from "../../interfaces/TypeAndVersionInterface.sol"; import {KeeperRegistryBase2_1 as R21} from "./KeeperRegistryBase2_1.sol"; import {IAutomationForwarder} from "../interfaces/IAutomationForwarder.sol"; -import {AutomationRegistryBaseInterface, UpkeepInfo} from "../interfaces/v2_0/AutomationRegistryInterface2_0.sol"; enum RegistryVersion { V12, diff --git a/contracts/src/v0.8/dev/BlockhashStore.sol b/contracts/src/v0.8/dev/BlockhashStore.sol index 74a4fc0ce47..4104be77ed7 100644 --- a/contracts/src/v0.8/dev/BlockhashStore.sol +++ b/contracts/src/v0.8/dev/BlockhashStore.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.6; -import "../ChainSpecificUtil.sol"; +import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; /** * @title BlockhashStore @@ -14,7 +14,7 @@ import "../ChainSpecificUtil.sol"; * would have to be deployed. */ contract BlockhashStore { - mapping(uint => bytes32) internal s_blockhashes; + mapping(uint256 => bytes32) internal s_blockhashes; /** * @notice stores blockhash of a given block, assuming it is available through BLOCKHASH @@ -22,6 +22,7 @@ contract BlockhashStore { */ function store(uint256 n) public { bytes32 h = ChainSpecificUtil.getBlockhash(uint64(n)); + // solhint-disable-next-line custom-errors require(h != 0x0, "blockhash(n) failed"); s_blockhashes[n] = h; } @@ -40,6 +41,7 @@ contract BlockhashStore { * that it hashes to a stored blockhash, and then extract parentHash to get the n-th blockhash. */ function storeVerifyHeader(uint256 n, bytes memory header) public { + // solhint-disable-next-line custom-errors require(keccak256(header) == s_blockhashes[n + 1], "header has unknown blockhash"); // At this point, we know that header is the correct blockheader for block n+1. @@ -72,6 +74,7 @@ contract BlockhashStore { */ function getBlockhash(uint256 n) external view returns (bytes32) { bytes32 h = s_blockhashes[n]; + // solhint-disable-next-line custom-errors require(h != 0x0, "blockhash not found in store"); return h; } diff --git a/contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol b/contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol index b9666eb6a14..81840d26a3e 100644 --- a/contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol +++ b/contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol @@ -96,7 +96,7 @@ pragma solidity ^0.8.4; * @dev and so remains effective only in the case of unmodified oracle software). */ -import "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; /** * @dev The VRFConsumerBaseV2Upgradable is an upgradable variant of VRFConsumerBaseV2 @@ -106,10 +106,12 @@ import "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol" */ abstract contract VRFConsumerBaseV2Upgradeable is Initializable { error OnlyCoordinatorCanFulfill(address have, address want); + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore address private vrfCoordinator; // See https://github.com/OpenZeppelin/openzeppelin-sdk/issues/37. // Each uint256 covers a single storage slot, see https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html. + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore uint256[49] private __gap; /** @@ -117,8 +119,10 @@ abstract contract VRFConsumerBaseV2Upgradeable is Initializable { * @dev See https://docs.chain.link/docs/vrf/v2/supported-networks/ for coordinator * @dev addresses on your preferred network. */ + // solhint-disable-next-line func-name-mixedcase function __VRFConsumerBaseV2_init(address _vrfCoordinator) internal onlyInitializing { if (_vrfCoordinator == address(0)) { + // solhint-disable-next-line custom-errors revert("must give valid coordinator address"); } @@ -139,6 +143,7 @@ abstract contract VRFConsumerBaseV2Upgradeable is Initializable { * @param requestId The Id initially returned by requestRandomness * @param randomWords the VRF output expanded to the requested number of words */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual; // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF diff --git a/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol b/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol index 91124709742..958ecdc1bad 100644 --- a/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol +++ b/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol @@ -2,11 +2,11 @@ pragma solidity 0.8.6; -import "../shared/access/ConfirmedOwner.sol"; -import "../automation/interfaces/KeeperCompatibleInterface.sol"; -import "../interfaces/VRFCoordinatorV2Interface.sol"; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "@openzeppelin/contracts/security/Pausable.sol"; +import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; +import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "../automation/interfaces/AutomationCompatibleInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; +import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; /** * @title The VRFSubscriptionBalanceMonitor contract. @@ -197,6 +197,7 @@ contract VRFSubscriptionBalanceMonitor is ConfirmedOwner, Pausable, KeeperCompat * @param payee the address to pay */ function withdraw(uint256 amount, address payable payee) external onlyOwner { + // solhint-disable-next-line custom-errors, reason-string require(payee != address(0)); emit FundsWithdrawn(amount, payee); LINKTOKEN.transfer(payee, amount); @@ -206,6 +207,7 @@ contract VRFSubscriptionBalanceMonitor is ConfirmedOwner, Pausable, KeeperCompat * @notice Sets the LINK token address. */ function setLinkTokenAddress(address linkTokenAddress) public onlyOwner { + // solhint-disable-next-line custom-errors, reason-string require(linkTokenAddress != address(0)); emit LinkTokenAddressUpdated(address(LINKTOKEN), linkTokenAddress); LINKTOKEN = LinkTokenInterface(linkTokenAddress); @@ -215,6 +217,7 @@ contract VRFSubscriptionBalanceMonitor is ConfirmedOwner, Pausable, KeeperCompat * @notice Sets the VRF coordinator address. */ function setVRFCoordinatorV2Address(address coordinatorAddress) public onlyOwner { + // solhint-disable-next-line custom-errors, reason-string require(coordinatorAddress != address(0)); emit VRFCoordinatorV2AddressUpdated(address(COORDINATOR), coordinatorAddress); COORDINATOR = VRFCoordinatorV2Interface(coordinatorAddress); @@ -224,6 +227,7 @@ contract VRFSubscriptionBalanceMonitor is ConfirmedOwner, Pausable, KeeperCompat * @notice Sets the keeper registry address. */ function setKeeperRegistryAddress(address keeperRegistryAddress) public onlyOwner { + // solhint-disable-next-line custom-errors, reason-string require(keeperRegistryAddress != address(0)); emit KeeperRegistryAddressUpdated(s_keeperRegistryAddress, keeperRegistryAddress); s_keeperRegistryAddress = keeperRegistryAddress; diff --git a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol b/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol index 0608340e674..20c60b593da 100644 --- a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol +++ b/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../vrf/libraries/VRFV2PlusClient.sol"; -import "./IVRFSubscriptionV2Plus.sol"; +import {VRFV2PlusClient} from "../vrf/libraries/VRFV2PlusClient.sol"; +import {IVRFSubscriptionV2Plus} from "./IVRFSubscriptionV2Plus.sol"; // Interface that enables consumers of VRFCoordinatorV2Plus to be future-proof for upgrades // This interface is supported by subsequent versions of VRFCoordinatorV2Plus diff --git a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol b/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol index 9892b88e691..e8fba69fc45 100644 --- a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol +++ b/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./IVRFCoordinatorV2Plus.sol"; + +import {IVRFCoordinatorV2Plus} from "./IVRFCoordinatorV2Plus.sol"; // IVRFCoordinatorV2PlusInternal is the interface used by chainlink core and should // not be used by consumer conracts @@ -51,9 +52,11 @@ interface IVRFCoordinatorV2PlusInternal is IVRFCoordinatorV2Plus { uint256 zInv; } + // solhint-disable-next-line func-name-mixedcase function s_requestCommitments(uint256 requestID) external view returns (bytes32); function fulfillRandomWords(Proof memory proof, RequestCommitment memory rc) external returns (uint96); + // solhint-disable-next-line func-name-mixedcase function LINK_NATIVE_FEED() external view returns (address); } diff --git a/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol b/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol index c08ac5dd0a4..9247cc21dd5 100644 --- a/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol +++ b/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT +// solhint-disable-next-line one-contract-per-file pragma solidity 0.8.6; -import "../../vrf/VRFTypes.sol"; +import {VRFTypes} from "../../vrf/VRFTypes.sol"; /** * @title BatchVRFCoordinatorV2Plus @@ -9,6 +10,7 @@ import "../../vrf/VRFTypes.sol"; * @notice provided VRFCoordinatorV2Plus contract efficiently in a single transaction. */ contract BatchVRFCoordinatorV2Plus { + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i IVRFCoordinatorV2Plus public immutable COORDINATOR; event ErrorReturned(uint256 indexed requestId, string reason); @@ -24,6 +26,7 @@ contract BatchVRFCoordinatorV2Plus { * @param rcs the request commitments corresponding to the randomness proofs. */ function fulfillRandomWords(VRFTypes.Proof[] memory proofs, VRFTypes.RequestCommitmentV2Plus[] memory rcs) external { + // solhint-disable-next-line custom-errors require(proofs.length == rcs.length, "input array arg lengths mismatch"); for (uint256 i = 0; i < proofs.length; i++) { try COORDINATOR.fulfillRandomWords(proofs[i], rcs[i]) returns (uint96 /* payment */) { @@ -42,6 +45,7 @@ contract BatchVRFCoordinatorV2Plus { * @notice Returns the proving key hash associated with this public key. * @param publicKey the key to return the hash of. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function hashOfKey(uint256[2] memory publicKey) internal pure returns (bytes32) { return keccak256(abi.encode(publicKey)); } @@ -50,6 +54,7 @@ contract BatchVRFCoordinatorV2Plus { * @notice Returns the request ID of the request associated with the given proof. * @param proof the VRF proof provided by the VRF oracle. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function getRequestIdFromProof(VRFTypes.Proof memory proof) internal pure returns (uint256) { bytes32 keyHash = hashOfKey(proof.pk); return uint256(keccak256(abi.encode(keyHash, proof.seed))); diff --git a/contracts/src/v0.8/dev/vrf/BlockhashStore.sol b/contracts/src/v0.8/dev/vrf/BlockhashStore.sol index 107746f8019..ad445595ff8 100644 --- a/contracts/src/v0.8/dev/vrf/BlockhashStore.sol +++ b/contracts/src/v0.8/dev/vrf/BlockhashStore.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.6; -import "../../ChainSpecificUtil.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; /** * @title BlockhashStore @@ -14,7 +14,7 @@ import "../../ChainSpecificUtil.sol"; * would have to be deployed. */ contract BlockhashStore { - mapping(uint => bytes32) internal s_blockhashes; + mapping(uint256 => bytes32) internal s_blockhashes; /** * @notice stores blockhash of a given block, assuming it is available through BLOCKHASH @@ -22,6 +22,7 @@ contract BlockhashStore { */ function store(uint256 n) public { bytes32 h = ChainSpecificUtil.getBlockhash(uint64(n)); + // solhint-disable-next-line custom-errors require(h != 0x0, "blockhash(n) failed"); s_blockhashes[n] = h; } @@ -40,6 +41,7 @@ contract BlockhashStore { * that it hashes to a stored blockhash, and then extract parentHash to get the n-th blockhash. */ function storeVerifyHeader(uint256 n, bytes memory header) public { + // solhint-disable-next-line custom-errors require(keccak256(header) == s_blockhashes[n + 1], "header has unknown blockhash"); // At this point, we know that header is the correct blockheader for block n+1. @@ -72,6 +74,7 @@ contract BlockhashStore { */ function getBlockhash(uint256 n) external view returns (bytes32) { bytes32 h = s_blockhashes[n]; + // solhint-disable-next-line custom-errors require(h != 0x0, "blockhash not found in store"); return h; } diff --git a/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol b/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol index c4781cbde8c..d79b6daf844 100644 --- a/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol +++ b/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../shared/access/ConfirmedOwner.sol"; -import "../../interfaces/AggregatorV3Interface.sol"; -import "../../shared/interfaces/IERC677Receiver.sol"; -import "../interfaces/IVRFSubscriptionV2Plus.sol"; +import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; +import {IERC677Receiver} from "../../shared/interfaces/IERC677Receiver.sol"; +import {IVRFSubscriptionV2Plus} from "../interfaces/IVRFSubscriptionV2Plus.sol"; abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscriptionV2Plus { using EnumerableSet for EnumerableSet.UintSet; @@ -392,6 +392,7 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr emit SubscriptionConsumerAdded(subId, consumer); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function deleteSubscription(uint256 subId) internal returns (uint96 balance, uint96 nativeBalance) { SubscriptionConfig memory subConfig = s_subscriptionConfigs[subId]; Subscription memory sub = s_subscriptions[subId]; @@ -410,6 +411,7 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr return (balance, nativeBalance); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function cancelSubscriptionHelper(uint256 subId, address to) internal { (uint96 balance, uint96 nativeBalance) = deleteSubscription(subId); diff --git a/contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol b/contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol index bbbc08f3a22..d084ea5c8eb 100644 --- a/contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol +++ b/contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.6; -import "../../ChainSpecificUtil.sol"; -import "../../shared/access/ConfirmedOwner.sol"; -import "./BlockhashStore.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {BlockhashStore} from "./BlockhashStore.sol"; contract TrustedBlockhashStore is ConfirmedOwner, BlockhashStore { error NotInWhitelist(); diff --git a/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol b/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol index 0e6e2b22016..c256630f7c6 100644 --- a/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol +++ b/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../interfaces/IVRFMigratableConsumerV2Plus.sol"; -import "../../shared/access/ConfirmedOwner.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFMigratableConsumerV2Plus} from "../interfaces/IVRFMigratableConsumerV2Plus.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; /** **************************************************************************** * @notice Interface for contracts using VRF randomness @@ -126,6 +126,7 @@ abstract contract VRFConsumerBaseV2Plus is IVRFMigratableConsumerV2Plus, Confirm * @param requestId The Id initially returned by requestRandomness * @param randomWords the VRF output expanded to the requested number of words */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual; // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF diff --git a/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol b/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol index 3cd5d05e6e8..d69fa38c096 100644 --- a/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol +++ b/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol @@ -1,19 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/BlockhashStoreInterface.sol"; -import "../../interfaces/TypeAndVersionInterface.sol"; -import "../../vrf/VRF.sol"; -import "./VRFConsumerBaseV2Plus.sol"; -import "../../ChainSpecificUtil.sol"; -import "./SubscriptionAPI.sol"; -import "./libraries/VRFV2PlusClient.sol"; -import "../interfaces/IVRFCoordinatorV2PlusMigration.sol"; -import "../interfaces/IVRFCoordinatorV2Plus.sol"; - +import {BlockhashStoreInterface} from "../../interfaces/BlockhashStoreInterface.sol"; +import {VRF} from "../../vrf/VRF.sol"; +import {VRFConsumerBaseV2Plus, IVRFMigratableConsumerV2Plus} from "./VRFConsumerBaseV2Plus.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; +import {SubscriptionAPI} from "./SubscriptionAPI.sol"; +import {VRFV2PlusClient} from "./libraries/VRFV2PlusClient.sol"; +import {IVRFCoordinatorV2PlusMigration} from "../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +// solhint-disable-next-line no-unused-import +import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; + +// solhint-disable-next-line contract-name-camelcase contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { /// @dev should always be available + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i BlockhashStoreInterface public immutable BLOCKHASH_STORE; // Set this maximum to 200 to give us a 56 block window to fulfill @@ -299,6 +300,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { return requestId; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function computeRequestId( bytes32 keyHash, address sender, @@ -313,8 +315,8 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow @@ -349,6 +351,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { uint256 randomness; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function getRandomnessFromProof( Proof memory proof, RequestCommitment memory rc @@ -452,6 +455,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { } } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmount( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -476,6 +480,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { ); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmountNative( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -493,6 +498,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { } // Get the amount of gas used for fulfillment + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmountLink( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -516,6 +522,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { return uint96(paymentNoFee + fee); } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getFeedData() private view returns (int256) { uint32 stalenessSeconds = s_config.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; @@ -620,6 +627,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { uint96 nativeBalance; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function isTargetRegistered(address target) internal view returns (bool) { for (uint256 i = 0; i < s_migrationTargets.length; i++) { if (s_migrationTargets[i] == target) { @@ -656,7 +664,9 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { revert CoordinatorNotRegistered(newCoordinator); } (uint96 balance, uint96 nativeBalance, , address owner, address[] memory consumers) = getSubscription(subId); + // solhint-disable-next-line custom-errors require(owner == msg.sender, "Not subscription owner"); + // solhint-disable-next-line custom-errors require(!pendingRequestExists(subId), "Pending request exists"); V1MigrationData memory migrationData = V1MigrationData({ @@ -673,6 +683,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { // Only transfer LINK if the token is active and there is a balance. if (address(LINK) != address(0) && balance != 0) { + // solhint-disable-next-line custom-errors require(LINK.transfer(address(newCoordinator), balance), "insufficient funds"); } diff --git a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol b/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol index fb6d9ee0243..8021f048989 100644 --- a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol +++ b/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol @@ -1,20 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../../shared/access/ConfirmedOwner.sol"; -import "../../interfaces/TypeAndVersionInterface.sol"; -import "./VRFConsumerBaseV2Plus.sol"; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/AggregatorV3Interface.sol"; -import "../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../interfaces/IVRFV2PlusWrapper.sol"; -import "./VRFV2PlusWrapperConsumerBase.sol"; -import "../../ChainSpecificUtil.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {TypeAndVersionInterface} from "../../interfaces/TypeAndVersionInterface.sol"; +import {VRFConsumerBaseV2Plus} from "./VRFConsumerBaseV2Plus.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; +import {VRFV2PlusClient} from "./libraries/VRFV2PlusClient.sol"; +import {IVRFV2PlusWrapper} from "../interfaces/IVRFV2PlusWrapper.sol"; +import {VRFV2PlusWrapperConsumerBase} from "./VRFV2PlusWrapperConsumerBase.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; /** * @notice A wrapper for VRFCoordinatorV2 that provides an interface better suited to one-off * @notice requests for randomness. */ +// solhint-disable-next-line max-states-count contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBaseV2Plus, IVRFV2PlusWrapper { event WrapperFulfillmentFailed(uint256 indexed requestId, address indexed consumer); @@ -27,10 +28,11 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume /* Storage Slot 1: BEGIN */ // s_keyHash is the key hash to use when requesting randomness. Fees are paid based on current gas // fees, so this should be set to the highest gas lane on the network. - bytes32 s_keyHash; + bytes32 internal s_keyHash; /* Storage Slot 1: END */ /* Storage Slot 2: BEGIN */ + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i uint256 public immutable SUBSCRIPTION_ID; /* Storage Slot 2: END */ @@ -106,7 +108,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume uint8 private s_wrapperPremiumPercentage; // s_maxNumWords is the max number of words that can be requested in a single wrapped VRF request. - uint8 s_maxNumWords; + uint8 internal s_maxNumWords; uint16 private constant EXPECTED_MIN_LENGTH = 36; /* Storage Slot 8: END */ @@ -307,6 +309,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume return calculateRequestPriceNativeInternal(_callbackGasLimit, _requestGasPriceWei); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculateRequestPriceNativeInternal(uint256 _gas, uint256 _requestGasPrice) internal view returns (uint256) { // costWei is the base fee denominated in wei (native) // costWei takes into account the L1 posting costs of the VRF fulfillment @@ -325,6 +328,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume return feeWithFlatFee; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculateRequestPriceInternal( uint256 _gas, uint256 _requestGasPrice, @@ -361,6 +365,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume * uint16 requestConfirmations, and uint32 numWords. */ function onTokenTransfer(address _sender, uint256 _amount, bytes calldata _data) external onlyConfiguredNotDisabled { + // solhint-disable-next-line custom-errors require(msg.sender == address(s_link), "only callable from LINK"); (uint32 callbackGasLimit, uint16 requestConfirmations, uint32 numWords, bytes memory extraArgs) = abi.decode( @@ -371,7 +376,9 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume uint32 eip150Overhead = getEIP150Overhead(callbackGasLimit); int256 weiPerUnitLink = getFeedData(); uint256 price = calculateRequestPriceInternal(callbackGasLimit, tx.gasprice, weiPerUnitLink); + // solhint-disable-next-line custom-errors require(_amount >= price, "fee too low"); + // solhint-disable-next-line custom-errors require(numWords <= s_maxNumWords, "numWords too high"); VRFV2PlusClient.RandomWordsRequest memory req = VRFV2PlusClient.RandomWordsRequest({ keyHash: s_keyHash, @@ -424,7 +431,9 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume uint32 eip150Overhead = getEIP150Overhead(_callbackGasLimit); uint256 price = calculateRequestPriceNativeInternal(_callbackGasLimit, tx.gasprice); + // solhint-disable-next-line custom-errors require(msg.value >= price, "fee too low"); + // solhint-disable-next-line custom-errors require(_numWords <= s_maxNumWords, "numWords too high"); VRFV2PlusClient.RandomWordsRequest memory req = VRFV2PlusClient.RandomWordsRequest({ keyHash: s_keyHash, @@ -466,6 +475,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume */ function withdrawNative(address _recipient, uint256 _amount) external onlyOwner { (bool success, ) = payable(_recipient).call{value: _amount}(""); + // solhint-disable-next-line custom-errors require(success, "failed to withdraw native"); } @@ -484,9 +494,11 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume s_disabled = true; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { Callback memory callback = s_callbacks[_requestId]; delete s_callbacks[_requestId]; + // solhint-disable-next-line custom-errors require(callback.callbackAddress != address(0), "request not found"); // This should never happen VRFV2PlusWrapperConsumerBase c; @@ -498,6 +510,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume } } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getFeedData() private view returns (int256) { bool staleFallback = s_stalenessSeconds > 0; uint256 timestamp; @@ -507,6 +520,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume if (staleFallback && s_stalenessSeconds < block.timestamp - timestamp) { weiPerUnitLink = s_fallbackWeiPerUnitLink; } + // solhint-disable-next-line custom-errors require(weiPerUnitLink >= 0, "Invalid LINK wei price"); return weiPerUnitLink; } @@ -514,6 +528,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume /** * @dev Calculates extra amount of gas required for running an assembly call() post-EIP150. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getEIP150Overhead(uint32 gas) private pure returns (uint32) { return gas / 63 + 1; } @@ -522,8 +537,8 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow @@ -557,7 +572,9 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume } modifier onlyConfiguredNotDisabled() { + // solhint-disable-next-line custom-errors require(s_configured, "wrapper is not configured"); + // solhint-disable-next-line custom-errors require(!s_disabled, "wrapper is disabled"); _; } diff --git a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol b/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol index c96623d28ef..e800753af2b 100644 --- a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol +++ b/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../interfaces/IVRFV2PlusWrapper.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFV2PlusWrapper} from "../interfaces/IVRFV2PlusWrapper.sol"; /** * @@ -31,7 +31,9 @@ import "../interfaces/IVRFV2PlusWrapper.sol"; abstract contract VRFV2PlusWrapperConsumerBase { error LINKAlreadySet(); + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore LinkTokenInterface internal LINK; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore IVRFV2PlusWrapper internal VRF_V2_PLUS_WRAPPER; /** @@ -70,6 +72,7 @@ abstract contract VRFV2PlusWrapperConsumerBase { * * @return requestId is the VRF V2+ request ID of the newly created randomness request. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function requestRandomness( uint32 _callbackGasLimit, uint16 _requestConfirmations, @@ -84,6 +87,7 @@ abstract contract VRFV2PlusWrapperConsumerBase { return VRF_V2_PLUS_WRAPPER.lastRequestId(); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function requestRandomnessPayInNative( uint32 _callbackGasLimit, uint16 _requestConfirmations, @@ -107,9 +111,11 @@ abstract contract VRFV2PlusWrapperConsumerBase { * @param _requestId is the VRF V2 request ID. * @param _randomWords is the randomness result. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual; function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external { + // solhint-disable-next-line custom-errors require(msg.sender == address(VRF_V2_PLUS_WRAPPER), "only VRF V2 Plus wrapper can fulfill"); fulfillRandomWords(_requestId, _randomWords); } diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol b/contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol index 5e54636bb17..f9c34b2b611 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../../../vrf/VRF.sol"; import {VRFCoordinatorV2_5} from "../VRFCoordinatorV2_5.sol"; -import "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; +import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; +// solhint-disable-next-line contract-name-camelcase contract ExposedVRFCoordinatorV2_5 is VRFCoordinatorV2_5 { using EnumerableSet for EnumerableSet.UintSet; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol index 7b34f96e376..1211014cd2f 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../../VRFConsumerBaseV2Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Upgradeable} from "../../VRFConsumerBaseV2Upgradeable.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; contract VRFConsumerV2PlusUpgradeableExample is Initializable, VRFConsumerBaseV2Upgradeable { uint256[] public s_randomWords; @@ -20,7 +21,9 @@ contract VRFConsumerV2PlusUpgradeableExample is Initializable, VRFConsumerBaseV2 LINKTOKEN = LinkTokenInterface(_link); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { + // solhint-disable-next-line custom-errors require(requestId == s_requestId, "request ID is incorrect"); s_gasAvailable = gasleft(); @@ -37,12 +40,14 @@ contract VRFConsumerV2PlusUpgradeableExample is Initializable, VRFConsumerBaseV2 } function topUpSubscription(uint96 amount) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "sub not set"); // Approve the link transfer. LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subId)); } function updateSubscription(address[] memory consumers) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "subID not set"); for (uint256 i = 0; i < consumers.length; i++) { COORDINATOR.addConsumer(s_subId, consumers[i]); diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol index 94017adde73..07b55388e10 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol @@ -1,17 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../../interfaces/BlockhashStoreInterface.sol"; -import "../../../interfaces/TypeAndVersionInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../../../vrf/VRF.sol"; -import "../VRFConsumerBaseV2Plus.sol"; -import "../../../ChainSpecificUtil.sol"; -import "../SubscriptionAPI.sol"; -import "../libraries/VRFV2PlusClient.sol"; -import "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; -import "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; +import {BlockhashStoreInterface} from "../../../interfaces/BlockhashStoreInterface.sol"; +// solhint-disable-next-line no-unused-import +import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRF} from "../../../vrf/VRF.sol"; +import {VRFConsumerBaseV2Plus, IVRFMigratableConsumerV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {ChainSpecificUtil} from "../../../ChainSpecificUtil.sol"; +import {SubscriptionAPI} from "../SubscriptionAPI.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; +import {IVRFCoordinatorV2PlusMigration} from "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; contract VRFCoordinatorV2PlusUpgradedVersion is VRF, @@ -21,6 +20,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is { using EnumerableSet for EnumerableSet.UintSet; /// @dev should always be available + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i BlockhashStoreInterface public immutable BLOCKHASH_STORE; // Set this maximum to 200 to give us a 56 block window to fulfill @@ -291,6 +291,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is return requestId; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function computeRequestId( bytes32 keyHash, address sender, @@ -305,8 +306,8 @@ contract VRFCoordinatorV2PlusUpgradedVersion is * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow @@ -341,6 +342,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is uint256 randomness; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function getRandomnessFromProof( Proof memory proof, RequestCommitment memory rc @@ -444,6 +446,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is } } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmount( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -468,6 +471,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is ); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmountNative( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -485,6 +489,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is } // Get the amount of gas used for fulfillment + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmountLink( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -508,6 +513,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is return uint96(paymentNoFee + fee); } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getFeedData() private view returns (int256) { uint32 stalenessSeconds = s_config.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; @@ -615,6 +621,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is uint96 nativeBalance; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function isTargetRegistered(address target) internal view returns (bool) { for (uint256 i = 0; i < s_migrationTargets.length; i++) { if (s_migrationTargets[i] == target) { @@ -637,7 +644,9 @@ contract VRFCoordinatorV2PlusUpgradedVersion is revert CoordinatorNotRegistered(newCoordinator); } (uint96 balance, uint96 nativeBalance, , address owner, address[] memory consumers) = getSubscription(subId); + // solhint-disable-next-line custom-errors require(owner == msg.sender, "Not subscription owner"); + // solhint-disable-next-line custom-errors require(!pendingRequestExists(subId), "Pending request exists"); V1MigrationData memory migrationData = V1MigrationData({ @@ -654,6 +663,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is // Only transfer LINK if the token is active and there is a balance. if (address(LINK) != address(0) && balance != 0) { + // solhint-disable-next-line custom-errors require(LINK.transfer(address(newCoordinator), balance), "insufficient funds"); } @@ -698,7 +708,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is revert SubscriptionIDCollisionFound(); } - for (uint i = 0; i < migrationData.consumers.length; i++) { + for (uint256 i = 0; i < migrationData.consumers.length; i++) { s_consumers[migrationData.consumers[i]][migrationData.subId] = 1; } diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol index 52a5b864c6b..7306931570a 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; +import {IVRFCoordinatorV2PlusMigration} from "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; /// @dev this contract is only meant for testing migration /// @dev it is a simplified example of future version (V2) of VRFCoordinatorV2Plus +// solhint-disable-next-line contract-name-camelcase contract VRFCoordinatorV2Plus_V2Example is IVRFCoordinatorV2PlusMigration { error SubscriptionIDCollisionFound(); @@ -138,6 +138,7 @@ contract VRFCoordinatorV2Plus_V2Example is IVRFCoordinatorV2PlusMigration { return handleRequest(msg.sender); } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function handleRequest(address requester) private returns (uint256) { s_requestId = s_requestId + 1; uint256 requestId = s_requestId; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol index 11e899ae659..cc3e465bc0c 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol @@ -1,24 +1,28 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; contract VRFMaliciousConsumerV2Plus is VRFConsumerBaseV2Plus { uint256[] public s_randomWords; uint256 public s_requestId; - IVRFCoordinatorV2Plus COORDINATOR; - LinkTokenInterface LINKTOKEN; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + IVRFCoordinatorV2Plus internal COORDINATOR; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + LinkTokenInterface internal LINKTOKEN; uint256 public s_gasAvailable; - uint256 s_subId; - bytes32 s_keyHash; + uint256 internal s_subId; + bytes32 internal s_keyHash; constructor(address vrfCoordinator, address link) VRFConsumerBaseV2Plus(vrfCoordinator) { COORDINATOR = IVRFCoordinatorV2Plus(vrfCoordinator); LINKTOKEN = LinkTokenInterface(link); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { s_gasAvailable = gasleft(); s_randomWords = randomWords; @@ -45,6 +49,7 @@ contract VRFMaliciousConsumerV2Plus is VRFConsumerBaseV2Plus { } function updateSubscription(address[] memory consumers) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "subID not set"); for (uint256 i = 0; i < consumers.length; i++) { COORDINATOR.addConsumer(s_subId, consumers[i]); diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol index 948cc17b3f3..8acc0ce6d0b 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; -import "../../../shared/access/ConfirmedOwner.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; /// @notice This contract is used for testing only and should not be used for production. contract VRFV2PlusConsumerExample is ConfirmedOwner, VRFConsumerBaseV2Plus { @@ -28,10 +29,12 @@ contract VRFV2PlusConsumerExample is ConfirmedOwner, VRFConsumerBaseV2Plus { function getRandomness(uint256 requestId, uint256 idx) public view returns (uint256 randomWord) { Response memory resp = s_requests[requestId]; + // solhint-disable-next-line custom-errors require(resp.requestId != 0, "request ID is incorrect"); return resp.randomWords[idx]; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function subscribe() internal returns (uint256) { if (s_subId == 0) { s_subId = s_vrfCoordinatorApiV1.createSubscription(); @@ -52,16 +55,20 @@ contract VRFV2PlusConsumerExample is ConfirmedOwner, VRFConsumerBaseV2Plus { } function topUpSubscription(uint96 amount) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "sub not set"); s_linkToken.transferAndCall(address(s_vrfCoordinator), amount, abi.encode(s_subId)); } function topUpSubscriptionNative() external payable { + // solhint-disable-next-line custom-errors require(s_subId != 0, "sub not set"); s_vrfCoordinatorApiV1.fundSubscriptionWithNative{value: msg.value}(s_subId); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { + // solhint-disable-next-line custom-errors require(requestId == s_recentRequestId, "request ID is incorrect"); s_requests[requestId].randomWords = randomWords; s_requests[requestId].fulfilled = true; @@ -94,6 +101,7 @@ contract VRFV2PlusConsumerExample is ConfirmedOwner, VRFConsumerBaseV2Plus { } function updateSubscription(address[] memory consumers) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "subID not set"); for (uint256 i = 0; i < consumers.length; i++) { s_vrfCoordinatorApiV1.addConsumer(s_subId, consumers[i]); diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol index 2b9ac5713cc..384a5890018 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol @@ -1,18 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; /// @notice This contract is used for testing only and should not be used for production. contract VRFV2PlusExternalSubOwnerExample is VRFConsumerBaseV2Plus { - IVRFCoordinatorV2Plus COORDINATOR; - LinkTokenInterface LINKTOKEN; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + IVRFCoordinatorV2Plus internal COORDINATOR; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + LinkTokenInterface internal LINKTOKEN; uint256[] public s_randomWords; uint256 public s_requestId; - address s_owner; + address internal s_owner; constructor(address vrfCoordinator, address link) VRFConsumerBaseV2Plus(vrfCoordinator) { COORDINATOR = IVRFCoordinatorV2Plus(vrfCoordinator); @@ -20,7 +23,9 @@ contract VRFV2PlusExternalSubOwnerExample is VRFConsumerBaseV2Plus { s_owner = msg.sender; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { + // solhint-disable-next-line custom-errors require(requestId == s_requestId, "request ID is incorrect"); s_randomWords = randomWords; } diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol index 42296ae6bf4..ad09f88fd2f 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol @@ -1,10 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../ChainSpecificUtil.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; -import "../../../shared/access/ConfirmedOwner.sol"; +import {ChainSpecificUtil} from "../../../ChainSpecificUtil.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; /** * @title The VRFLoadTestExternalSubOwner contract. @@ -17,13 +16,14 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus { uint256 public s_slowestFulfillment = 0; uint256 public s_fastestFulfillment = 999; uint256 public s_lastRequestId; - mapping(uint256 => uint256) requestHeights; // requestIds to block number when rand request was made + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + mapping(uint256 => uint256) internal requestHeights; // requestIds to block number when rand request was made struct RequestStatus { bool fulfilled; uint256[] randomWords; - uint requestTimestamp; - uint fulfilmentTimestamp; + uint256 requestTimestamp; + uint256 fulfilmentTimestamp; uint256 requestBlockNumber; uint256 fulfilmentBlockNumber; } @@ -32,6 +32,7 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus { constructor(address _vrfCoordinator) VRFConsumerBaseV2Plus(_vrfCoordinator) {} + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { uint256 fulfilmentBlockNumber = ChainSpecificUtil.getBlockNumber(); uint256 requestDelay = fulfilmentBlockNumber - requestHeights[_requestId]; @@ -105,8 +106,8 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus { returns ( bool fulfilled, uint256[] memory randomWords, - uint requestTimestamp, - uint fulfilmentTimestamp, + uint256 requestTimestamp, + uint256 fulfilmentTimestamp, uint256 requestBlockNumber, uint256 fulfilmentBlockNumber ) diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol index b1dca81ebdf..2be0024ae71 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import "../../interfaces/IVRFMigratableConsumerV2Plus.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../libraries/VRFV2PlusClient.sol"; +import {IVRFMigratableConsumerV2Plus} from "../../interfaces/IVRFMigratableConsumerV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; contract VRFV2PlusMaliciousMigrator is IVRFMigratableConsumerV2Plus { - IVRFCoordinatorV2Plus s_vrfCoordinator; + IVRFCoordinatorV2Plus internal s_vrfCoordinator; constructor(address _vrfCoordinator) { s_vrfCoordinator = IVRFCoordinatorV2Plus(_vrfCoordinator); @@ -15,7 +15,7 @@ contract VRFV2PlusMaliciousMigrator is IVRFMigratableConsumerV2Plus { /** * @inheritdoc IVRFMigratableConsumerV2Plus */ - function setCoordinator(address _vrfCoordinator) public override { + function setCoordinator(address /* _vrfCoordinator */) public override { // try to re-enter, should revert // args don't really matter s_vrfCoordinator.requestRandomWords( diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol index 36063533586..170ff9dd6e9 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol @@ -1,16 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; // VRFV2RevertingExample will always revert. Used for testing only, useless in prod. contract VRFV2PlusRevertingExample is VRFConsumerBaseV2Plus { uint256[] public s_randomWords; uint256 public s_requestId; - IVRFCoordinatorV2Plus COORDINATOR; - LinkTokenInterface LINKTOKEN; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + IVRFCoordinatorV2Plus internal COORDINATOR; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + LinkTokenInterface internal LINKTOKEN; uint256 public s_subId; uint256 public s_gasAvailable; @@ -19,7 +22,9 @@ contract VRFV2PlusRevertingExample is VRFConsumerBaseV2Plus { LINKTOKEN = LinkTokenInterface(link); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256, uint256[] memory) internal pure override { + // solhint-disable-next-line custom-errors, reason-string revert(); } @@ -33,12 +38,14 @@ contract VRFV2PlusRevertingExample is VRFConsumerBaseV2Plus { } function topUpSubscription(uint96 amount) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "sub not set"); // Approve the link transfer. LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subId)); } function updateSubscription(address[] memory consumers) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "subID not set"); for (uint256 i = 0; i < consumers.length; i++) { COORDINATOR.addConsumer(s_subId, consumers[i]); diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol index e4cd9ae29ad..b190ebc8715 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol @@ -2,14 +2,17 @@ // Example of a single consumer contract which owns the subscription. pragma solidity ^0.8.0; -import "../../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import "../VRFConsumerBaseV2Plus.sol"; +import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; +import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; /// @notice This contract is used for testing only and should not be used for production. contract VRFV2PlusSingleConsumerExample is VRFConsumerBaseV2Plus { - IVRFCoordinatorV2Plus COORDINATOR; - LinkTokenInterface LINKTOKEN; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + IVRFCoordinatorV2Plus internal COORDINATOR; + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + LinkTokenInterface internal LINKTOKEN; struct RequestConfig { uint256 subId; @@ -22,7 +25,7 @@ contract VRFV2PlusSingleConsumerExample is VRFConsumerBaseV2Plus { RequestConfig public s_requestConfig; uint256[] public s_randomWords; uint256 public s_requestId; - address s_owner; + address internal s_owner; constructor( address vrfCoordinator, @@ -47,7 +50,9 @@ contract VRFV2PlusSingleConsumerExample is VRFConsumerBaseV2Plus { subscribe(); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { + // solhint-disable-next-line custom-errors require(requestId == s_requestId, "request ID is incorrect"); s_randomWords = randomWords; } diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol index 206d56ea321..5285eee9463 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../VRFV2PlusWrapperConsumerBase.sol"; -import "../../../shared/access/ConfirmedOwner.sol"; +import {VRFV2PlusWrapperConsumerBase} from "../VRFV2PlusWrapperConsumerBase.sol"; +import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, ConfirmedOwner { @@ -49,7 +49,9 @@ contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, Confir return requestId; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); s_requests[_requestId].fulfilled = true; s_requests[_requestId].randomWords = _randomWords; @@ -59,6 +61,7 @@ contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, Confir function getRequestStatus( uint256 _requestId ) external view returns (uint256 paid, bool fulfilled, uint256[] memory randomWords) { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); RequestStatus memory request = s_requests[_requestId]; return (request.paid, request.fulfilled, request.randomWords); @@ -74,6 +77,7 @@ contract VRFV2PlusWrapperConsumerExample is VRFV2PlusWrapperConsumerBase, Confir /// @param amount the amount to withdraw, in wei function withdrawNative(uint256 amount) external onlyOwner { (bool success, ) = payable(owner()).call{value: amount}(""); + // solhint-disable-next-line custom-errors require(success, "withdrawNative failed"); } } diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol index 0656f621799..7b6df2c563e 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol +++ b/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../VRFV2PlusWrapperConsumerBase.sol"; -import "../../../shared/access/ConfirmedOwner.sol"; -import "../../../ChainSpecificUtil.sol"; +import {VRFV2PlusWrapperConsumerBase} from "../VRFV2PlusWrapperConsumerBase.sol"; +import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; +import {ChainSpecificUtil} from "../../../ChainSpecificUtil.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; +import {IVRFV2PlusWrapper} from "../../interfaces/IVRFV2PlusWrapper.sol"; contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, ConfirmedOwner { uint256 public s_responseCount; @@ -13,7 +14,8 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi uint256 public s_slowestFulfillment = 0; uint256 public s_fastestFulfillment = 999; uint256 public s_lastRequestId; - mapping(uint256 => uint256) requestHeights; // requestIds to block number when rand request was made + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore + mapping(uint256 => uint256) internal requestHeights; // requestIds to block number when rand request was made event WrappedRequestFulfilled(uint256 requestId, uint256[] randomWords, uint256 payment); event WrapperRequestMade(uint256 indexed requestId, uint256 paid); @@ -22,8 +24,8 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi uint256 paid; bool fulfilled; uint256[] randomWords; - uint requestTimestamp; - uint fulfilmentTimestamp; + uint256 requestTimestamp; + uint256 fulfilmentTimestamp; uint256 requestBlockNumber; uint256 fulfilmentBlockNumber; bool native; @@ -94,7 +96,9 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi } } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); uint256 fulfilmentBlockNumber = ChainSpecificUtil.getBlockNumber(); uint256 requestDelay = fulfilmentBlockNumber - requestHeights[_requestId]; @@ -126,12 +130,13 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi uint256 paid, bool fulfilled, uint256[] memory randomWords, - uint requestTimestamp, - uint fulfilmentTimestamp, + uint256 requestTimestamp, + uint256 fulfilmentTimestamp, uint256 requestBlockNumber, uint256 fulfilmentBlockNumber ) { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); RequestStatus memory request = s_requests[_requestId]; return ( @@ -163,6 +168,7 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi /// @param amount the amount to withdraw, in wei function withdrawNative(uint256 amount) external onlyOwner { (bool success, ) = payable(owner()).call{value: amount}(""); + // solhint-disable-next-line custom-errors require(success, "withdrawNative failed"); } @@ -172,7 +178,7 @@ contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, Confi receive() external payable {} - function getBalance() public view returns (uint) { + function getBalance() public view returns (uint256) { return address(this).balance; } } diff --git a/contracts/src/v0.8/functions/dev/v0_0_0/FunctionsBillingRegistry.sol b/contracts/src/v0.8/functions/dev/v0_0_0/FunctionsBillingRegistry.sol index 3488af55cca..19dba693671 100644 --- a/contracts/src/v0.8/functions/dev/v0_0_0/FunctionsBillingRegistry.sol +++ b/contracts/src/v0.8/functions/dev/v0_0_0/FunctionsBillingRegistry.sol @@ -377,7 +377,6 @@ contract FunctionsBillingRegistry is * or reverts if at least gasAmount gas is not available. */ function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // GAS_FOR_CALL_EXACT_CHECK = 5000 diff --git a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsCoordinator.sol b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsCoordinator.sol index 540b382d652..daafe593a7b 100644 --- a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsCoordinator.sol +++ b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsCoordinator.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.19; import {IFunctionsCoordinator} from "./interfaces/IFunctionsCoordinator.sol"; -import {IFunctionsBilling} from "./interfaces/IFunctionsBilling.sol"; import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol"; import {FunctionsBilling} from "./FunctionsBilling.sol"; diff --git a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsRouter.sol b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsRouter.sol index 41cd90341f3..9051fd26d44 100644 --- a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsRouter.sol +++ b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsRouter.sol @@ -402,7 +402,6 @@ contract FunctionsRouter is IFunctionsRouter, FunctionsSubscriptions, Pausable, address client ) private returns (CallbackResult memory) { bool destinationNoLongerExists; - // solhint-disable-next-line no-inline-assembly assembly { // solidity calls check that a contract actually exists at the destination, so we do the same destinationNoLongerExists := iszero(extcodesize(client)) @@ -432,7 +431,6 @@ contract FunctionsRouter is IFunctionsRouter, FunctionsSubscriptions, Pausable, // allocate return data memory ahead of time bytes memory returnData = new bytes(MAX_CALLBACK_RETURN_BYTES); - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= gasForCallExactCheck and check for underflow diff --git a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsSubscriptions.sol b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsSubscriptions.sol index 864225fd38c..9a390a93fce 100644 --- a/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsSubscriptions.sol +++ b/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsSubscriptions.sol @@ -3,15 +3,12 @@ pragma solidity ^0.8.19; import {IFunctionsSubscriptions} from "./interfaces/IFunctionsSubscriptions.sol"; import {IERC677Receiver} from "../../../shared/interfaces/IERC677Receiver.sol"; -import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; import {IFunctionsBilling} from "./interfaces/IFunctionsBilling.sol"; -import {IFunctionsRouter} from "./interfaces/IFunctionsRouter.sol"; import {FunctionsResponse} from "./libraries/FunctionsResponse.sol"; import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol"; -import {SafeCast} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/utils/math/SafeCast.sol"; /// @title Functions Subscriptions contract /// @notice Contract that coordinates payment from users to the nodes of the Decentralized Oracle Network (DON). diff --git a/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsResponse.sol b/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsResponse.sol index 31a33169226..65fad665d69 100644 --- a/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsResponse.sol +++ b/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsResponse.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import {IFunctionsSubscriptions} from "../interfaces/IFunctionsSubscriptions.sol"; - /// @title Library of types that are used for fulfillment of a Functions request library FunctionsResponse { // Used to send request information from the Router to the Coordinator diff --git a/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryMigration.sol b/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryMigration.sol index f9e6649d026..d70fd3645e9 100644 --- a/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryMigration.sol +++ b/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryMigration.sol @@ -6,7 +6,6 @@ import {AggregatorV3Interface} from "../../../../../interfaces/AggregatorV3Inter import {FunctionsBillingRegistryInterface} from "./FunctionsBillingRegistryInterface.sol"; import {FunctionsOracleInterface} from "./FunctionsOracleInterface.sol"; import {FunctionsClientInterface} from "./FunctionsClientInterface.sol"; -import {TypeAndVersionInterface} from "../../../../../interfaces/TypeAndVersionInterface.sol"; import {IERC677Receiver} from "../../../../../shared/interfaces/IERC677Receiver.sol"; import {AuthorizedOriginReceiverInterface} from "./AuthorizedOriginReceiverInterface.sol"; import {ConfirmedOwnerUpgradeable} from "./ConfirmedOwnerUpgradeable.sol"; @@ -372,7 +371,6 @@ contract FunctionsBillingRegistryMigration is * or reverts if at least gasAmount gas is not available. */ function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // GAS_FOR_CALL_EXACT_CHECK = 5000 diff --git a/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryOriginal.sol b/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryOriginal.sol index 39bff270401..a11d57f90e2 100644 --- a/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryOriginal.sol +++ b/contracts/src/v0.8/functions/tests/v0_0_0/testhelpers/mocks/FunctionsBillingRegistryOriginal.sol @@ -6,7 +6,6 @@ import {AggregatorV3Interface} from "../../../../../interfaces/AggregatorV3Inter import {FunctionsOracleInterface} from "./FunctionsOracleInterface.sol"; import {FunctionsBillingRegistryInterface} from "./FunctionsBillingRegistryInterface.sol"; import {FunctionsClientInterface} from "./FunctionsClientInterface.sol"; -import {TypeAndVersionInterface} from "../../../../../interfaces/TypeAndVersionInterface.sol"; import {IERC677Receiver} from "../../../../../shared/interfaces/IERC677Receiver.sol"; import {AuthorizedOriginReceiverInterface} from "./AuthorizedOriginReceiverInterface.sol"; import {ConfirmedOwnerUpgradeable} from "./ConfirmedOwnerUpgradeable.sol"; @@ -372,7 +371,6 @@ contract FunctionsBillingRegistryOriginal is * or reverts if at least gasAmount gas is not available. */ function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // GAS_FOR_CALL_EXACT_CHECK = 5000 diff --git a/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol b/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol index 4cb40c104e1..c023e3d2f90 100644 --- a/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol +++ b/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./AggregatorInterface.sol"; -import "./AggregatorV3Interface.sol"; +import {AggregatorInterface} from "./AggregatorInterface.sol"; +import {AggregatorV3Interface} from "./AggregatorV3Interface.sol"; interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {} diff --git a/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol b/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol index 512939b38fe..1d2367d82a8 100644 --- a/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol +++ b/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; pragma abicoder v2; -import "./AggregatorV2V3Interface.sol"; +import {AggregatorV2V3Interface} from "./AggregatorV2V3Interface.sol"; interface FeedRegistryInterface { struct Phase { diff --git a/contracts/src/v0.8/interfaces/OperatorInterface.sol b/contracts/src/v0.8/interfaces/OperatorInterface.sol index 14922649159..668c167cf4b 100644 --- a/contracts/src/v0.8/interfaces/OperatorInterface.sol +++ b/contracts/src/v0.8/interfaces/OperatorInterface.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./OracleInterface.sol"; -import "./ChainlinkRequestInterface.sol"; +import {OracleInterface} from "./OracleInterface.sol"; +import {ChainlinkRequestInterface} from "./ChainlinkRequestInterface.sol"; interface OperatorInterface is OracleInterface, ChainlinkRequestInterface { function operatorRequest( diff --git a/contracts/src/v0.8/l2ep/dev/arbitrum/ArbitrumSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/dev/arbitrum/ArbitrumSequencerUptimeFeed.sol index 3c09fb9acad..5c9b3268c7f 100644 --- a/contracts/src/v0.8/l2ep/dev/arbitrum/ArbitrumSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/dev/arbitrum/ArbitrumSequencerUptimeFeed.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.4; import {AddressAliasHelper} from "../../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol"; -import {ForwarderInterface} from "./../interfaces/ForwarderInterface.sol"; import {AggregatorInterface} from "../../../interfaces/AggregatorInterface.sol"; import {AggregatorV3Interface} from "../../../interfaces/AggregatorV3Interface.sol"; import {AggregatorV2V3Interface} from "../../../interfaces/AggregatorV2V3Interface.sol"; @@ -10,7 +9,6 @@ import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterfa import {FlagsInterface} from "./../../../dev/interfaces/FlagsInterface.sol"; import {ArbitrumSequencerUptimeFeedInterface} from "../interfaces/ArbitrumSequencerUptimeFeedInterface.sol"; import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAccessController.sol"; -import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; /** * @title ArbitrumSequencerUptimeFeed - L2 sequencer uptime status aggregator diff --git a/contracts/src/v0.8/l2ep/dev/optimism/OptimismSequencerUptimeFeed.sol b/contracts/src/v0.8/l2ep/dev/optimism/OptimismSequencerUptimeFeed.sol index a4ef57505b5..af7ccc90574 100644 --- a/contracts/src/v0.8/l2ep/dev/optimism/OptimismSequencerUptimeFeed.sol +++ b/contracts/src/v0.8/l2ep/dev/optimism/OptimismSequencerUptimeFeed.sol @@ -7,7 +7,6 @@ import {AggregatorV2V3Interface} from "../../../interfaces/AggregatorV2V3Interfa import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol"; import {OptimismSequencerUptimeFeedInterface} from "./../interfaces/OptimismSequencerUptimeFeedInterface.sol"; import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAccessController.sol"; -import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; import {IL2CrossDomainMessenger} from "@eth-optimism/contracts/L2/messaging/IL2CrossDomainMessenger.sol"; /** diff --git a/contracts/src/v0.8/libraries/ByteUtil.sol b/contracts/src/v0.8/libraries/ByteUtil.sol index 906fef3fa77..9691cfb7fea 100644 --- a/contracts/src/v0.8/libraries/ByteUtil.sol +++ b/contracts/src/v0.8/libraries/ByteUtil.sol @@ -16,7 +16,7 @@ library ByteUtil { * @param offset Position to start reading from. * @return result The uint256 read from the byte array. */ - function readUint256(bytes memory data, uint256 offset) internal pure returns (uint256 result) { + function _readUint256(bytes memory data, uint256 offset) internal pure returns (uint256 result) { //bounds check if (offset + 32 > data.length) revert MalformedData(); @@ -32,7 +32,7 @@ library ByteUtil { * @param offset Position to start reading from. * @return result The uint192 read from the byte array. */ - function readUint192(bytes memory data, uint256 offset) internal pure returns (uint256 result) { + function _readUint192(bytes memory data, uint256 offset) internal pure returns (uint256 result) { //bounds check if (offset + 24 > data.length) revert MalformedData(); @@ -50,7 +50,7 @@ library ByteUtil { * @param offset Position to start reading from. * @return result The uint32 read from the byte array. */ - function readUint32(bytes memory data, uint256 offset) internal pure returns (uint256 result) { + function _readUint32(bytes memory data, uint256 offset) internal pure returns (uint256 result) { //bounds check if (offset + 4 > data.length) revert MalformedData(); @@ -68,7 +68,7 @@ library ByteUtil { * @param offset Position to start reading from. * @return result The uint32 read from the byte array. */ - function readAddress(bytes memory data, uint256 offset) internal pure returns (address result) { + function _readAddress(bytes memory data, uint256 offset) internal pure returns (address result) { //bounds check if (offset + 20 > data.length) revert MalformedData(); diff --git a/contracts/src/v0.8/libraries/Common.sol b/contracts/src/v0.8/libraries/Common.sol index 5bb8275c72e..fe04a9af71b 100644 --- a/contracts/src/v0.8/libraries/Common.sol +++ b/contracts/src/v0.8/libraries/Common.sol @@ -24,7 +24,7 @@ library Common { * @param recipients The array of AddressAndWeight to check * @return bool True if there are duplicates, false otherwise */ - function hasDuplicateAddresses(Common.AddressAndWeight[] memory recipients) internal pure returns (bool) { + function _hasDuplicateAddresses(Common.AddressAndWeight[] memory recipients) internal pure returns (bool) { for (uint256 i = 0; i < recipients.length; ) { for (uint256 j = i + 1; j < recipients.length; ) { if (recipients[i].addr == recipients[j].addr) { diff --git a/contracts/src/v0.8/libraries/test/ByteUtilTest.t.sol b/contracts/src/v0.8/libraries/test/ByteUtilTest.t.sol index eabae4f5729..0629d0235ee 100644 --- a/contracts/src/v0.8/libraries/test/ByteUtilTest.t.sol +++ b/contracts/src/v0.8/libraries/test/ByteUtilTest.t.sol @@ -17,7 +17,7 @@ contract ByteUtilTest is Test { function test_readUint256Max() public { //read the first 32 bytes - uint256 result = B_512.readUint256(0); + uint256 result = B_512._readUint256(0); //the result should be the max value of a uint256 assertEq(result, type(uint256).max); @@ -25,7 +25,7 @@ contract ByteUtilTest is Test { function test_readUint192Max() public { //read the first 24 bytes - uint256 result = B_512.readUint192(0); + uint256 result = B_512._readUint192(0); //the result should be the max value of a uint192 assertEq(result, type(uint192).max); @@ -33,7 +33,7 @@ contract ByteUtilTest is Test { function test_readUint32Max() public { //read the first 4 bytes - uint256 result = B_512.readUint32(0); + uint256 result = B_512._readUint32(0); //the result should be the max value of a uint32 assertEq(result, type(uint32).max); @@ -41,7 +41,7 @@ contract ByteUtilTest is Test { function test_readUint256Min() public { //read the second 32 bytes - uint256 result = B_512.readUint256(32); + uint256 result = B_512._readUint256(32); //the result should be the min value of a uint256 assertEq(result, type(uint256).min); @@ -49,7 +49,7 @@ contract ByteUtilTest is Test { function test_readUint192Min() public { //read the second 24 bytes - uint256 result = B_512.readUint192(32); + uint256 result = B_512._readUint192(32); //the result should be the min value of a uint192 assertEq(result, type(uint192).min); @@ -57,7 +57,7 @@ contract ByteUtilTest is Test { function test_readUint32Min() public { //read the second 4 bytes - uint256 result = B_512.readUint32(32); + uint256 result = B_512._readUint32(32); //the result should be the min value of a uint32 assertEq(result, type(uint32).min); @@ -65,7 +65,7 @@ contract ByteUtilTest is Test { function test_readUint256MultiWord() public { //read the first 32 bytes - uint256 result = B_512.readUint256(31); + uint256 result = B_512._readUint256(31); //the result should be the last byte from the first word (ff), and 31 bytes from the second word (0000) (0xFF...0000) assertEq(result, type(uint256).max << 248); @@ -73,7 +73,7 @@ contract ByteUtilTest is Test { function test_readUint192MultiWord() public { //read the first 24 bytes - uint256 result = B_512.readUint192(31); + uint256 result = B_512._readUint192(31); //the result should be the last byte from the first word (ff), and 23 bytes from the second word (0000) (0xFF...0000) assertEq(result, type(uint192).max << 184); @@ -81,7 +81,7 @@ contract ByteUtilTest is Test { function test_readUint32MultiWord() public { //read the first 4 bytes - uint256 result = B_512.readUint32(31); + uint256 result = B_512._readUint32(31); //the result should be the last byte from the first word (ff), and 3 bytes from the second word (0000) (0xFF...0000) assertEq(result, type(uint32).max << 24); @@ -92,7 +92,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //try and read 32 bytes from a 16 byte number - B_128.readUint256(0); + B_128._readUint256(0); } function test_readUint192WithNotEnoughBytes() public { @@ -100,7 +100,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //try and read 24 bytes from a 16 byte number - B_128.readUint192(0); + B_128._readUint192(0); } function test_readUint32WithNotEnoughBytes() public { @@ -108,7 +108,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //try and read 4 bytes from a 2 byte number - B_16.readUint32(0); + B_16._readUint32(0); } function test_readUint256WithEmptyArray() public { @@ -116,7 +116,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //read 20 bytes from an empty array - B_EMPTY.readUint256(0); + B_EMPTY._readUint256(0); } function test_readUint192WithEmptyArray() public { @@ -124,7 +124,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //read 20 bytes from an empty array - B_EMPTY.readUint192(0); + B_EMPTY._readUint192(0); } function test_readUint32WithEmptyArray() public { @@ -132,12 +132,12 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //read 20 bytes from an empty array - B_EMPTY.readUint32(0); + B_EMPTY._readUint32(0); } function test_readAddress() public { //read the first 20 bytes - address result = B_512.readAddress(0); + address result = B_512._readAddress(0); //the result should be the max value of a uint256 assertEq(result, address(type(uint160).max)); @@ -145,7 +145,7 @@ contract ByteUtilTest is Test { function test_readZeroAddress() public { //read the first 32 bytes after the first word - address result = B_512.readAddress(32); + address result = B_512._readAddress(32); //the result should be 0x00...0 assertEq(result, address(type(uint160).min)); @@ -153,7 +153,7 @@ contract ByteUtilTest is Test { function test_readAddressMultiWord() public { //read the first 20 bytes after byte 13 - address result = B_512.readAddress(13); + address result = B_512._readAddress(13); //the result should be the value last 19 bytes of the first word (ffff..) and the first byte of the second word (00) (0xFFFF..00) assertEq(result, address(type(uint160).max << 8)); @@ -164,7 +164,7 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //read 20 bytes from a 16 byte array - B_128.readAddress(0); + B_128._readAddress(0); } function test_readAddressWithEmptyArray() public { @@ -172,6 +172,6 @@ contract ByteUtilTest is Test { vm.expectRevert(MALFORMED_ERROR_SELECTOR); //read the first 20 bytes of an empty array - B_EMPTY.readAddress(0); + B_EMPTY._readAddress(0); } } diff --git a/contracts/src/v0.8/llo-feeds/RewardManager.sol b/contracts/src/v0.8/llo-feeds/RewardManager.sol index f4bd835c256..e064bff8b67 100644 --- a/contracts/src/v0.8/llo-feeds/RewardManager.sol +++ b/contracts/src/v0.8/llo-feeds/RewardManager.sol @@ -5,7 +5,6 @@ import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; import {IRewardManager} from "./interfaces/IRewardManager.sol"; import {IERC20} from "../vendor/openzeppelin-solidity/v4.8.0/contracts/interfaces/IERC20.sol"; import {TypeAndVersionInterface} from "../interfaces/TypeAndVersionInterface.sol"; -import {IERC165} from "../vendor/openzeppelin-solidity/v4.8.0/contracts/interfaces/IERC165.sol"; import {Common} from "../libraries/Common.sol"; import {SafeERC20} from "../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol"; @@ -200,7 +199,7 @@ contract RewardManager is IRewardManager, ConfirmedOwner, TypeAndVersionInterfac uint256 expectedWeight ) internal { //we can't update the weights if it contains duplicates - if (Common.hasDuplicateAddresses(rewardRecipientAndWeights)) revert InvalidAddress(); + if (Common._hasDuplicateAddresses(rewardRecipientAndWeights)) revert InvalidAddress(); //loop all the reward recipients and validate the weight and address uint256 totalWeight; diff --git a/contracts/src/v0.8/llo-feeds/Verifier.sol b/contracts/src/v0.8/llo-feeds/Verifier.sol index dbd5fc73abc..cd7e3d2bad6 100644 --- a/contracts/src/v0.8/llo-feeds/Verifier.sol +++ b/contracts/src/v0.8/llo-feeds/Verifier.sol @@ -173,7 +173,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface { address private immutable i_verifierProxyAddr; /// @notice Verifier states keyed on Feed ID - mapping(bytes32 => VerifierState) s_feedVerifierStates; + mapping(bytes32 => VerifierState) internal s_feedVerifierStates; /// @param verifierProxyAddr The address of the VerifierProxy contract constructor(address verifierProxyAddr) ConfirmedOwner(msg.sender) { diff --git a/contracts/src/v0.8/llo-feeds/test/fee-manager/BaseFeeManager.t.sol b/contracts/src/v0.8/llo-feeds/test/fee-manager/BaseFeeManager.t.sol index ef46ad37853..c446150406e 100644 --- a/contracts/src/v0.8/llo-feeds/test/fee-manager/BaseFeeManager.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/fee-manager/BaseFeeManager.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {Test} from "forge-std/Test.sol"; import {FeeManager} from "../../FeeManager.sol"; -import {IFeeManager} from "../../interfaces/IFeeManager.sol"; import {RewardManager} from "../../RewardManager.sol"; import {Common} from "../../../libraries/Common.sol"; import {ERC20Mock} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/mocks/ERC20Mock.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.general.t.sol b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.general.t.sol index 105c140b73a..e2c9916f663 100644 --- a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.general.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.general.t.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.16; -import {Test} from "forge-std/Test.sol"; -import {FeeManager} from "../../FeeManager.sol"; -import {Common} from "../../../libraries/Common.sol"; import "./BaseFeeManager.t.sol"; /** diff --git a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.getFeeAndReward.t.sol b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.getFeeAndReward.t.sol index dcabe6e5f9d..801a1e39925 100644 --- a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.getFeeAndReward.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.getFeeAndReward.t.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.16; -import {Test} from "forge-std/Test.sol"; -import {FeeManager} from "../../FeeManager.sol"; -import {IFeeManager} from "../../interfaces/IFeeManager.sol"; import {Common} from "../../../libraries/Common.sol"; import "./BaseFeeManager.t.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFee.t.sol b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFee.t.sol index 91fb42a500f..9c2bd711ed5 100644 --- a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFee.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFee.t.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.16; -import {Test} from "forge-std/Test.sol"; -import {FeeManager} from "../../FeeManager.sol"; import {Common} from "../../../libraries/Common.sol"; import "./BaseFeeManager.t.sol"; import {IRewardManager} from "../../interfaces/IRewardManager.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFeeBulk.t.sol b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFeeBulk.t.sol index 25fb804630d..3570b8824a8 100644 --- a/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFeeBulk.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/fee-manager/FeeManager.processFeeBulk.t.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.16; -import {Test} from "forge-std/Test.sol"; -import {FeeManager} from "../../FeeManager.sol"; -import {Common} from "../../../libraries/Common.sol"; import "./BaseFeeManager.t.sol"; import {IRewardManager} from "../../interfaces/IRewardManager.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/gas/Gas_VerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/test/gas/Gas_VerifierTest.t.sol index 5e601034bb8..3198576e8aa 100644 --- a/contracts/src/v0.8/llo-feeds/test/gas/Gas_VerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/gas/Gas_VerifierTest.t.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.16; import {BaseTest, BaseTestWithConfiguredVerifierAndFeeManager} from "../verifier/BaseVerifierTest.t.sol"; -import {Verifier} from "../../Verifier.sol"; import {SimpleWriteAccessController} from "../../../shared/access/SimpleWriteAccessController.sol"; import {Common} from "../../../libraries/Common.sol"; import {IRewardManager} from "../../interfaces/IRewardManager.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.general.t.sol b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.general.t.sol index befe6bfce93..9cee5b05c57 100644 --- a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.general.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.general.t.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.16; import {BaseRewardManagerTest} from "./BaseRewardManager.t.sol"; -import {Common} from "../../../libraries/Common.sol"; import {RewardManager} from "../../RewardManager.sol"; import {ERC20Mock} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/mocks/ERC20Mock.sol"; import {IRewardManager} from "../../interfaces/IRewardManager.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.payRecipients.t.sol b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.payRecipients.t.sol index 5dcf1eeae4f..0f94805da69 100644 --- a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.payRecipients.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.payRecipients.t.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.16; import {BaseRewardManagerTest} from "./BaseRewardManager.t.sol"; -import {Common} from "../../../libraries/Common.sol"; import {IRewardManager} from "../../interfaces/IRewardManager.sol"; /** diff --git a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.setRecipients.t.sol b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.setRecipients.t.sol index 58cce9a9154..0e45ba00da4 100644 --- a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.setRecipients.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.setRecipients.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseRewardManagerTest} from "./BaseRewardManager.t.sol"; import {Common} from "../../../libraries/Common.sol"; -import {RewardManager} from "../../RewardManager.sol"; /** * @title BaseRewardManagerTest diff --git a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.updateRewardRecipients.t.sol b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.updateRewardRecipients.t.sol index e6f964f9f9f..4b3063ac016 100644 --- a/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.updateRewardRecipients.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/reward-manager/RewardManager.updateRewardRecipients.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseRewardManagerTest} from "./BaseRewardManager.t.sol"; import {Common} from "../../../libraries/Common.sol"; -import {RewardManager} from "../../RewardManager.sol"; /** * @title BaseRewardManagerTest diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierActivateConfigTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierActivateConfigTest.t.sol index 641d2772595..8838beded9d 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierActivateConfigTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierActivateConfigTest.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseTestWithConfiguredVerifierAndFeeManager, BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; contract VerifierActivateConfigTest is BaseTestWithConfiguredVerifierAndFeeManager { function test_revertsIfNotOwner() public { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierDeactivateFeedTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierDeactivateFeedTest.t.sol index fc6814d3bfe..70e65a60300 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierDeactivateFeedTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierDeactivateFeedTest.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseTestWithConfiguredVerifierAndFeeManager, BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; contract VerifierActivateFeedTest is BaseTestWithConfiguredVerifierAndFeeManager { function test_revertsIfNotOwnerActivateFeed() public { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyConstructorTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyConstructorTest.t.sol index 7de7dea03d1..8410d655897 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyConstructorTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyConstructorTest.t.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.16; import {BaseTest} from "./BaseVerifierTest.t.sol"; -import {IVerifier} from "../../interfaces/IVerifier.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; import {AccessControllerInterface} from "../../../shared/interfaces/AccessControllerInterface.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyInitializeVerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyInitializeVerifierTest.t.sol index 66ddb4bf3c3..f73d93af18c 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyInitializeVerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyInitializeVerifierTest.t.sol @@ -2,9 +2,7 @@ pragma solidity 0.8.16; import {BaseTest} from "./BaseVerifierTest.t.sol"; -import {IVerifier} from "../../interfaces/IVerifier.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; -import {AccessControllerInterface} from "../../../shared/interfaces/AccessControllerInterface.sol"; contract VerifierProxyInitializeVerifierTest is BaseTest { bytes32 latestDigest; diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxySetVerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxySetVerifierTest.t.sol index 9fa2f16d900..3699aaf420d 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxySetVerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxySetVerifierTest.t.sol @@ -4,7 +4,6 @@ pragma solidity 0.8.16; import {BaseTestWithConfiguredVerifierAndFeeManager} from "./BaseVerifierTest.t.sol"; import {IVerifier} from "../../interfaces/IVerifier.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; -import {AccessControllerInterface} from "../../../shared/interfaces/AccessControllerInterface.sol"; import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/interfaces/IERC165.sol"; import {Common} from "../../../libraries/Common.sol"; diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyTest.t.sol index 5aa3e791ed8..9b5f94acd4b 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyTest.t.sol @@ -2,11 +2,7 @@ pragma solidity 0.8.16; import {BaseTestWithConfiguredVerifierAndFeeManager} from "./BaseVerifierTest.t.sol"; -import {IVerifier} from "../../interfaces/IVerifier.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; -import {AccessControllerInterface} from "../../../shared/interfaces/AccessControllerInterface.sol"; -import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/interfaces/IERC165.sol"; -import {Common} from "../../../libraries/Common.sol"; import {FeeManager} from "../../FeeManager.sol"; contract VerifierProxyInitializeVerifierTest is BaseTestWithConfiguredVerifierAndFeeManager { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyUnsetVerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyUnsetVerifierTest.t.sol index a64d6ee0f78..95a42e52edc 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyUnsetVerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierProxyUnsetVerifierTest.t.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.16; import {BaseTest, BaseTestWithConfiguredVerifierAndFeeManager} from "./BaseVerifierTest.t.sol"; -import {IVerifier} from "../../interfaces/IVerifier.sol"; import {VerifierProxy} from "../../VerifierProxy.sol"; contract VerifierProxyUnsetVerifierTest is BaseTest { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigFromSourceTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigFromSourceTest.t.sol index 57c98622f5b..6c5eac9b6dd 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigFromSourceTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigFromSourceTest.t.sol @@ -2,8 +2,6 @@ pragma solidity 0.8.16; import {BaseTest, BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; -import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; import {Common} from "../../../libraries/Common.sol"; contract VerifierSetConfigFromSourceTest is BaseTest { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigTest.t.sol index faa1f98bc30..f0b045e7f30 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierSetConfigTest.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseTest, BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; import {Common} from "../../../libraries/Common.sol"; contract VerifierSetConfigTest is BaseTest { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTest.t.sol index 1b4340495fc..290eaa1d568 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTest.t.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.16; import {BaseTest} from "./BaseVerifierTest.t.sol"; import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; contract VerifierConstructorTest is BaseTest { function test_revertsIfInitializedWithEmptyVerifierProxy() public { diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTestBillingReport.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTestBillingReport.t.sol index fffa291b0d8..52281298d48 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTestBillingReport.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierTestBillingReport.t.sol @@ -2,9 +2,6 @@ pragma solidity 0.8.16; import {BaseTestWithConfiguredVerifierAndFeeManager} from "./BaseVerifierTest.t.sol"; -import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; -import {Common} from "../../../libraries/Common.sol"; contract VerifierTestWithConfiguredVerifierAndFeeManager is BaseTestWithConfiguredVerifierAndFeeManager { uint256 internal constant DEFAULT_LINK_MINT_QUANTITY = 100 ether; diff --git a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierUnsetConfigTest.t.sol b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierUnsetConfigTest.t.sol index 467c5072d55..41c484a8787 100644 --- a/contracts/src/v0.8/llo-feeds/test/verifier/VerifierUnsetConfigTest.t.sol +++ b/contracts/src/v0.8/llo-feeds/test/verifier/VerifierUnsetConfigTest.t.sol @@ -1,9 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.16; -import {BaseTestWithConfiguredVerifierAndFeeManager, BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; +import {BaseTestWithMultipleConfiguredDigests} from "./BaseVerifierTest.t.sol"; import {Verifier} from "../../Verifier.sol"; -import {VerifierProxy} from "../../VerifierProxy.sol"; contract VerificationdeactivateConfigWhenThereAreMultipleDigestsTest is BaseTestWithMultipleConfiguredDigests { function test_revertsIfCalledByNonOwner() public { diff --git a/contracts/src/v0.8/shared/access/ConfirmedOwner.sol b/contracts/src/v0.8/shared/access/ConfirmedOwner.sol index a33cff10bc9..a25d92ffd67 100644 --- a/contracts/src/v0.8/shared/access/ConfirmedOwner.sol +++ b/contracts/src/v0.8/shared/access/ConfirmedOwner.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./ConfirmedOwnerWithProposal.sol"; +import {ConfirmedOwnerWithProposal} from "./ConfirmedOwnerWithProposal.sol"; /** * @title The ConfirmedOwner contract diff --git a/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol b/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol index c2a01cfca18..a6757c38869 100644 --- a/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol +++ b/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../interfaces/IOwnable.sol"; +import {IOwnable} from "../interfaces/IOwnable.sol"; /** * @title The ConfirmedOwner contract @@ -15,6 +15,7 @@ contract ConfirmedOwnerWithProposal is IOwnable { event OwnershipTransferred(address indexed from, address indexed to); constructor(address newOwner, address pendingOwner) { + // solhint-disable-next-line custom-errors require(newOwner != address(0), "Cannot set owner to zero"); s_owner = newOwner; @@ -35,6 +36,7 @@ contract ConfirmedOwnerWithProposal is IOwnable { * @notice Allows an ownership transfer to be completed by the recipient. */ function acceptOwnership() external override { + // solhint-disable-next-line custom-errors require(msg.sender == s_pendingOwner, "Must be proposed owner"); address oldOwner = s_owner; @@ -55,6 +57,7 @@ contract ConfirmedOwnerWithProposal is IOwnable { * @notice validate, transfer ownership, and emit relevant events */ function _transferOwnership(address to) private { + // solhint-disable-next-line custom-errors require(to != msg.sender, "Cannot transfer to self"); s_pendingOwner = to; @@ -66,6 +69,7 @@ contract ConfirmedOwnerWithProposal is IOwnable { * @notice validate access */ function _validateOwnership() internal view { + // solhint-disable-next-line custom-errors require(msg.sender == s_owner, "Only callable by owner"); } diff --git a/contracts/src/v0.8/shared/access/SimpleReadAccessController.sol b/contracts/src/v0.8/shared/access/SimpleReadAccessController.sol index ade1c15c86b..b36fa4e4b60 100644 --- a/contracts/src/v0.8/shared/access/SimpleReadAccessController.sol +++ b/contracts/src/v0.8/shared/access/SimpleReadAccessController.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./SimpleWriteAccessController.sol"; +import {SimpleWriteAccessController} from "./SimpleWriteAccessController.sol"; /** * @title SimpleReadAccessController @@ -20,6 +20,7 @@ contract SimpleReadAccessController is SimpleWriteAccessController { * @param _user The address to query */ function hasAccess(address _user, bytes memory _calldata) public view virtual override returns (bool) { + // solhint-disable-next-line avoid-tx-origin return super.hasAccess(_user, _calldata) || _user == tx.origin; } } diff --git a/contracts/src/v0.8/shared/access/SimpleWriteAccessController.sol b/contracts/src/v0.8/shared/access/SimpleWriteAccessController.sol index c73dec470b2..117d2e77dd6 100644 --- a/contracts/src/v0.8/shared/access/SimpleWriteAccessController.sol +++ b/contracts/src/v0.8/shared/access/SimpleWriteAccessController.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./ConfirmedOwner.sol"; -import "../interfaces/AccessControllerInterface.sol"; +import {ConfirmedOwner} from "./ConfirmedOwner.sol"; +import {AccessControllerInterface} from "../interfaces/AccessControllerInterface.sol"; /** * @title SimpleWriteAccessController @@ -13,7 +13,7 @@ import "../interfaces/AccessControllerInterface.sol"; */ contract SimpleWriteAccessController is AccessControllerInterface, ConfirmedOwner { bool public checkEnabled; - mapping(address => bool) internal accessList; + mapping(address => bool) internal s_accessList; event AddedAccess(address user); event RemovedAccess(address user); @@ -29,7 +29,7 @@ contract SimpleWriteAccessController is AccessControllerInterface, ConfirmedOwne * @param _user The address to query */ function hasAccess(address _user, bytes memory) public view virtual override returns (bool) { - return accessList[_user] || !checkEnabled; + return s_accessList[_user] || !checkEnabled; } /** @@ -37,8 +37,8 @@ contract SimpleWriteAccessController is AccessControllerInterface, ConfirmedOwne * @param _user The address to add */ function addAccess(address _user) external onlyOwner { - if (!accessList[_user]) { - accessList[_user] = true; + if (!s_accessList[_user]) { + s_accessList[_user] = true; emit AddedAccess(_user); } @@ -49,8 +49,8 @@ contract SimpleWriteAccessController is AccessControllerInterface, ConfirmedOwne * @param _user The address to remove */ function removeAccess(address _user) external onlyOwner { - if (accessList[_user]) { - accessList[_user] = false; + if (s_accessList[_user]) { + s_accessList[_user] = false; emit RemovedAccess(_user); } @@ -82,6 +82,7 @@ contract SimpleWriteAccessController is AccessControllerInterface, ConfirmedOwne * @dev reverts if the caller does not have access */ modifier checkAccess() { + // solhint-disable-next-line custom-errors require(hasAccess(msg.sender, msg.data), "No access"); _; } diff --git a/contracts/src/v0.8/shared/interfaces/IWERC20.sol b/contracts/src/v0.8/shared/interfaces/IWERC20.sol index e79712a593d..96073530482 100644 --- a/contracts/src/v0.8/shared/interfaces/IWERC20.sol +++ b/contracts/src/v0.8/shared/interfaces/IWERC20.sol @@ -4,5 +4,5 @@ pragma solidity ^0.8.0; interface IWERC20 { function deposit() external payable; - function withdraw(uint) external; + function withdraw(uint256) external; } diff --git a/contracts/src/v0.8/shared/mocks/WERC20Mock.sol b/contracts/src/v0.8/shared/mocks/WERC20Mock.sol index 11bdb790c02..02c13be9937 100644 --- a/contracts/src/v0.8/shared/mocks/WERC20Mock.sol +++ b/contracts/src/v0.8/shared/mocks/WERC20Mock.sol @@ -6,8 +6,8 @@ import {ERC20} from "../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/E contract WERC20Mock is ERC20 { constructor() ERC20("WERC20Mock", "WERC") {} - event Deposit(address indexed dst, uint wad); - event Withdrawal(address indexed src, uint wad); + event Deposit(address indexed dst, uint256 wad); + event Withdrawal(address indexed src, uint256 wad); receive() external payable { deposit(); @@ -18,7 +18,8 @@ contract WERC20Mock is ERC20 { emit Deposit(msg.sender, msg.value); } - function withdraw(uint wad) public { + function withdraw(uint256 wad) public { + // solhint-disable-next-line custom-errors, reason-string require(balanceOf(msg.sender) >= wad); _burn(msg.sender, wad); payable(msg.sender).transfer(wad); diff --git a/contracts/src/v0.8/shared/ocr2/OCR2Abstract.sol b/contracts/src/v0.8/shared/ocr2/OCR2Abstract.sol index 5031a528b3d..1f19d0de54e 100644 --- a/contracts/src/v0.8/shared/ocr2/OCR2Abstract.sol +++ b/contracts/src/v0.8/shared/ocr2/OCR2Abstract.sol @@ -5,8 +5,11 @@ import {ITypeAndVersion} from "../interfaces/ITypeAndVersion.sol"; abstract contract OCR2Abstract is ITypeAndVersion { // Maximum number of oracles the offchain reporting protocol is designed for + // solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables uint256 internal constant maxNumOracles = 31; + // solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables uint256 private constant prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00 + // solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables uint256 private constant prefix = 0x0001 << (256 - 16); // 0x000100..00 /** diff --git a/contracts/src/v0.8/shared/test/token/ERC677/BurnMintERC677.t.sol b/contracts/src/v0.8/shared/test/token/ERC677/BurnMintERC677.t.sol index 6b223f51236..6b13f390009 100644 --- a/contracts/src/v0.8/shared/test/token/ERC677/BurnMintERC677.t.sol +++ b/contracts/src/v0.8/shared/test/token/ERC677/BurnMintERC677.t.sol @@ -8,7 +8,6 @@ import {BaseTest} from "../../BaseTest.t.sol"; import {BurnMintERC677} from "../../../token/ERC677/BurnMintERC677.sol"; import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol"; -import {Strings} from "../../../../vendor/openzeppelin-solidity/v4.8.0/contracts/utils/Strings.sol"; import {IERC165} from "../../../../vendor/openzeppelin-solidity/v4.8.0/contracts/utils/introspection/IERC165.sol"; contract BurnMintERC677Setup is BaseTest { diff --git a/contracts/src/v0.8/shared/token/ERC20/IOptimismMintableERC20.sol b/contracts/src/v0.8/shared/token/ERC20/IOptimismMintableERC20.sol index 79441cf89f7..6362d9e78ac 100644 --- a/contracts/src/v0.8/shared/token/ERC20/IOptimismMintableERC20.sol +++ b/contracts/src/v0.8/shared/token/ERC20/IOptimismMintableERC20.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT +// solhint-disable one-contract-per-file pragma solidity ^0.8.0; import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.0/contracts/utils/introspection/IERC165.sol"; diff --git a/contracts/src/v0.8/shared/token/ERC677/BurnMintERC677.sol b/contracts/src/v0.8/shared/token/ERC677/BurnMintERC677.sol index 0d78581b13c..775d5fb3d94 100644 --- a/contracts/src/v0.8/shared/token/ERC677/BurnMintERC677.sol +++ b/contracts/src/v0.8/shared/token/ERC677/BurnMintERC677.sol @@ -91,6 +91,7 @@ contract BurnMintERC677 is IBurnMintERC20, ERC677, IERC165, ERC20Burnable, Owner /// @dev Reverts with an empty revert to be compatible with the existing link token when /// the recipient is this contract address. modifier validAddress(address recipient) virtual { + // solhint-disable-next-line reason-string, custom-errors if (recipient == address(this)) revert(); _; } diff --git a/contracts/src/v0.8/shared/token/ERC677/ERC677.sol b/contracts/src/v0.8/shared/token/ERC677/ERC677.sol index de124d53c55..c9a2996e8e9 100644 --- a/contracts/src/v0.8/shared/token/ERC677/ERC677.sol +++ b/contracts/src/v0.8/shared/token/ERC677/ERC677.sol @@ -13,7 +13,7 @@ contract ERC677 is IERC677, ERC20 { constructor(string memory name, string memory symbol) ERC20(name, symbol) {} /// @inheritdoc IERC677 - function transferAndCall(address to, uint amount, bytes memory data) public returns (bool success) { + function transferAndCall(address to, uint256 amount, bytes memory data) public returns (bool success) { super.transfer(to, amount); emit Transfer(msg.sender, to, amount, data); if (to.isContract()) { diff --git a/contracts/src/v0.8/vrf/BatchBlockhashStore.sol b/contracts/src/v0.8/vrf/BatchBlockhashStore.sol index c6c3a888289..bdd906897fa 100644 --- a/contracts/src/v0.8/vrf/BatchBlockhashStore.sol +++ b/contracts/src/v0.8/vrf/BatchBlockhashStore.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT +// solhint-disable-next-line one-contract-per-file pragma solidity 0.8.6; -import "../ChainSpecificUtil.sol"; +import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; /** * @title BatchBlockhashStore @@ -11,6 +12,7 @@ import "../ChainSpecificUtil.sol"; * in times of high network congestion. */ contract BatchBlockhashStore { + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i BlockhashStore public immutable BHS; constructor(address blockhashStoreAddr) { @@ -40,6 +42,7 @@ contract BatchBlockhashStore { * @param headers the rlp-encoded block headers of blockNumbers[i] + 1. */ function storeVerifyHeader(uint256[] memory blockNumbers, bytes[] memory headers) public { + // solhint-disable-next-line custom-errors require(blockNumbers.length == headers.length, "input array arg lengths mismatch"); for (uint256 i = 0; i < blockNumbers.length; i++) { BHS.storeVerifyHeader(blockNumbers[i], headers[i]); @@ -70,6 +73,7 @@ contract BatchBlockhashStore { * using the blockhash() instruction. * @param blockNumber the block number to check if it's storeable with blockhash() */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function storeableBlock(uint256 blockNumber) private view returns (bool) { // handle edge case on simulated chains which possibly have < 256 blocks total. return ChainSpecificUtil.getBlockNumber() <= 256 ? true : blockNumber >= (ChainSpecificUtil.getBlockNumber() - 256); diff --git a/contracts/src/v0.8/vrf/BatchVRFCoordinatorV2.sol b/contracts/src/v0.8/vrf/BatchVRFCoordinatorV2.sol index 83f0a78359d..1072289e88e 100644 --- a/contracts/src/v0.8/vrf/BatchVRFCoordinatorV2.sol +++ b/contracts/src/v0.8/vrf/BatchVRFCoordinatorV2.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT +// solhint-disable-next-line one-contract-per-file pragma solidity 0.8.6; -import "./VRFTypes.sol"; +import {VRFTypes} from "./VRFTypes.sol"; /** * @title BatchVRFCoordinatorV2 @@ -9,6 +10,7 @@ import "./VRFTypes.sol"; * provided VRFCoordinatorV2 contract efficiently in a single transaction. */ contract BatchVRFCoordinatorV2 { + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i VRFCoordinatorV2 public immutable COORDINATOR; event ErrorReturned(uint256 indexed requestId, string reason); @@ -24,6 +26,7 @@ contract BatchVRFCoordinatorV2 { * @param rcs the request commitments corresponding to the randomness proofs. */ function fulfillRandomWords(VRFTypes.Proof[] memory proofs, VRFTypes.RequestCommitment[] memory rcs) external { + // solhint-disable-next-line custom-errors require(proofs.length == rcs.length, "input array arg lengths mismatch"); for (uint256 i = 0; i < proofs.length; i++) { try COORDINATOR.fulfillRandomWords(proofs[i], rcs[i]) returns (uint96 /* payment */) { @@ -42,6 +45,7 @@ contract BatchVRFCoordinatorV2 { * @notice Returns the proving key hash associated with this public key. * @param publicKey the key to return the hash of. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function hashOfKey(uint256[2] memory publicKey) internal pure returns (bytes32) { return keccak256(abi.encode(publicKey)); } @@ -50,6 +54,7 @@ contract BatchVRFCoordinatorV2 { * @notice Returns the request ID of the request associated with the given proof. * @param proof the VRF proof provided by the VRF oracle. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function getRequestIdFromProof(VRFTypes.Proof memory proof) internal pure returns (uint256) { bytes32 keyHash = hashOfKey(proof.pk); return uint256(keccak256(abi.encode(keyHash, proof.seed))); diff --git a/contracts/src/v0.8/vrf/VRF.sol b/contracts/src/v0.8/vrf/VRF.sol index a6c35c79043..7ec5f2d5a60 100644 --- a/contracts/src/v0.8/vrf/VRF.sol +++ b/contracts/src/v0.8/vrf/VRF.sol @@ -142,6 +142,7 @@ contract VRF { // (base^exponent) % FIELD_SIZE // Cribbed from https://medium.com/@rbkhmrcr/precompiles-solidity-e5d29bd428c4 + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function bigModExp(uint256 base, uint256 exponent) internal view returns (uint256 exponentiation) { uint256 callResult; uint256[6] memory bigModExpContractInputs; @@ -153,7 +154,6 @@ contract VRF { bigModExpContractInputs[5] = FIELD_SIZE; uint256[1] memory output; assembly { - // solhint-disable-line no-inline-assembly callResult := staticcall( not(0), // Gas cost: no limit 0x05, // Bigmodexp contract address @@ -164,6 +164,7 @@ contract VRF { ) } if (callResult == 0) { + // solhint-disable-next-line custom-errors revert("bigModExp failure!"); } return output[0]; @@ -174,11 +175,13 @@ contract VRF { uint256 private constant SQRT_POWER = (FIELD_SIZE + 1) >> 2; // Computes a s.t. a^2 = x in the field. Assumes a exists + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function squareRoot(uint256 x) internal view returns (uint256) { return bigModExp(x, SQRT_POWER); } // The value of y^2 given that (x,y) is on secp256k1. + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function ySquared(uint256 x) internal pure returns (uint256) { // Curve is y^2=x^3+7. See section 2.4.1 of https://www.secg.org/sec2-v2.pdf uint256 xCubed = mulmod(x, mulmod(x, x, FIELD_SIZE), FIELD_SIZE); @@ -186,15 +189,19 @@ contract VRF { } // True iff p is on secp256k1 + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function isOnCurve(uint256[2] memory p) internal pure returns (bool) { // Section 2.3.6. in https://www.secg.org/sec1-v2.pdf // requires each ordinate to be in [0, ..., FIELD_SIZE-1] + // solhint-disable-next-line custom-errors require(p[0] < FIELD_SIZE, "invalid x-ordinate"); + // solhint-disable-next-line custom-errors require(p[1] < FIELD_SIZE, "invalid y-ordinate"); return ySquared(p[0]) == mulmod(p[1], p[1], FIELD_SIZE); } // Hash x uniformly into {0, ..., FIELD_SIZE-1}. + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fieldHash(bytes memory b) internal pure returns (uint256 x_) { x_ = uint256(keccak256(b)); // Rejecting if x >= FIELD_SIZE corresponds to step 2.1 in section 2.3.4 of @@ -211,6 +218,7 @@ contract VRF { // step 5.C, which references arbitrary_string_to_point, defined in // https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-vrf-05#section-5.5 as // returning the point with given x ordinate, and even y ordinate. + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function newCandidateSecp256k1Point(bytes memory b) internal view returns (uint256[2] memory p) { unchecked { p[0] = fieldHash(b); @@ -241,6 +249,7 @@ contract VRF { // // This would greatly simplify the analysis in "OTHER SECURITY CONSIDERATIONS" // https://www.pivotaltracker.com/story/show/171120900 + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function hashToCurve(uint256[2] memory pk, uint256 input) internal view returns (uint256[2] memory rv) { rv = newCandidateSecp256k1Point(abi.encodePacked(HASH_TO_CURVE_HASH_PREFIX, pk, input)); while (!isOnCurve(rv)) { @@ -258,11 +267,13 @@ contract VRF { * @param product: secp256k1 expected to be multiplier * multiplicand * @return verifies true iff product==scalar*multiplicand, with cryptographically high probability */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function ecmulVerify( uint256[2] memory multiplicand, uint256 scalar, uint256[2] memory product ) internal pure returns (bool verifies) { + // solhint-disable-next-line custom-errors require(scalar != 0, "zero scalar"); // Rules out an ecrecover failure case uint256 x = multiplicand[0]; // x ordinate of multiplicand uint8 v = multiplicand[1] % 2 == 0 ? 27 : 28; // parity of y ordinate @@ -278,6 +289,7 @@ contract VRF { } // Returns x1/z1-x2/z2=(x1z2-x2z1)/(z1z2) in projective coordinates on P¹(𝔽ₙ) + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function projectiveSub( uint256 x1, uint256 z1, @@ -294,6 +306,7 @@ contract VRF { } // Returns x1/z1*x2/z2=(x1x2)/(z1z2), in projective coordinates on P¹(𝔽ₙ) + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function projectiveMul( uint256 x1, uint256 z1, @@ -335,6 +348,7 @@ contract VRF { @return sy @return sz */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function projectiveECAdd( uint256 px, uint256 py, @@ -391,6 +405,7 @@ contract VRF { // // p1 and p2 must be distinct, because projectiveECAdd doesn't handle // point doubling. + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function affineECAdd( uint256[2] memory p1, uint256[2] memory p2, @@ -400,6 +415,7 @@ contract VRF { uint256 y; uint256 z; (x, y, z) = projectiveECAdd(p1[0], p1[1], p2[0], p2[1]); + // solhint-disable-next-line custom-errors require(mulmod(z, invZ, FIELD_SIZE) == 1, "invZ must be inverse of z"); // Clear the z ordinate of the projective representation by dividing through // by it, to obtain the affine representation @@ -408,6 +424,7 @@ contract VRF { // True iff address(c*p+s*g) == lcWitness, where g is generator. (With // cryptographically high probability.) + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function verifyLinearCombinationWithGenerator( uint256 c, uint256[2] memory p, @@ -416,6 +433,7 @@ contract VRF { ) internal pure returns (bool) { // Rule out ecrecover failure modes which return address 0. unchecked { + // solhint-disable-next-line custom-errors require(lcWitness != address(0), "bad witness"); uint8 v = (p[1] % 2 == 0) ? 27 : 28; // parity of y-ordinate of p // Note this cannot wrap (X - Y % X), but we use unchecked to save @@ -440,6 +458,7 @@ contract VRF { // a proof with equal c*p1 and s*p2, they should retry with a different // proof nonce.) Assumes that all points are on secp256k1 // (which is checked in verifyVRFProof below.) + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function linearCombination( uint256 c, uint256[2] memory p1, @@ -451,8 +470,11 @@ contract VRF { ) internal pure returns (uint256[2] memory) { unchecked { // Note we are relying on the wrap around here + // solhint-disable-next-line custom-errors require((cp1Witness[0] % FIELD_SIZE) != (sp2Witness[0] % FIELD_SIZE), "points in sum must be distinct"); + // solhint-disable-next-line custom-errors require(ecmulVerify(p1, c, cp1Witness), "First mul check failed"); + // solhint-disable-next-line custom-errors require(ecmulVerify(p2, s, sp2Witness), "Second mul check failed"); return affineECAdd(cp1Witness, sp2Witness, zInv); } @@ -473,6 +495,7 @@ contract VRF { // using the compressed representation of the points, if we collated the y // parities into a single bytes32. // https://www.pivotaltracker.com/story/show/171120588 + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function scalarFromCurvePoints( uint256[2] memory hash, uint256[2] memory pk, @@ -492,6 +515,7 @@ contract VRF { // the x ordinate, and the parity of the y ordinate in the top bit of uWitness // (which I could make a uint256 without using any extra space.) Would save // about 2000 gas. https://www.pivotaltracker.com/story/show/170828567 + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function verifyVRFProof( uint256[2] memory pk, uint256[2] memory gamma, @@ -504,15 +528,20 @@ contract VRF { uint256 zInv ) internal view { unchecked { + // solhint-disable-next-line custom-errors require(isOnCurve(pk), "public key is not on curve"); + // solhint-disable-next-line custom-errors require(isOnCurve(gamma), "gamma is not on curve"); + // solhint-disable-next-line custom-errors require(isOnCurve(cGammaWitness), "cGammaWitness is not on curve"); + // solhint-disable-next-line custom-errors require(isOnCurve(sHashWitness), "sHashWitness is not on curve"); // Step 5. of IETF draft section 5.3 (pk corresponds to 5.3's Y, and here // we use the address of u instead of u itself. Also, here we add the // terms instead of taking the difference, and in the proof construction in // vrf.GenerateProof, we correspondingly take the difference instead of // taking the sum as they do in step 7 of section 5.1.) + // solhint-disable-next-line custom-errors require(verifyLinearCombinationWithGenerator(c, pk, s, uWitness), "addr(c*pk+s*g)!=_uWitness"); // Step 4. of IETF draft section 5.3 (pk corresponds to Y, seed to alpha_string) uint256[2] memory hash = hashToCurve(pk, seed); @@ -520,6 +549,7 @@ contract VRF { uint256[2] memory v = linearCombination(c, gamma, cGammaWitness, s, hash, sHashWitness, zInv); // Steps 7. and 8. of IETF draft section 5.3 uint256 derivedC = scalarFromCurvePoints(hash, pk, gamma, uWitness, v); + // solhint-disable-next-line custom-errors require(c == derivedC, "invalid proof"); } } @@ -550,6 +580,7 @@ contract VRF { * @return output i.e., the random output implied by the proof * *************************************************************************** */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function randomValueFromVRFProof(Proof memory proof, uint256 seed) internal view returns (uint256 output) { verifyVRFProof( proof.pk, diff --git a/contracts/src/v0.8/vrf/VRFConsumerBase.sol b/contracts/src/v0.8/vrf/VRFConsumerBase.sol index 983a5b23cb7..7661ad40a30 100644 --- a/contracts/src/v0.8/vrf/VRFConsumerBase.sol +++ b/contracts/src/v0.8/vrf/VRFConsumerBase.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../shared/interfaces/LinkTokenInterface.sol"; +import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; -import "./VRFRequestIDBase.sol"; +import {VRFRequestIDBase} from "./VRFRequestIDBase.sol"; /** **************************************************************************** * @notice Interface for contracts using VRF randomness @@ -113,6 +113,7 @@ abstract contract VRFConsumerBase is VRFRequestIDBase { * @param requestId The Id initially returned by requestRandomness * @param randomness the VRF output */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual; /** @@ -149,6 +150,7 @@ abstract contract VRFConsumerBase is VRFRequestIDBase { * @dev concurrent requests. It is passed as the first argument to * @dev fulfillRandomness. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function requestRandomness(bytes32 _keyHash, uint256 _fee) internal returns (bytes32 requestId) { LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PLACEHOLDER)); // This is the seed passed to VRFCoordinator. The oracle will mix this with @@ -165,12 +167,15 @@ abstract contract VRFConsumerBase is VRFRequestIDBase { return makeRequestId(_keyHash, vRFSeed); } + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i LinkTokenInterface internal immutable LINK; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i address private immutable vrfCoordinator; // Nonces for each VRF key from which randomness has been requested. // // Must stay in sync with VRFCoordinator[_keyHash][this] + // solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore mapping(bytes32 => uint256) /* keyHash */ /* nonce */ private nonces; /** @@ -188,6 +193,7 @@ abstract contract VRFConsumerBase is VRFRequestIDBase { // proof. rawFulfillRandomness then calls fulfillRandomness, after validating // the origin of the call function rawFulfillRandomness(bytes32 requestId, uint256 randomness) external { + // solhint-disable-next-line custom-errors require(msg.sender == vrfCoordinator, "Only VRFCoordinator can fulfill"); fulfillRandomness(requestId, randomness); } diff --git a/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol b/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol index e023373ab0f..ad7025fc980 100644 --- a/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol +++ b/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol @@ -96,6 +96,7 @@ pragma solidity ^0.8.4; */ abstract contract VRFConsumerBaseV2 { error OnlyCoordinatorCanFulfill(address have, address want); + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i address private immutable vrfCoordinator; /** @@ -119,6 +120,7 @@ abstract contract VRFConsumerBaseV2 { * @param requestId The Id initially returned by requestRandomness * @param randomWords the VRF output expanded to the requested number of words */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual; // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF diff --git a/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol b/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol index bed0d361b35..92cb0cdb324 100644 --- a/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol +++ b/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol @@ -1,20 +1,23 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "../interfaces/BlockhashStoreInterface.sol"; -import "../interfaces/AggregatorV3Interface.sol"; -import "../interfaces/VRFCoordinatorV2Interface.sol"; -import "../interfaces/TypeAndVersionInterface.sol"; -import "../shared/interfaces/IERC677Receiver.sol"; -import "./VRF.sol"; -import "../shared/access/ConfirmedOwner.sol"; -import "./VRFConsumerBaseV2.sol"; -import "../ChainSpecificUtil.sol"; +import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; +import {BlockhashStoreInterface} from "../interfaces/BlockhashStoreInterface.sol"; +import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {TypeAndVersionInterface} from "../interfaces/TypeAndVersionInterface.sol"; +import {IERC677Receiver} from "../shared/interfaces/IERC677Receiver.sol"; +import {VRF} from "./VRF.sol"; +import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; +import {VRFConsumerBaseV2} from "./VRFConsumerBaseV2.sol"; +import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCoordinatorV2Interface, IERC677Receiver { + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i LinkTokenInterface public immutable LINK; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i AggregatorV3Interface public immutable LINK_ETH_FEED; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i BlockhashStoreInterface public immutable BLOCKHASH_STORE; // We need to maintain a list of consuming addresses. @@ -413,6 +416,7 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo return s_requestCommitments[requestId]; } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function computeRequestId( bytes32 keyHash, address sender, @@ -427,8 +431,8 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow @@ -457,6 +461,7 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo return success; } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getRandomnessFromProof( Proof memory proof, RequestCommitment memory rc @@ -569,6 +574,7 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo } // Get the amount of gas used for fulfillment + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculatePaymentAmount( uint256 startGas, uint256 gasAfterPaymentCalculation, @@ -592,6 +598,7 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo return uint96(paymentNoFee + fee); } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getFeedData() private view returns (int256) { uint32 stalenessSeconds = s_config.stalenessSeconds; bool staleFallback = stalenessSeconds > 0; @@ -766,6 +773,7 @@ contract VRFCoordinatorV2 is VRF, ConfirmedOwner, TypeAndVersionInterface, VRFCo cancelSubscriptionHelper(subId, to); } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function cancelSubscriptionHelper(uint64 subId, address to) private nonReentrant { SubscriptionConfig memory subConfig = s_subscriptionConfigs[subId]; Subscription memory sub = s_subscriptions[subId]; diff --git a/contracts/src/v0.8/vrf/VRFOwner.sol b/contracts/src/v0.8/vrf/VRFOwner.sol index 2c4adf36e8c..055308cac42 100644 --- a/contracts/src/v0.8/vrf/VRFOwner.sol +++ b/contracts/src/v0.8/vrf/VRFOwner.sol @@ -1,9 +1,10 @@ // SPDX-License-Identifier: MIT +// solhint-disable-next-line one-contract-per-file pragma solidity ^0.8.6; import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; import {AuthorizedReceiver} from "./AuthorizedReceiver.sol"; -import "./VRFTypes.sol"; +import {VRFTypes} from "./VRFTypes.sol"; // Taken from VRFCoordinatorV2.sol // Must be abi-compatible with what's there @@ -109,6 +110,7 @@ contract VRFOwner is ConfirmedOwner, AuthorizedReceiver { event RandomWordsForced(uint256 indexed requestId, uint64 indexed subId, address indexed sender); constructor(address _vrfCoordinator) ConfirmedOwner(msg.sender) { + // solhint-disable-next-line custom-errors require(_vrfCoordinator != address(0), "vrf coordinator address must be non-zero"); s_vrfCoordinator = IVRFCoordinatorV2(_vrfCoordinator); } @@ -192,6 +194,7 @@ contract VRFOwner is ConfirmedOwner, AuthorizedReceiver { * @param fallbackWeiPerUnitLink fallback eth/link price in the case of a stale feed * @param feeConfig fee tier configuration */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function setConfigPrivate( uint16 minimumRequestConfirmations, uint32 maxGasLimit, @@ -233,6 +236,7 @@ contract VRFOwner is ConfirmedOwner, AuthorizedReceiver { * @dev when too many local variables are in the same scope. * @return Config struct containing all relevant configs from the VRF coordinator. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getConfigs() private view returns (Config memory) { ( uint16 minimumRequestConfirmations, @@ -338,6 +342,7 @@ contract VRFOwner is ConfirmedOwner, AuthorizedReceiver { * @param proofSeed the proof seed * @dev Refer to VRFCoordinatorV2.getRandomnessFromProof for original implementation. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function requestIdFromProof(uint256[2] memory publicKey, uint256 proofSeed) private view returns (uint256) { bytes32 keyHash = s_vrfCoordinator.hashOfKey(publicKey); uint256 requestId = uint256(keccak256(abi.encode(keyHash, proofSeed))); diff --git a/contracts/src/v0.8/vrf/VRFRequestIDBase.sol b/contracts/src/v0.8/vrf/VRFRequestIDBase.sol index 7770640550e..ce0f6b1547a 100644 --- a/contracts/src/v0.8/vrf/VRFRequestIDBase.sol +++ b/contracts/src/v0.8/vrf/VRFRequestIDBase.sol @@ -16,6 +16,7 @@ contract VRFRequestIDBase { * @param _requester Address of the requesting contract * @param _nonce User-specific nonce at the time of the request */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function makeVRFInputSeed( bytes32 _keyHash, uint256 _userSeed, @@ -34,6 +35,7 @@ contract VRFRequestIDBase { * @dev Note that _vRFInputSeed is not the seed passed by the consuming * @dev contract, but the one generated by makeVRFInputSeed */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function makeRequestId(bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed)); } diff --git a/contracts/src/v0.8/vrf/VRFV2Wrapper.sol b/contracts/src/v0.8/vrf/VRFV2Wrapper.sol index 101e1bdfe20..3573b972276 100644 --- a/contracts/src/v0.8/vrf/VRFV2Wrapper.sol +++ b/contracts/src/v0.8/vrf/VRFV2Wrapper.sol @@ -1,15 +1,16 @@ // SPDX-License-Identifier: MIT +// solhint-disable-next-line one-contract-per-file pragma solidity ^0.8.6; -import "../shared/access/ConfirmedOwner.sol"; -import "../interfaces/TypeAndVersionInterface.sol"; -import "./VRFConsumerBaseV2.sol"; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "../interfaces/AggregatorV3Interface.sol"; -import "../interfaces/VRFCoordinatorV2Interface.sol"; -import "../interfaces/VRFV2WrapperInterface.sol"; -import "./VRFV2WrapperConsumerBase.sol"; -import "../ChainSpecificUtil.sol"; +import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; +import {TypeAndVersionInterface} from "../interfaces/TypeAndVersionInterface.sol"; +import {VRFConsumerBaseV2} from "./VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; +import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFV2WrapperInterface} from "../interfaces/VRFV2WrapperInterface.sol"; +import {VRFV2WrapperConsumerBase} from "./VRFV2WrapperConsumerBase.sol"; +import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; /** * @notice A wrapper for VRFCoordinatorV2 that provides an interface better suited to one-off @@ -18,9 +19,13 @@ import "../ChainSpecificUtil.sol"; contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBaseV2, VRFV2WrapperInterface { event WrapperFulfillmentFailed(uint256 indexed requestId, address indexed consumer); + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i LinkTokenInterface public immutable LINK; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i AggregatorV3Interface public immutable LINK_ETH_FEED; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i ExtendedVRFCoordinatorV2Interface public immutable COORDINATOR; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i uint64 public immutable SUBSCRIPTION_ID; /// @dev this is the size of a VRF v2 fulfillment's calldata abi-encoded in bytes. /// @dev proofSize = 13 words = 13 * 256 = 3328 bits @@ -78,10 +83,10 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas // s_keyHash is the key hash to use when requesting randomness. Fees are paid based on current gas // fees, so this should be set to the highest gas lane on the network. - bytes32 s_keyHash; + bytes32 internal s_keyHash; // s_maxNumWords is the max number of words that can be requested in a single wrapped VRF request. - uint8 s_maxNumWords; + uint8 internal s_maxNumWords; struct Callback { address callbackAddress; @@ -237,6 +242,7 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas return calculateRequestPriceInternal(_callbackGasLimit, _requestGasPriceWei, weiPerUnitLink); } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function calculateRequestPriceInternal( uint256 _gas, uint256 _requestGasPrice, @@ -273,6 +279,7 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas * uint16 requestConfirmations, and uint32 numWords. */ function onTokenTransfer(address _sender, uint256 _amount, bytes calldata _data) external onlyConfiguredNotDisabled { + // solhint-disable-next-line custom-errors require(msg.sender == address(LINK), "only callable from LINK"); (uint32 callbackGasLimit, uint16 requestConfirmations, uint32 numWords) = abi.decode( @@ -282,7 +289,9 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas uint32 eip150Overhead = getEIP150Overhead(callbackGasLimit); int256 weiPerUnitLink = getFeedData(); uint256 price = calculateRequestPriceInternal(callbackGasLimit, tx.gasprice, weiPerUnitLink); + // solhint-disable-next-line custom-errors require(_amount >= price, "fee too low"); + // solhint-disable-next-line custom-errors require(numWords <= s_maxNumWords, "numWords too high"); uint256 requestId = COORDINATOR.requestRandomWords( @@ -328,9 +337,11 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas s_disabled = true; } + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { Callback memory callback = s_callbacks[_requestId]; delete s_callbacks[_requestId]; + // solhint-disable-next-line custom-errors require(callback.callbackAddress != address(0), "request not found"); // This should never happen VRFV2WrapperConsumerBase c; @@ -342,6 +353,7 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas } } + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getFeedData() private view returns (int256) { bool staleFallback = s_stalenessSeconds > 0; uint256 timestamp; @@ -351,6 +363,7 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas if (staleFallback && s_stalenessSeconds < block.timestamp - timestamp) { weiPerUnitLink = s_fallbackWeiPerUnitLink; } + // solhint-disable-next-line custom-errors require(weiPerUnitLink >= 0, "Invalid LINK wei price"); return weiPerUnitLink; } @@ -358,6 +371,7 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas /** * @dev Calculates extra amount of gas required for running an assembly call() post-EIP150. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function getEIP150Overhead(uint32 gas) private pure returns (uint32) { return gas / 63 + 1; } @@ -366,8 +380,8 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas * @dev calls target address with exactly gasAmount gas and data as calldata * or reverts if at least gasAmount gas is not available. */ + // solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) { - // solhint-disable-next-line no-inline-assembly assembly { let g := gas() // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow @@ -401,7 +415,9 @@ contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBas } modifier onlyConfiguredNotDisabled() { + // solhint-disable-next-line custom-errors require(s_configured, "wrapper is not configured"); + // solhint-disable-next-line custom-errors require(!s_disabled, "wrapper is disabled"); _; } diff --git a/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol b/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol index 4c7918e8b7a..a9c8e5568a9 100644 --- a/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol +++ b/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "../interfaces/VRFV2WrapperInterface.sol"; +import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; +import {VRFV2WrapperInterface} from "../interfaces/VRFV2WrapperInterface.sol"; /** ******************************************************************************* * @notice Interface for contracts using VRF randomness through the VRF V2 wrapper @@ -28,7 +28,9 @@ import "../interfaces/VRFV2WrapperInterface.sol"; * @dev fulfillment with the randomness result. */ abstract contract VRFV2WrapperConsumerBase { + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i LinkTokenInterface internal immutable LINK; + // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i VRFV2WrapperInterface internal immutable VRF_V2_WRAPPER; /** @@ -52,6 +54,7 @@ abstract contract VRFV2WrapperConsumerBase { * * @return requestId is the VRF V2 request ID of the newly created randomness request. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function requestRandomness( uint32 _callbackGasLimit, uint16 _requestConfirmations, @@ -72,9 +75,11 @@ abstract contract VRFV2WrapperConsumerBase { * @param _requestId is the VRF V2 request ID. * @param _randomWords is the randomness result. */ + // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual; function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external { + // solhint-disable-next-line custom-errors require(msg.sender == address(VRF_V2_WRAPPER), "only VRF V2 wrapper can fulfill"); fulfillRandomWords(_requestId, _randomWords); } diff --git a/core/gethwrappers/generated/vrfv2plus_malicious_migrator/vrfv2plus_malicious_migrator.go b/core/gethwrappers/generated/vrfv2plus_malicious_migrator/vrfv2plus_malicious_migrator.go index 043ee6e303f..c0c19a1134c 100644 --- a/core/gethwrappers/generated/vrfv2plus_malicious_migrator/vrfv2plus_malicious_migrator.go +++ b/core/gethwrappers/generated/vrfv2plus_malicious_migrator/vrfv2plus_malicious_migrator.go @@ -29,7 +29,7 @@ var ( ) var VRFV2PlusMaliciousMigratorMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_vrfCoordinator\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_vrfCoordinator\",\"type\":\"address\"}],\"name\":\"setCoordinator\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_vrfCoordinator\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"setCoordinator\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", Bin: "0x608060405234801561001057600080fd5b506040516102e03803806102e083398101604081905261002f91610054565b600080546001600160a01b0319166001600160a01b0392909216919091179055610084565b60006020828403121561006657600080fd5b81516001600160a01b038116811461007d57600080fd5b9392505050565b61024d806100936000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80638ea9811714610030575b600080fd5b61004361003e36600461012a565b610045565b005b600080546040805160c081018252838152602080820185905281830185905260608201859052608082018590528251908101835293845260a0810193909352517f9b1c385e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911691639b1c385e916100d49190600401610180565b602060405180830381600087803b1580156100ee57600080fd5b505af1158015610102573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101269190610167565b5050565b60006020828403121561013c57600080fd5b813573ffffffffffffffffffffffffffffffffffffffff8116811461016057600080fd5b9392505050565b60006020828403121561017957600080fd5b5051919050565b6000602080835283518184015280840151604084015261ffff6040850151166060840152606084015163ffffffff80821660808601528060808701511660a0860152505060a084015160c08085015280518060e086015260005b818110156101f757828101840151868201610100015283016101da565b8181111561020a57600061010083880101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016939093016101000194935050505056fea164736f6c6343000806000a", } @@ -169,16 +169,16 @@ func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorTransactorRaw) Tran return _VRFV2PlusMaliciousMigrator.Contract.contract.Transact(opts, method, params...) } -func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorTransactor) SetCoordinator(opts *bind.TransactOpts, _vrfCoordinator common.Address) (*types.Transaction, error) { - return _VRFV2PlusMaliciousMigrator.contract.Transact(opts, "setCoordinator", _vrfCoordinator) +func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorTransactor) SetCoordinator(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) { + return _VRFV2PlusMaliciousMigrator.contract.Transact(opts, "setCoordinator", arg0) } -func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorSession) SetCoordinator(_vrfCoordinator common.Address) (*types.Transaction, error) { - return _VRFV2PlusMaliciousMigrator.Contract.SetCoordinator(&_VRFV2PlusMaliciousMigrator.TransactOpts, _vrfCoordinator) +func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorSession) SetCoordinator(arg0 common.Address) (*types.Transaction, error) { + return _VRFV2PlusMaliciousMigrator.Contract.SetCoordinator(&_VRFV2PlusMaliciousMigrator.TransactOpts, arg0) } -func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorTransactorSession) SetCoordinator(_vrfCoordinator common.Address) (*types.Transaction, error) { - return _VRFV2PlusMaliciousMigrator.Contract.SetCoordinator(&_VRFV2PlusMaliciousMigrator.TransactOpts, _vrfCoordinator) +func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigratorTransactorSession) SetCoordinator(arg0 common.Address) (*types.Transaction, error) { + return _VRFV2PlusMaliciousMigrator.Contract.SetCoordinator(&_VRFV2PlusMaliciousMigrator.TransactOpts, arg0) } func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigrator) Address() common.Address { @@ -186,7 +186,7 @@ func (_VRFV2PlusMaliciousMigrator *VRFV2PlusMaliciousMigrator) Address() common. } type VRFV2PlusMaliciousMigratorInterface interface { - SetCoordinator(opts *bind.TransactOpts, _vrfCoordinator common.Address) (*types.Transaction, error) + SetCoordinator(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) Address() common.Address } diff --git a/core/gethwrappers/generation/generated-wrapper-dependency-versions-do-not-edit.txt b/core/gethwrappers/generation/generated-wrapper-dependency-versions-do-not-edit.txt index 5251d94e70c..ac0786a8bb5 100644 --- a/core/gethwrappers/generation/generated-wrapper-dependency-versions-do-not-edit.txt +++ b/core/gethwrappers/generation/generated-wrapper-dependency-versions-do-not-edit.txt @@ -100,7 +100,7 @@ vrfv2_wrapper_consumer_example: ../../contracts/solc/v0.8.6/VRFV2WrapperConsumer vrfv2_wrapper_interface: ../../contracts/solc/v0.8.6/VRFV2WrapperInterface.abi ../../contracts/solc/v0.8.6/VRFV2WrapperInterface.bin ff8560169de171a68b360b7438d13863682d07040d984fd0fb096b2379421003 vrfv2plus_client: ../../contracts/solc/v0.8.6/VRFV2PlusClient.abi ../../contracts/solc/v0.8.6/VRFV2PlusClient.bin 3ffbfa4971a7e5f46051a26b1722613f265d89ea1867547ecec58500953a9501 vrfv2plus_consumer_example: ../../contracts/solc/v0.8.6/VRFV2PlusConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusConsumerExample.bin 2c480a6d7955d33a00690fdd943486d95802e48a03f3cc243df314448e4ddb2c -vrfv2plus_malicious_migrator: ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.abi ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.bin e5ae923d5fdfa916303cd7150b8474ccd912e14bafe950c6431f6ec94821f642 +vrfv2plus_malicious_migrator: ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.abi ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.bin 80dbc98be5e42246960c889d29488f978d3db0127e95e9b295352c481d8c9b07 vrfv2plus_reverting_example: ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.bin 34743ac1dd5e2c9d210b2bd721ebd4dff3c29c548f05582538690dde07773589 vrfv2plus_wrapper: ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.bin 3e1e3836e8c8bf7a6f83f571f17e258f30e6d02037e53eebf74c2af3fbcf0913 vrfv2plus_wrapper_consumer_example: ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.bin 4b3da45ff177e09b1e731b5b0cf4e050033a600ef8b0d32e79eec97db5c72408