From 279fec72e7a7cdd0ed2d7dded14a3494df649cd5 Mon Sep 17 00:00:00 2001 From: jinhoonbang Date: Thu, 21 Dec 2023 14:32:11 -0800 Subject: [PATCH] address comments --- .../scripts/native_solc_compile_all_vrfv2plus | 60 ------------------- core/gethwrappers/go_generate_vrfv2plus.go | 23 ------- .../vrf/v2/integration_helpers_test.go | 26 ++++---- .../vrf/v2/integration_v2_plus_test.go | 1 + core/services/vrf/v2/integration_v2_test.go | 34 ++--------- integration-tests/smoke/vrfv2plus_test.go | 1 + 6 files changed, 23 insertions(+), 122 deletions(-) delete mode 100755 contracts/scripts/native_solc_compile_all_vrfv2plus delete mode 100644 core/gethwrappers/go_generate_vrfv2plus.go diff --git a/contracts/scripts/native_solc_compile_all_vrfv2plus b/contracts/scripts/native_solc_compile_all_vrfv2plus deleted file mode 100755 index b8cc5b42a29..00000000000 --- a/contracts/scripts/native_solc_compile_all_vrfv2plus +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo " ┌──────────────────────────────────────────────┐" -echo " │ Compiling VRF contracts... │" -echo " └──────────────────────────────────────────────┘" - -SOLC_VERSION="0.8.6" -OPTIMIZE_RUNS=1000000 - -SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" -ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; cd ../../ && pwd -P )" -python3 -m pip install --require-hashes -r "$SCRIPTPATH"/requirements.txt - -solc-select install $SOLC_VERSION -solc-select use $SOLC_VERSION -export SOLC_VERSION=$SOLC_VERSION - -compileContract () { - local contract - contract=$(basename "$1" ".sol") - - solc @openzeppelin/="$ROOT"/contracts/node_modules/@openzeppelin/ --overwrite --optimize --optimize-runs $OPTIMIZE_RUNS --metadata-hash none \ - -o "$ROOT"/contracts/solc/v$SOLC_VERSION/"$contract" \ - --abi --bin --allow-paths "$ROOT"/contracts/src/v0.8,"$ROOT"/contracts/node_modules\ - "$ROOT"/contracts/src/v0.8/"$1" -} - -compileContractAltOpts () { - local contract - contract=$(basename "$1" ".sol") - - solc @openzeppelin/="$ROOT"/contracts/node_modules/@openzeppelin/ --overwrite --optimize --optimize-runs "$2" --metadata-hash none \ - -o "$ROOT"/contracts/solc/v$SOLC_VERSION/"$contract" \ - --abi --bin --allow-paths "$ROOT"/contracts/src/v0.8,"$ROOT"/contracts/node_modules\ - "$ROOT"/contracts/src/v0.8/"$1" -} - -# VRF V2Plus -compileContract vrf/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol -compileContract vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol -compileContractAltOpts vrf/dev/VRFCoordinatorV2_5.sol 50 -compileContract vrf/dev/BatchVRFCoordinatorV2Plus.sol -compileContract vrf/dev/VRFV2PlusWrapper.sol -compileContract vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol -compileContract vrf/dev/testhelpers/VRFMaliciousConsumerV2Plus.sol -compileContract vrf/dev/testhelpers/VRFV2PlusExternalSubOwnerExample.sol -compileContract vrf/dev/testhelpers/VRFV2PlusSingleConsumerExample.sol -compileContract vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol -compileContract vrf/dev/testhelpers/VRFV2PlusRevertingExample.sol -compileContract vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol -compileContract vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol -compileContract vrf/dev/libraries/VRFV2PlusClient.sol -compileContract vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol -compileContract vrf/dev/BlockhashStore.sol -compileContract vrf/dev/TrustedBlockhashStore.sol -compileContract vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol -compileContractAltOpts vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5 -compileContract vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol \ No newline at end of file diff --git a/core/gethwrappers/go_generate_vrfv2plus.go b/core/gethwrappers/go_generate_vrfv2plus.go deleted file mode 100644 index 109243e9205..00000000000 --- a/core/gethwrappers/go_generate_vrfv2plus.go +++ /dev/null @@ -1,23 +0,0 @@ -package gethwrappers - -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/BlockhashStore/BlockhashStore.abi ../../contracts/solc/v0.8.6/BlockhashStore/BlockhashStore.bin BlockhashStore blockhash_store - -// VRF V2Plus -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/IVRFCoordinatorV2PlusInternal/IVRFCoordinatorV2PlusInternal.abi ../../contracts/solc/v0.8.6/IVRFCoordinatorV2PlusInternal/IVRFCoordinatorV2PlusInternal.bin IVRFCoordinatorV2PlusInternal vrf_coordinator_v2plus_interface -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/BatchVRFCoordinatorV2Plus/BatchVRFCoordinatorV2Plus.abi ../../contracts/solc/v0.8.6/BatchVRFCoordinatorV2Plus/BatchVRFCoordinatorV2Plus.bin BatchVRFCoordinatorV2Plus batch_vrf_coordinator_v2plus -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/TrustedBlockhashStore/TrustedBlockhashStore.abi ../../contracts/solc/v0.8.6/TrustedBlockhashStore/TrustedBlockhashStore.bin TrustedBlockhashStore trusted_blockhash_store -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusConsumerExample/VRFV2PlusConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusConsumerExample/VRFV2PlusConsumerExample.bin VRFV2PlusConsumerExample vrfv2plus_consumer_example -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2_5/VRFCoordinatorV2_5.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2_5/VRFCoordinatorV2_5.bin VRFCoordinatorV2_5 vrf_coordinator_v2_5 -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapper/VRFV2PlusWrapper.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapper/VRFV2PlusWrapper.bin VRFV2PlusWrapper vrfv2plus_wrapper -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample/VRFV2PlusWrapperConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperConsumerExample/VRFV2PlusWrapperConsumerExample.bin VRFV2PlusWrapperConsumerExample vrfv2plus_wrapper_consumer_example -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2Plus/VRFMaliciousConsumerV2Plus.abi ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2Plus/VRFMaliciousConsumerV2Plus.bin VRFMaliciousConsumerV2Plus vrf_malicious_consumer_v2_plus -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusSingleConsumerExample/VRFV2PlusSingleConsumerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusSingleConsumerExample/VRFV2PlusSingleConsumerExample.bin VRFV2PlusSingleConsumerExample vrf_v2plus_single_consumer -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusExternalSubOwnerExample/VRFV2PlusExternalSubOwnerExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusExternalSubOwnerExample/VRFV2PlusExternalSubOwnerExample.bin VRFV2PlusExternalSubOwnerExample vrf_v2plus_sub_owner -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample/VRFV2PlusRevertingExample.abi ../../contracts/solc/v0.8.6/VRFV2PlusRevertingExample/VRFV2PlusRevertingExample.bin VRFV2PlusRevertingExample vrfv2plus_reverting_example -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFConsumerV2PlusUpgradeableExample/VRFConsumerV2PlusUpgradeableExample.abi ../../contracts/solc/v0.8.6/VRFConsumerV2PlusUpgradeableExample/VRFConsumerV2PlusUpgradeableExample.bin VRFConsumerV2PlusUpgradeableExample vrf_consumer_v2_plus_upgradeable_example -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusClient/VRFV2PlusClient.abi ../../contracts/solc/v0.8.6/VRFV2PlusClient/VRFV2PlusClient.bin VRFV2PlusClient vrfv2plus_client -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2Plus_V2Example/VRFCoordinatorV2Plus_V2Example.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2Plus_V2Example/VRFCoordinatorV2Plus_V2Example.bin VRFCoordinatorV2Plus_V2Example vrf_coordinator_v2_plus_v2_example -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator/VRFV2PlusMaliciousMigrator.abi ../../contracts/solc/v0.8.6/VRFV2PlusMaliciousMigrator/VRFV2PlusMaliciousMigrator.bin VRFV2PlusMaliciousMigrator vrfv2plus_malicious_migrator -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics/VRFV2PlusLoadTestWithMetrics.abi ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics/VRFV2PlusLoadTestWithMetrics.bin VRFV2PlusLoadTestWithMetrics vrf_v2plus_load_test_with_metrics -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion/VRFCoordinatorV2PlusUpgradedVersion.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion/VRFCoordinatorV2PlusUpgradedVersion.bin VRFCoordinatorV2PlusUpgradedVersion vrf_v2plus_upgraded_version -//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer/VRFV2PlusWrapperLoadTestConsumer.bin VRFV2PlusWrapperLoadTestConsumer vrfv2plus_wrapper_load_test_consumer diff --git a/core/services/vrf/v2/integration_helpers_test.go b/core/services/vrf/v2/integration_helpers_test.go index e50c331789f..5b490f27cdd 100644 --- a/core/services/vrf/v2/integration_helpers_test.go +++ b/core/services/vrf/v2/integration_helpers_test.go @@ -30,6 +30,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" + "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/vrfkey" "github.com/smartcontractkit/chainlink/v2/core/services/signatures/secp256k1" v22 "github.com/smartcontractkit/chainlink/v2/core/services/vrf/v2" "github.com/smartcontractkit/chainlink/v2/core/services/vrf/vrfcommon" @@ -1681,16 +1682,7 @@ func testMaliciousConsumer( time.Sleep(1 * time.Second) // Register a proving key associated with the VRF job. - p, err := vrfkey.PublicKey.Point() - require.NoError(t, err) - if vrfVersion == vrfcommon.V2Plus { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, nil, pair(secp256k1.Coordinates(p))) - } else { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, &uni.nallory.From, pair(secp256k1.Coordinates(p))) - } - require.NoError(t, err) + registerProvingKey(t, uni, vrfkey) subFunding := decimal.RequireFromString("1000000000000000000") _, err = uni.maliciousConsumerContract.CreateSubscriptionAndFund(carol, @@ -1744,3 +1736,17 @@ func testMaliciousConsumer( } require.Equal(t, 1, len(requests)) } + +func registerProvingKey(t *testing.T, uni coordinatorV2UniverseCommon, vrfkey vrfkey.KeyV2) { + p, err := vrfkey.PublicKey.Point() + require.NoError(t, err) + if uni.rootContract.Version() == vrfcommon.V2Plus { + _, err = uni.rootContract.RegisterProvingKey( + uni.neil, nil, pair(secp256k1.Coordinates(p))) + } else { + _, err = uni.rootContract.RegisterProvingKey( + uni.neil, &uni.nallory.From, pair(secp256k1.Coordinates(p))) + } + require.NoError(t, err) + uni.backend.Commit() +} diff --git a/core/services/vrf/v2/integration_v2_plus_test.go b/core/services/vrf/v2/integration_v2_plus_test.go index 174034692f5..97943be7170 100644 --- a/core/services/vrf/v2/integration_v2_plus_test.go +++ b/core/services/vrf/v2/integration_v2_plus_test.go @@ -850,6 +850,7 @@ func TestVRFV2PlusIntegration_RequestCost(t *testing.T) { vrfkey, err := app.GetKeyStore().VRF().Create() require.NoError(t, err) + registerProvingKey(t, uni.coordinatorV2UniverseCommon, vrfkey) p, err := vrfkey.PublicKey.Point() require.NoError(t, err) _, err = uni.rootContract.RegisterProvingKey( diff --git a/core/services/vrf/v2/integration_v2_test.go b/core/services/vrf/v2/integration_v2_test.go index 6509a4b7142..9fd7887f3d9 100644 --- a/core/services/vrf/v2/integration_v2_test.go +++ b/core/services/vrf/v2/integration_v2_test.go @@ -1808,18 +1808,7 @@ func TestRequestCost(t *testing.T) { vrfkey, err := app.GetKeyStore().VRF().Create() require.NoError(t, err) - p, err := vrfkey.PublicKey.Point() - require.NoError(t, err) - if uni.rootContract.Version() == vrfcommon.V2Plus { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, nil, pair(secp256k1.Coordinates(p))) - } else { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, &uni.nallory.From, pair(secp256k1.Coordinates(p))) - } - require.NoError(t, err) - uni.backend.Commit() - + registerProvingKey(t, uni.coordinatorV2UniverseCommon, vrfkey) t.Run("non-proxied consumer", func(tt *testing.T) { carol := uni.vrfConsumers[0] carolContract := uni.consumerContracts[0] @@ -1922,23 +1911,10 @@ func TestFulfillmentCost(t *testing.T) { app := cltest.NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain(t, cfg, uni.backend, key) require.NoError(t, app.Start(testutils.Context(t))) - var vrfkey vrfkey.KeyV2 - { - var err error - vrfkey, err = app.GetKeyStore().VRF().Create() - require.NoError(t, err) - p, err := vrfkey.PublicKey.Point() - require.NoError(t, err) - if uni.rootContract.Version() == vrfcommon.V2Plus { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, nil, pair(secp256k1.Coordinates(p))) - } else { - _, err = uni.rootContract.RegisterProvingKey( - uni.neil, &uni.nallory.From, pair(secp256k1.Coordinates(p))) - } - require.NoError(t, err) - uni.backend.Commit() - } + vrfkey, err := app.GetKeyStore().VRF().Create() + require.NoError(t, err) + registerProvingKey(t, uni.coordinatorV2UniverseCommon, vrfkey) + var ( nonProxiedConsumerGasEstimate uint64 proxiedConsumerGasEstimate uint64 diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 917e0cd618d..5f5569b4030 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -522,6 +522,7 @@ func TestVRFv2Plus(t *testing.T) { "Active subscription ids should not contain sub id after sub cancellation", ) }) + t.Run("Owner Withdraw", func(t *testing.T) { testConfig := vrfv2PlusConfig subIDsForWithdraw, err := vrfv2plus.CreateFundSubsAndAddConsumers(