Skip to content

Commit

Permalink
Merge branch 'develop' into BCI-2531-extract-core-store-models
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov authored Jan 4, 2024
2 parents ccfb274 + e3fe671 commit 83b6ad1
Show file tree
Hide file tree
Showing 44 changed files with 1,130 additions and 535 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,12 @@ jobs:
nodes: 1
os: ubuntu-latest
file: ocr
pyroscope_env: ci-smoke-ocr-evm-simulated
pyroscope_env: ci-smoke-ocr-evm-simulated
- name: ocr2
nodes: 1
os: ubuntu-latest
file: ocr2
pyroscope_env: ci-smoke-ocr2-evm-simulated
- name: ocr2
nodes: 1
os: ubuntu-latest
run: -run TestOCRv2Request
file: ocr2
pyroscope_env: ci-smoke-ocr2-evm-simulated
pyroscope_env: ci-smoke-ocr2-evm-simulated
- name: ocr2
nodes: 1
os: ubuntu-latest
Expand All @@ -358,7 +352,7 @@ jobs:
- name: vrfv2plus
nodes: 1
os: ubuntu-latest
pyroscope_env: ci-smoke-vrf2plus-evm-simulated
pyroscope_env: ci-smoke-vrf2plus-evm-simulated
- name: forwarder_ocr
nodes: 1
os: ubuntu-latest
Expand Down
9 changes: 5 additions & 4 deletions charts/chainlink-cluster/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ pipelines:
# You can run this pipeline via `devspace deploy` (or `devspace run-pipeline deploy`)
deploy:
run: |-
run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
ensure_pull_secrets --all # 2. Ensure pull secrets
build_images --all -t $(git rev-parse --short HEAD) # 3. Build, tag (git commit hash) and push all images (see "images")
create_deployments --all # 5. Deploy Helm charts and manifests specfied as "deployments"
run_dependencies --all
ensure_pull_secrets --all
build_images ---var DOCKER_DEFAULT_PLATFORM=linux/amd64 --all -t $(git rev-parse --short HEAD)
kubectl annotate namespace ${DEVSPACE_NAMESPACE} janitor/ttl=${NS_TTL}
kubectl label namespace/${DEVSPACE_NAMESPACE} network=crib
create_deployments --all
echo "Namespace ${DEVSPACE_NAMESPACE} will be deleted in ${NS_TTL}"
purge:
run: |-
Expand Down
22 changes: 12 additions & 10 deletions contracts/src/v0.8/vrf/dev/SubscriptionAPI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr
// A discrepancy with this contract's native balance indicates someone
// sent native using transfer and so we may need to use recoverNativeFunds.
uint96 public s_totalNativeBalance;
mapping(address => uint96) /* oracle */ /* LINK balance */ internal s_withdrawableTokens;
mapping(address => uint96) /* oracle */ /* native balance */ internal s_withdrawableNative;
uint96 internal s_withdrawableTokens;
uint96 internal s_withdrawableNative;

event SubscriptionCreated(uint256 indexed subId, address owner);
event SubscriptionFunded(uint256 indexed subId, uint256 oldBalance, uint256 newBalance);
Expand Down Expand Up @@ -204,35 +204,37 @@ abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscr
}

/*
* @notice Oracle withdraw LINK earned through fulfilling requests
* @notice withdraw LINK earned through fulfilling requests
* @param recipient where to send the funds
* @param amount amount to withdraw
*/
function oracleWithdraw(address recipient, uint96 amount) external nonReentrant {
function withdraw(address recipient) external nonReentrant onlyOwner {
if (address(LINK) == address(0)) {
revert LinkNotSet();
}
if (s_withdrawableTokens[msg.sender] < amount) {
if (s_withdrawableTokens == 0) {
revert InsufficientBalance();
}
s_withdrawableTokens[msg.sender] -= amount;
uint96 amount = s_withdrawableTokens;
s_withdrawableTokens -= amount;
s_totalBalance -= amount;
if (!LINK.transfer(recipient, amount)) {
revert InsufficientBalance();
}
}

/*
* @notice Oracle withdraw native earned through fulfilling requests
* @notice withdraw native earned through fulfilling requests
* @param recipient where to send the funds
* @param amount amount to withdraw
*/
function oracleWithdrawNative(address payable recipient, uint96 amount) external nonReentrant {
if (s_withdrawableNative[msg.sender] < amount) {
function withdrawNative(address payable recipient) external nonReentrant onlyOwner {
if (s_withdrawableNative == 0) {
revert InsufficientBalance();
}
// Prevent re-entrancy by updating state before transfer.
s_withdrawableNative[msg.sender] -= amount;
uint96 amount = s_withdrawableNative;
s_withdrawableNative -= amount;
s_totalNativeBalance -= amount;
(bool sent, ) = recipient.call{value: amount}("");
if (!sent) {
Expand Down
33 changes: 15 additions & 18 deletions contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
address sender;
bytes extraArgs;
}
mapping(bytes32 => address) /* keyHash */ /* oracle */ public s_provingKeys;
mapping(bytes32 => bool) /* keyHash */ /* exists */ public s_provingKeys;
bytes32[] public s_provingKeyHashes;
mapping(uint256 => bytes32) /* requestID */ /* commitment */ public s_requestCommitments;
event ProvingKeyRegistered(bytes32 keyHash, address indexed oracle);
event ProvingKeyDeregistered(bytes32 keyHash, address indexed oracle);
event ProvingKeyRegistered(bytes32 keyHash);
event ProvingKeyDeregistered(bytes32 keyHash);
event RandomWordsRequested(
bytes32 indexed keyHash,
uint256 requestId,
Expand Down Expand Up @@ -94,28 +94,26 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
}

/**
* @notice Registers a proving key to an oracle.
* @param oracle address of the oracle
* @notice Registers a proving key to.
* @param publicProvingKey key that oracle can use to submit vrf fulfillments
*/
function registerProvingKey(address oracle, uint256[2] calldata publicProvingKey) external onlyOwner {
function registerProvingKey(uint256[2] calldata publicProvingKey) external onlyOwner {
bytes32 kh = hashOfKey(publicProvingKey);
if (s_provingKeys[kh] != address(0)) {
if (s_provingKeys[kh]) {
revert ProvingKeyAlreadyRegistered(kh);
}
s_provingKeys[kh] = oracle;
s_provingKeys[kh] = true;
s_provingKeyHashes.push(kh);
emit ProvingKeyRegistered(kh, oracle);
emit ProvingKeyRegistered(kh);
}

/**
* @notice Deregisters a proving key to an oracle.
* @notice Deregisters a proving key.
* @param publicProvingKey key that oracle can use to submit vrf fulfillments
*/
function deregisterProvingKey(uint256[2] calldata publicProvingKey) external onlyOwner {
bytes32 kh = hashOfKey(publicProvingKey);
address oracle = s_provingKeys[kh];
if (oracle == address(0)) {
if (!s_provingKeys[kh]) {
revert NoSuchProvingKey(kh);
}
delete s_provingKeys[kh];
Expand All @@ -127,7 +125,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
s_provingKeyHashes.pop();
}
}
emit ProvingKeyDeregistered(kh, oracle);
emit ProvingKeyDeregistered(kh);
}

/**
Expand Down Expand Up @@ -355,8 +353,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
) internal view returns (Output memory) {
bytes32 keyHash = hashOfKey(proof.pk);
// Only registered proving keys are permitted.
address oracle = s_provingKeys[keyHash];
if (oracle == address(0)) {
if (!s_provingKeys[keyHash]) {
revert NoSuchProvingKey(keyHash);
}
uint256 requestId = uint256(keccak256(abi.encode(keyHash, proof.seed)));
Expand Down Expand Up @@ -423,7 +420,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
bool nativePayment = uint8(rc.extraArgs[rc.extraArgs.length - 1]) == 1;
// We want to charge users exactly for how much gas they use in their callback.
// The gasAfterPaymentCalculation is meant to cover these additional operations where we
// decrement the subscription balance and increment the oracles withdrawable balance.
// decrement the subscription balance and increment the withdrawable balance.
uint96 payment = _calculatePaymentAmount(
startGas,
s_config.gasAfterPaymentCalculation,
Expand All @@ -435,13 +432,13 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
revert InsufficientBalance();
}
s_subscriptions[rc.subId].nativeBalance -= payment;
s_withdrawableNative[s_provingKeys[output.keyHash]] += payment;
s_withdrawableNative += payment;
} else {
if (s_subscriptions[rc.subId].balance < payment) {
revert InsufficientBalance();
}
s_subscriptions[rc.subId].balance -= payment;
s_withdrawableTokens[s_provingKeys[output.keyHash]] += payment;
s_withdrawableTokens += payment;
}

// Include payment in the event for tracking costs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ contract ExposedVRFCoordinatorV2_5 is VRFCoordinatorV2_5 {
s_totalNativeBalance = newBalance;
}

function setWithdrawableTokensTestingOnlyXXX(address oracle, uint96 newBalance) external {
s_withdrawableTokens[oracle] = newBalance;
function setWithdrawableTokensTestingOnlyXXX(uint96 newBalance) external {
s_withdrawableTokens = newBalance;
}

function getWithdrawableTokensTestingOnlyXXX(address oracle) external view returns (uint96) {
return s_withdrawableTokens[oracle];
function getWithdrawableTokensTestingOnlyXXX() external view returns (uint96) {
return s_withdrawableTokens;
}

function setWithdrawableNativeTestingOnlyXXX(address oracle, uint96 newBalance) external {
s_withdrawableNative[oracle] = newBalance;
function setWithdrawableNativeTestingOnlyXXX(uint96 newBalance) external {
s_withdrawableNative = newBalance;
}

function getWithdrawableNativeTestingOnlyXXX(address oracle) external view returns (uint96) {
return s_withdrawableNative[oracle];
function getWithdrawableNativeTestingOnlyXXX() external view returns (uint96) {
return s_withdrawableNative;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ contract VRFCoordinatorV2PlusUpgradedVersion is
bytes extraArgs;
}

mapping(bytes32 => address) /* keyHash */ /* oracle */ internal s_provingKeys;
mapping(bytes32 => bool) /* keyHash */ /* exists */ internal s_provingKeys;
bytes32[] public s_provingKeyHashes;
mapping(uint256 => bytes32) /* requestID */ /* commitment */ public s_requestCommitments;

event ProvingKeyRegistered(bytes32 keyHash, address indexed oracle);
event ProvingKeyRegistered(bytes32 keyHash);
event RandomWordsRequested(
bytes32 indexed keyHash,
uint256 requestId,
Expand Down Expand Up @@ -108,17 +108,16 @@ contract VRFCoordinatorV2PlusUpgradedVersion is

/**
* @notice Registers a proving key to an oracle.
* @param oracle address of the oracle
* @param publicProvingKey key that oracle can use to submit vrf fulfillments
*/
function registerProvingKey(address oracle, uint256[2] calldata publicProvingKey) external onlyOwner {
function registerProvingKey(uint256[2] calldata publicProvingKey) external onlyOwner {
bytes32 kh = hashOfKey(publicProvingKey);
if (s_provingKeys[kh] != address(0)) {
if (s_provingKeys[kh]) {
revert ProvingKeyAlreadyRegistered(kh);
}
s_provingKeys[kh] = oracle;
s_provingKeys[kh] = true;
s_provingKeyHashes.push(kh);
emit ProvingKeyRegistered(kh, oracle);
emit ProvingKeyRegistered(kh);
}

/**
Expand Down Expand Up @@ -346,8 +345,7 @@ contract VRFCoordinatorV2PlusUpgradedVersion is
) internal view returns (Output memory) {
bytes32 keyHash = hashOfKey(proof.pk);
// Only registered proving keys are permitted.
address oracle = s_provingKeys[keyHash];
if (oracle == address(0)) {
if (!s_provingKeys[keyHash]) {
revert NoSuchProvingKey(keyHash);
}
uint256 requestId = uint256(keccak256(abi.encode(keyHash, proof.seed)));
Expand Down Expand Up @@ -426,13 +424,13 @@ contract VRFCoordinatorV2PlusUpgradedVersion is
revert InsufficientBalance();
}
s_subscriptions[rc.subId].nativeBalance -= payment;
s_withdrawableNative[s_provingKeys[output.keyHash]] += payment;
s_withdrawableNative += payment;
} else {
if (s_subscriptions[rc.subId].balance < payment) {
revert InsufficientBalance();
}
s_subscriptions[rc.subId].balance -= payment;
s_withdrawableTokens[s_provingKeys[output.keyHash]] += payment;
s_withdrawableTokens += payment;
}

// Include payment in the event for tracking costs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ contract VRFCoordinatorV2Plus_Migration is BaseTest {

function registerProvingKey() public {
uint256[2] memory uncompressedKeyParts = this.getProvingKeyParts(UNCOMPRESSED_PUBLIC_KEY);
v1Coordinator.registerProvingKey(OWNER, uncompressedKeyParts);
v1Coordinator_noLink.registerProvingKey(OWNER, uncompressedKeyParts);
v1Coordinator.registerProvingKey(uncompressedKeyParts);
v1Coordinator_noLink.registerProvingKey(uncompressedKeyParts);
}

// note: Call this function via this.getProvingKeyParts to be able to pass memory as calldata and
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ contract VRFV2Plus is BaseTest {
// Should revert when already registered.
uint256[2] memory uncompressedKeyParts = this.getProvingKeyParts(vrfUncompressedPublicKey);
vm.expectRevert(abi.encodeWithSelector(VRFCoordinatorV2_5.ProvingKeyAlreadyRegistered.selector, vrfKeyHash));
s_testCoordinator.registerProvingKey(LINK_WHALE, uncompressedKeyParts);
s_testCoordinator.registerProvingKey(uncompressedKeyParts);
}

function registerProvingKey() public {
uint256[2] memory uncompressedKeyParts = this.getProvingKeyParts(vrfUncompressedPublicKey);
s_testCoordinator.registerProvingKey(LINK_WHALE, uncompressedKeyParts);
s_testCoordinator.registerProvingKey(uncompressedKeyParts);
}

// note: Call this function via this.getProvingKeyParts to be able to pass memory as calldata and
Expand Down
Loading

0 comments on commit 83b6ad1

Please sign in to comment.