Skip to content

Commit

Permalink
Merge branch 'develop' into feature/BCI-2649-latest-finalized-block
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaidashenko committed Mar 12, 2024
2 parents 4a117c4 + 2e08d9b commit 00cbb2e
Show file tree
Hide file tree
Showing 25 changed files with 220 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-weeks-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

update AutomationBase interface to check for ready only address on polygon zkEVM
5 changes: 5 additions & 0 deletions .changeset/fresh-spies-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Update automation smoke test to use UpkeepCounter with time based counter
5 changes: 5 additions & 0 deletions .changeset/pretty-fishes-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

VRF V2+ Coordinator msg.data len validation
5 changes: 5 additions & 0 deletions .changeset/wild-walls-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Validate if flat fee configs are configured correctly
2 changes: 1 addition & 1 deletion contracts/src/v0.8/automation/AutomationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract AutomationBase {
*/
function _preventExecution() internal view {
// solhint-disable-next-line avoid-tx-origin
if (tx.origin != address(0)) {
if (tx.origin != address(0) && tx.origin != address(0x1111111111111111111111111111111111111111)) {
revert OnlySimulatedBackend();
}
}
Expand Down
28 changes: 14 additions & 14 deletions contracts/src/v0.8/automation/testhelpers/UpkeepCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ pragma solidity 0.8.16;
contract UpkeepCounter {
event PerformingUpkeep(
address indexed from,
uint256 initialBlock,
uint256 lastBlock,
uint256 initialTimestamp,
uint256 lastTimestamp,
uint256 previousBlock,
uint256 counter
);

uint256 public testRange;
uint256 public interval;
uint256 public lastBlock;
uint256 public lastTimestamp;
uint256 public previousPerformBlock;
uint256 public initialBlock;
uint256 public initialTimestamp;
uint256 public counter;

constructor(uint256 _testRange, uint256 _interval) {
testRange = _testRange;
interval = _interval;
previousPerformBlock = 0;
lastBlock = block.number;
initialBlock = 0;
lastTimestamp = block.timestamp;
initialTimestamp = 0;
counter = 0;
}

Expand All @@ -31,28 +31,28 @@ contract UpkeepCounter {
}

function performUpkeep(bytes calldata performData) external {
if (initialBlock == 0) {
initialBlock = block.number;
if (initialTimestamp == 0) {
initialTimestamp = block.timestamp;
}
lastBlock = block.number;
lastTimestamp = block.timestamp;
counter = counter + 1;
performData;
emit PerformingUpkeep(tx.origin, initialBlock, lastBlock, previousPerformBlock, counter);
previousPerformBlock = lastBlock;
emit PerformingUpkeep(tx.origin, initialTimestamp, lastTimestamp, previousPerformBlock, counter);
previousPerformBlock = lastTimestamp;
}

function eligible() public view returns (bool) {
if (initialBlock == 0) {
if (initialTimestamp == 0) {
return true;
}

return (block.number - initialBlock) < testRange && (block.number - lastBlock) >= interval;
return (block.timestamp - initialTimestamp) < testRange && (block.timestamp - lastTimestamp) >= interval;
}

function setSpread(uint256 _testRange, uint256 _interval) external {
testRange = _testRange;
interval = _interval;
initialBlock = 0;
initialTimestamp = 0;
counter = 0;
}
}
29 changes: 28 additions & 1 deletion contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
error InvalidRequestConfirmations(uint16 have, uint16 min, uint16 max);
error GasLimitTooBig(uint32 have, uint32 want);
error NumWordsTooBig(uint32 have, uint32 want);
error MsgDataTooBig(uint256 have, uint32 max);
error ProvingKeyAlreadyRegistered(bytes32 keyHash);
error NoSuchProvingKey(bytes32 keyHash);
error InvalidLinkWeiPrice(int256 linkWei);
Expand Down Expand Up @@ -176,7 +177,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
if (fallbackWeiPerUnitLink <= 0) {
revert InvalidLinkWeiPrice(fallbackWeiPerUnitLink);
}
if (fulfillmentFlatFeeNativePPM > 0 && fulfillmentFlatFeeLinkDiscountPPM >= fulfillmentFlatFeeNativePPM) {
if (fulfillmentFlatFeeLinkDiscountPPM > fulfillmentFlatFeeNativePPM) {
revert LinkDiscountTooHigh(fulfillmentFlatFeeLinkDiscountPPM, fulfillmentFlatFeeNativePPM);
}
s_config = Config({
Expand Down Expand Up @@ -444,6 +445,32 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
bool onlyPremium
) external nonReentrant returns (uint96 payment) {
uint256 startGas = gasleft();
// fulfillRandomWords msg.data has 772 bytes and with an additional
// buffer of 32 bytes, we get 804 bytes.
/* Data size split:
* fulfillRandomWords function signature - 4 bytes
* proof - 416 bytes
* pk - 64 bytes
* gamma - 64 bytes
* c - 32 bytes
* s - 32 bytes
* seed - 32 bytes
* uWitness - 32 bytes
* cGammaWitness - 64 bytes
* sHashWitness - 64 bytes
* zInv - 32 bytes
* requestCommitment - 320 bytes
* blockNum - 32 bytes
* subId - 32 bytes
* callbackGasLimit - 32 bytes
* numWords - 32 bytes
* sender - 32 bytes
* extraArgs - 128 bytes
* onlyPremium - 32 bytes
*/
if (msg.data.length > 804) {
revert MsgDataTooBig(msg.data.length, 804);
}
Output memory output = _getRandomnessFromProof(proof, rc);
uint256 gasPrice = _getValidatedGasPrice(onlyPremium, output.provingKey.maxGas);

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/v0.8/automation/KeeperRegistry1_2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { toWei } from '../../test-helpers/helpers'

const BYTECODE = KeeperRegistryFactory.bytecode
const BYTECODE_CHECKSUM =
'0x8e465b93eae52724b7edbef5bc133c96520dad33f959373e5d026549ca40158c'
'0x4a23953416a64a0fa4c943954d9a92059f862257440f2cbcf5f238314b89f416'

describe('KeeperRegistry1_2 - Frozen [ @skip-coverage ]', () => {
it('has not changed', () => {
Expand Down
17 changes: 15 additions & 2 deletions contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ contract VRFV2Plus is BaseTest {
);

// Test that setting link discount flat fee higher than native flat fee reverts
vm.expectRevert(abi.encodeWithSelector(VRFCoordinatorV2_5.LinkDiscountTooHigh.selector, uint32(1000), uint32(500)));
vm.expectRevert(abi.encodeWithSelector(VRFCoordinatorV2_5.LinkDiscountTooHigh.selector, uint32(501), uint32(500)));

s_testCoordinator.setConfig(
0,
Expand All @@ -145,7 +145,20 @@ contract VRFV2Plus is BaseTest {
50_000,
500,
500, // fulfillmentFlatFeeNativePPM
1000, // fulfillmentFlatFeeLinkDiscountPPM
501, // fulfillmentFlatFeeLinkDiscountPPM
15, // nativePremiumPercentage
10 // linkPremiumPercentage
);

// // Test that setting link discount flat fee equal to native flat fee does not revert
s_testCoordinator.setConfig(
0,
2_500_000,
1,
50_000,
500,
450, // fulfillmentFlatFeeNativePPM
450, // fulfillmentFlatFeeLinkDiscountPPM
15, // nativePremiumPercentage
10 // linkPremiumPercentage
);
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func newMockRpc(t *testing.T) *mocks.RPCClient {
mockRpc.On("Dial", mock.Anything).Return(nil).Once()
mockRpc.On("Close").Return(nil).Once()
mockRpc.On("ChainID", mock.Anything).Return(testutils.FixtureChainID, nil).Once()
mockRpc.On("Subscribe", mock.Anything, mock.Anything, mock.Anything).Return(client.NewMockSubscription(), nil).Once()
mockRpc.On("SetAliveLoopSub", mock.Anything).Return().Once()
// node does not always manage to fully setup aliveLoop, so we have to make calls optional to avoid flakes
mockRpc.On("Subscribe", mock.Anything, mock.Anything, mock.Anything).Return(client.NewMockSubscription(), nil).Maybe()
mockRpc.On("SetAliveLoopSub", mock.Anything).Return().Maybe()
return mockRpc
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading

0 comments on commit 00cbb2e

Please sign in to comment.