Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRF-591: add ctf test for VRF V2 Plus direct funding #10721

Merged
merged 24 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1ce3cd7
VRF-591: add ctf test for VRF V2 Plus direct funding
iljapavlovs Sep 19, 2023
ce41f21
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 19, 2023
5d21c2b
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 19, 2023
54533e3
VRF-591: add missing gethwrapper
iljapavlovs Sep 19, 2023
6b9d5ba
VRF-591: fix test
iljapavlovs Sep 20, 2023
984a4b6
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 20, 2023
e33ddd8
VRF-591: uncomment eth funding
iljapavlovs Sep 20, 2023
7796668
VRF-591: fixing eth funding
iljapavlovs Sep 20, 2023
3f8a3a3
VRF-591: update
iljapavlovs Sep 20, 2023
52bc69e
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 20, 2023
773f936
VRF-591: add native billing test
iljapavlovs Sep 20, 2023
006df6e
Merge remote-tracking branch 'origin/chore/VRF-591-add-ctf-test-vrfv2…
iljapavlovs Sep 20, 2023
8d163ca
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 20, 2023
884e784
VRF-591: fixing lint
iljapavlovs Sep 20, 2023
6152a94
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 20, 2023
6e58a74
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 21, 2023
0a1dd02
VRF-591: updating comment with bug reference
iljapavlovs Sep 21, 2023
3ffe563
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 21, 2023
9ad382d
VRF-591: use explicit types for logging
iljapavlovs Sep 21, 2023
8920e3f
Merge remote-tracking branch 'origin/chore/VRF-591-add-ctf-test-vrfv2…
iljapavlovs Sep 21, 2023
6e649b3
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 21, 2023
f1b0ef6
VRF-591: refactoring consumer contract
iljapavlovs Sep 21, 2023
7c2fbb7
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 21, 2023
b717617
Merge branch 'develop' into chore/VRF-591-add-ctf-test-vrfv2plus-wrapper
iljapavlovs Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_vrf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ compileContract dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol
compileContract dev/vrf/TrustedBlockhashStore.sol
compileContract dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol
compileContractAltOpts dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5
compileContract dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol

# VRF V2 Wrapper
compileContract vrf/VRFV2Wrapper.sol
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import "../VRFV2PlusWrapperConsumerBase.sol";
import "../../../shared/access/ConfirmedOwner.sol";
import "../../../ChainSpecificUtil.sol";

contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, ConfirmedOwner {
uint256 public s_responseCount;
uint256 public s_requestCount;
uint256 public s_averageFulfillmentInMillions = 0; // in millions for better precision
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

event WrappedRequestFulfilled(uint256 requestId, uint256[] randomWords, uint256 payment);
event WrapperRequestMade(uint256 indexed requestId, uint256 paid);

struct RequestStatus {
uint256 paid;
bool fulfilled;
uint256[] randomWords;
uint requestTimestamp;
uint fulfilmentTimestamp;
uint256 requestBlockNumber;
uint256 fulfilmentBlockNumber;
bool native;
}

mapping(uint256 => RequestStatus) /* requestId */ /* requestStatus */ public s_requests;

constructor(
address _link,
address _vrfV2PlusWrapper
) ConfirmedOwner(msg.sender) VRFV2PlusWrapperConsumerBase(_link, _vrfV2PlusWrapper) {}

function makeRequests(
uint32 _callbackGasLimit,
uint16 _requestConfirmations,
uint32 _numWords,
uint16 _requestCount
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
uint256 requestId = requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords);
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 paid = VRF_V2_PLUS_WRAPPER.calculateRequestPrice(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
randomWords: new uint256[](0),
requestTimestamp: block.timestamp,
requestBlockNumber: requestBlockNumber,
fulfilmentTimestamp: 0,
fulfilmentBlockNumber: 0,
native: false
});
s_requestCount++;
requestHeights[requestId] = requestBlockNumber;
emit WrapperRequestMade(requestId, paid);
}
}

function makeRequestsNative(
uint32 _callbackGasLimit,
uint16 _requestConfirmations,
uint32 _numWords,
uint16 _requestCount
) external onlyOwner {
for (uint16 i = 0; i < _requestCount; i++) {
uint256 requestId = requestRandomnessPayInNative(_callbackGasLimit, _requestConfirmations, _numWords);
iljapavlovs marked this conversation as resolved.
Show resolved Hide resolved
s_lastRequestId = requestId;

uint256 requestBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 paid = VRF_V2_PLUS_WRAPPER.calculateRequestPriceNative(_callbackGasLimit);
s_requests[requestId] = RequestStatus({
paid: paid,
fulfilled: false,
randomWords: new uint256[](0),
requestTimestamp: block.timestamp,
requestBlockNumber: requestBlockNumber,
fulfilmentTimestamp: 0,
fulfilmentBlockNumber: 0,
native: true
});
s_requestCount++;
requestHeights[requestId] = requestBlockNumber;
emit WrapperRequestMade(requestId, paid);
}
}

function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override {
require(s_requests[_requestId].paid > 0, "request not found");
uint256 fulfilmentBlockNumber = ChainSpecificUtil.getBlockNumber();
uint256 requestDelay = fulfilmentBlockNumber - requestHeights[_requestId];
uint256 requestDelayInMillions = requestDelay * 1_000_000;

if (requestDelay > s_slowestFulfillment) {
s_slowestFulfillment = requestDelay;
}
s_fastestFulfillment = requestDelay < s_fastestFulfillment ? requestDelay : s_fastestFulfillment;
s_averageFulfillmentInMillions = s_responseCount > 0
? (s_averageFulfillmentInMillions * s_responseCount + requestDelayInMillions) / (s_responseCount + 1)
: requestDelayInMillions;

s_responseCount++;
s_requests[_requestId].fulfilled = true;
s_requests[_requestId].randomWords = _randomWords;
s_requests[_requestId].fulfilmentTimestamp = block.timestamp;
s_requests[_requestId].fulfilmentBlockNumber = fulfilmentBlockNumber;

emit WrappedRequestFulfilled(_requestId, _randomWords, s_requests[_requestId].paid);
}

function getRequestStatus(
uint256 _requestId
)
external
view
returns (
uint256 paid,
bool fulfilled,
uint256[] memory randomWords,
uint requestTimestamp,
uint fulfilmentTimestamp,
uint256 requestBlockNumber,
uint256 fulfilmentBlockNumber
)
{
require(s_requests[_requestId].paid > 0, "request not found");
RequestStatus memory request = s_requests[_requestId];
return (
request.paid,
request.fulfilled,
request.randomWords,
request.requestTimestamp,
request.fulfilmentTimestamp,
request.requestBlockNumber,
request.fulfilmentBlockNumber
);
}

function reset() external {
s_averageFulfillmentInMillions = 0; // in millions for better precision
s_slowestFulfillment = 0;
s_fastestFulfillment = 999;
s_requestCount = 0;
s_responseCount = 0;
}

/// @notice withdrawLink withdraws the amount specified in amount to the owner
/// @param amount the amount to withdraw, in juels
function withdrawLink(uint256 amount) external onlyOwner {
LINK.transfer(owner(), amount);
}

/// @notice withdrawNative withdraws the amount specified in amount to the owner
/// @param amount the amount to withdraw, in wei
function withdrawNative(uint256 amount) external onlyOwner {
(bool success, ) = payable(owner()).call{value: amount}("");
require(success, "withdrawNative failed");
}

function getWrapper() external view returns (VRFV2PlusWrapperInterface) {
return VRF_V2_PLUS_WRAPPER;
}

receive() external payable {}

function getBalance() public view returns (uint) {
return address(this).balance;
}
iljapavlovs marked this conversation as resolved.
Show resolved Hide resolved
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ vrfv2plus_malicious_migrator: ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigr
vrfv2plus_reverting_example: ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample.bin d8f9b537f4f75535e3fca943d5f2d5b891fc63f38eb04e0c219fee28033883ae
vrfv2plus_wrapper: ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapper.bin d30c6232e24e7f6007bd9e46c23534d8da17fbf332f9dfd6485a476ef1be0af9
vrfv2plus_wrapper_consumer_example: ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample.bin d4ddf86da21b87c013f551b2563ab68712ea9d4724894664d5778f6b124f4e78
vrfv2plus_wrapper_load_test_consumer: ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.bin 8212afe0f981cd0820f46f1e2e98219ce5d1b1eeae502730dbb52b8638f9ad44
1 change: 1 addition & 0 deletions core/gethwrappers/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ package gethwrappers
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.abi ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator.bin VRFV2PlusMaliciousMigrator vrfv2plus_malicious_migrator
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics.abi ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics.bin VRFV2PlusLoadTestWithMetrics vrf_v2plus_load_test_with_metrics
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion.bin VRFCoordinatorV2PlusUpgradedVersion vrf_v2plus_upgraded_version
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer.bin VRFV2PlusWrapperLoadTestConsumer vrfv2plus_wrapper_load_test_consumer

// Aggregators
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/AggregatorV2V3Interface.abi ../../contracts/solc/v0.8.6/AggregatorV2V3Interface.bin AggregatorV2V3Interface aggregator_v2v3_interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
LinkEthFeedResponse = big.NewInt(1e18)
MinimumConfirmations = uint16(3)
RandomnessRequestCountPerRequest = uint16(1)
VRFSubscriptionFundingAmountLink = big.NewInt(100)
VRFSubscriptionFundingAmountLink = big.NewInt(10)
VRFSubscriptionFundingAmountNativeToken = big.NewInt(1)
ChainlinkNodeFundingAmountEth = big.NewFloat(0.1)
NumberOfWords = uint32(3)
Expand All @@ -28,4 +28,12 @@ var (
FulfillmentFlatFeeLinkPPM: 500,
FulfillmentFlatFeeEthPPM: 500,
}

WrapperGasOverhead = uint32(50_000)
CoordinatorGasOverhead = uint32(52_000)
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to revisit these values after ongoing investigations regarding gas

WrapperPremiumPercentage = uint8(25)
WrapperMaxNumberOfWords = uint8(10)
WrapperConsumerFundingAmountNativeToken = big.NewFloat(1)

WrapperConsumerFundingAmountLink = big.NewInt(10)
)
5 changes: 5 additions & 0 deletions integration-tests/actions/vrfv2plus/vrfv2plus_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ type VRFV2PlusContracts struct {
BHS contracts.BlockHashStore
LoadTestConsumers []contracts.VRFv2PlusLoadTestConsumer
}

type VRFV2PlusWrapperContracts struct {
VRFV2PlusWrapper contracts.VRFV2PlusWrapper
LoadTestConsumers []contracts.VRFv2PlusWrapperLoadTestConsumer
}
Loading
Loading