Skip to content

Commit

Permalink
chore/VRF-722-externalise-oracleWithdraw-address (#11216)
Browse files Browse the repository at this point in the history
* VRF-722: made eoa address configurable which is used for VRF Key registration in VRF super scripts

* VRF-722: PR comments
  • Loading branch information
iljapavlovs authored Nov 8, 2023
1 parent c3e889f commit 7be2d65
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 63 deletions.
5 changes: 5 additions & 0 deletions core/scripts/common/vrf/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ type ContractAddresses struct {
CoordinatorAddress common.Address
BatchCoordinatorAddress common.Address
}

type VRFKeyRegistrationConfig struct {
VRFKeyUncompressedPubKey string
RegisterAgainstAddress string
}
4 changes: 3 additions & 1 deletion core/scripts/common/vrf/setup-envs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ go run . \
--min-confs=3 \
--num-eth-keys=1 \
--num-vrf-keys=1 \
--sending-key-funding-amount="1e17"
--sending-key-funding-amount="1e17" \
--register-vrf-key-against-address=<vrf key will be registered against this address
in order to call oracleWithdraw from this address>
```

Optional parameters - will not be deployed if specified (NOT WORKING YET)
Expand Down
27 changes: 17 additions & 10 deletions core/scripts/common/vrf/setup-envs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func main() {
batchBHSAddressString := flag.String("batch-bhs-address", "", "address of Batch BHS contract")
coordinatorAddressString := flag.String("coordinator-address", "", "address of VRF Coordinator contract")
batchCoordinatorAddressString := flag.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract")
registerVRFKeyAgainstAddress := flag.String("register-vrf-key-against-address", "", "VRF Key registration against address - "+
"from this address you can perform `coordinator.oracleWithdraw` to withdraw earned funds from rand request fulfilments")

e := helpers.SetupEnv(false)
flag.Parse()
Expand Down Expand Up @@ -171,6 +173,11 @@ func main() {
BatchCoordinatorAddress: common.HexToAddress(*batchCoordinatorAddressString),
}

vrfKeyRegistrationConfig := model.VRFKeyRegistrationConfig{
VRFKeyUncompressedPubKey: nodesMap[model.VRFPrimaryNodeName].VrfKeys[0],
RegisterAgainstAddress: *registerVRFKeyAgainstAddress,
}

var jobSpecs model.JobSpecs

switch *vrfVersion {
Expand All @@ -188,18 +195,18 @@ func main() {
}

coordinatorConfigV2 := v2scripts.CoordinatorConfigV2{
MinConfs: minConfs,
MaxGasLimit: &constants.MaxGasLimit,
StalenessSeconds: &constants.StalenessSeconds,
GasAfterPayment: &constants.GasAfterPayment,
MinConfs: *minConfs,
MaxGasLimit: constants.MaxGasLimit,
StalenessSeconds: constants.StalenessSeconds,
GasAfterPayment: constants.GasAfterPayment,
FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink,
FeeConfig: feeConfigV2,
}

jobSpecs = v2scripts.VRFV2DeployUniverse(
e,
subscriptionBalanceJuels,
&nodesMap[model.VRFPrimaryNodeName].VrfKeys[0],
vrfKeyRegistrationConfig,
contractAddresses,
coordinatorConfigV2,
*batchFulfillmentEnabled,
Expand All @@ -211,10 +218,10 @@ func main() {
FulfillmentFlatFeeNativePPM: uint32(constants.FlatFeeNativePPM),
}
coordinatorConfigV2Plus := v2plusscripts.CoordinatorConfigV2Plus{
MinConfs: minConfs,
MaxGasLimit: &constants.MaxGasLimit,
StalenessSeconds: &constants.StalenessSeconds,
GasAfterPayment: &constants.GasAfterPayment,
MinConfs: *minConfs,
MaxGasLimit: constants.MaxGasLimit,
StalenessSeconds: constants.StalenessSeconds,
GasAfterPayment: constants.GasAfterPayment,
FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink,
FeeConfig: feeConfigV2Plus,
}
Expand All @@ -223,7 +230,7 @@ func main() {
e,
subscriptionBalanceJuels,
subscriptionBalanceNativeWei,
&nodesMap[model.VRFPrimaryNodeName].VrfKeys[0],
vrfKeyRegistrationConfig,
contractAddresses,
coordinatorConfigV2Plus,
*batchFulfillmentEnabled,
Expand Down
16 changes: 12 additions & 4 deletions core/scripts/vrfv2/testnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ To deploy a full VRF environment on-chain, run:

```shell
go run . deploy-universe \
--sending-key-funding-amount 100000000000000000 \
--subscription-balance=10000000000000000000 \
--subscription-balance=5000000000000000000 \ #5 LINK
--uncompressed-pub-key=<VRF Uncompressed Public Key> \
--vrf-primary-node-sending-keys="<sending-key1-address,sending-key2-address>" \
--batch-fulfillment-enabled false
--vrf-primary-node-sending-keys="<sending-key1-address,sending-key2-address>" \ #used to fund the keys and for sample VRF Job Spec generation
--sending-key-funding-amount 100000000000000000 \ #0.1 ETH, fund addresses specified in vrf-primary-node-sending-keys
--batch-fulfillment-enabled false \ #only used for sample VRF Job Spec generation
--register-vrf-key-against-address=<"from this address you can perform `coordinator.oracleWithdraw` to withdraw earned funds from rand request fulfilments>
```
```shell
go run . deploy-universe \
--subscription-balance=5000000000000000000 \
--uncompressed-pub-key="0xf3706e247a7b205c8a8bd25a6e8c4650474da496151371085d45beeead27e568c1a5e8330c7fa718f8a31226efbff6632ed6f8ed470b637aa9be2b948e9dcef6" \
--batch-fulfillment-enabled false \
--register-vrf-key-against-address="0x23b5613fc04949F4A53d1cc8d6BCCD21ffc38C11"
```
## Deploying the Consumer Contract
Expand Down
54 changes: 31 additions & 23 deletions core/scripts/vrfv2/testnet/v2scripts/super_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
)

type CoordinatorConfigV2 struct {
MinConfs *int
MaxGasLimit *int64
StalenessSeconds *int64
GasAfterPayment *int64
MinConfs int
MaxGasLimit int64
StalenessSeconds int64
GasAfterPayment int64
FallbackWeiPerUnitLink *big.Int
FeeConfig vrf_coordinator_v2.VRFCoordinatorV2FeeConfig
}
Expand All @@ -52,7 +52,10 @@ func DeployUniverseViaCLI(e helpers.Environment) {

// optional flags
fallbackWeiPerUnitLinkString := deployCmd.String("fallback-wei-per-unit-link", constants.FallbackWeiPerUnitLink.String(), "fallback wei/link ratio")
registerKeyUncompressedPubKey := deployCmd.String("uncompressed-pub-key", "", "uncompressed public key")
registerVRFKeyUncompressedPubKey := deployCmd.String("uncompressed-pub-key", "", "uncompressed public key")
registerVRFKeyAgainstAddress := deployCmd.String("register-vrf-key-against-address", "", "VRF Key registration against address - "+
"from this address you can perform `coordinator.oracleWithdraw` to withdraw earned funds from rand request fulfilments")

vrfPrimaryNodeSendingKeysString := deployCmd.String("vrf-primary-node-sending-keys", "", "VRF Primary Node sending keys")

minConfs := deployCmd.Int("min-confs", constants.MinConfs, "min confs")
Expand Down Expand Up @@ -119,18 +122,23 @@ func DeployUniverseViaCLI(e helpers.Environment) {
}

coordinatorConfig := CoordinatorConfigV2{
MinConfs: minConfs,
MaxGasLimit: maxGasLimit,
StalenessSeconds: stalenessSeconds,
GasAfterPayment: gasAfterPayment,
MinConfs: *minConfs,
MaxGasLimit: *maxGasLimit,
StalenessSeconds: *stalenessSeconds,
GasAfterPayment: *gasAfterPayment,
FallbackWeiPerUnitLink: fallbackWeiPerUnitLink,
FeeConfig: feeConfig,
}

vrfKeyRegistrationConfig := model.VRFKeyRegistrationConfig{
VRFKeyUncompressedPubKey: *registerVRFKeyUncompressedPubKey,
RegisterAgainstAddress: *registerVRFKeyAgainstAddress,
}

VRFV2DeployUniverse(
e,
subscriptionBalanceJuels,
registerKeyUncompressedPubKey,
vrfKeyRegistrationConfig,
contractAddresses,
coordinatorConfig,
*batchFulfillmentEnabled,
Expand All @@ -147,22 +155,22 @@ func DeployUniverseViaCLI(e helpers.Environment) {
func VRFV2DeployUniverse(
e helpers.Environment,
subscriptionBalanceJuels *big.Int,
registerKeyUncompressedPubKey *string,
vrfKeyRegistrationConfig model.VRFKeyRegistrationConfig,
contractAddresses model.ContractAddresses,
coordinatorConfig CoordinatorConfigV2,
batchFulfillmentEnabled bool,
nodesMap map[string]model.Node,
) model.JobSpecs {
var compressedPkHex string
var keyHash common.Hash
if len(*registerKeyUncompressedPubKey) > 0 {
if len(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey) > 0 {
// Put key in ECDSA format
if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") {
*registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1)
if strings.HasPrefix(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey, "0x") {
vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey = strings.Replace(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey, "0x", "04", 1)
}

// Generate compressed public key and key hash
pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey)
pubBytes, err := hex.DecodeString(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey)
helpers.PanicErr(err)
pk, err := crypto.UnmarshalPubkey(pubBytes)
helpers.PanicErr(err)
Expand Down Expand Up @@ -217,23 +225,23 @@ func VRFV2DeployUniverse(
SetCoordinatorConfig(
e,
*coordinator,
uint16(*coordinatorConfig.MinConfs),
uint32(*coordinatorConfig.MaxGasLimit),
uint32(*coordinatorConfig.StalenessSeconds),
uint32(*coordinatorConfig.GasAfterPayment),
uint16(coordinatorConfig.MinConfs),
uint32(coordinatorConfig.MaxGasLimit),
uint32(coordinatorConfig.StalenessSeconds),
uint32(coordinatorConfig.GasAfterPayment),
coordinatorConfig.FallbackWeiPerUnitLink,
coordinatorConfig.FeeConfig,
)

fmt.Println("\nConfig set, getting current config from deployed contract...")
PrintCoordinatorConfig(coordinator)

if len(*registerKeyUncompressedPubKey) > 0 {
if len(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey) > 0 {
fmt.Println("\nRegistering proving key...")

//NOTE - register proving key against EOA account, and not against Oracle's sending address in other to be able
// easily withdraw funds from Coordinator contract back to EOA account
RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, e.Owner.From.String())
RegisterCoordinatorProvingKey(e, *coordinator, vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey, vrfKeyRegistrationConfig.RegisterAgainstAddress)

fmt.Println("\nProving key registered, getting proving key hashes from deployed contract...")
_, _, provingKeyHashes, configErr := coordinator.GetRequestConfig(nil)
Expand Down Expand Up @@ -271,7 +279,7 @@ func VRFV2DeployUniverse(
contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress
batchFulfillmentEnabled, //batchFulfillmentEnabled
compressedPkHex, //publicKey
*coordinatorConfig.MinConfs, //minIncomingConfirmations
coordinatorConfig.MinConfs, //minIncomingConfirmations
e.ChainID, //evmChainID
strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses
contractAddresses.CoordinatorAddress,
Expand Down Expand Up @@ -348,7 +356,7 @@ func VRFV2DeployUniverse(
"\nVRF Subscription Id:", subID,
"\nVRF Subscription Balance:", *subscriptionBalanceJuels,
"\nPossible VRF Request command: ",
fmt.Sprintf("go run . eoa-load-test-request-with-metrics --consumer-address=%s --sub-id=%d --key-hash=%s --request-confirmations %d --requests 1 --runs 1 --cb-gas-limit 1_000_000", consumerAddress, subID, keyHash, *coordinatorConfig.MinConfs),
fmt.Sprintf("go run . eoa-load-test-request-with-metrics --consumer-address=%s --sub-id=%d --key-hash=%s --request-confirmations %d --requests 1 --runs 1 --cb-gas-limit 1_000_000", consumerAddress, subID, keyHash, coordinatorConfig.MinConfs),
"\nRetrieve Request Status: ",
fmt.Sprintf("go run . eoa-load-test-read-metrics --consumer-address=%s", consumerAddress),
"\nA node can now be configured to run a VRF job with the below job spec :\n",
Expand Down
11 changes: 10 additions & 1 deletion core/scripts/vrfv2plus/testnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ cd <YOUR LOCAL CHAINLINK REPO>/core/scripts/vrfv2/testnet
- Not specifying `--link-eth-feed` would make the super script deploy a new LINK-ETH feed contract and use it for funding VRF V2+ subscription

```shell
go run . deploy-universe --link-address=$LINK --link-eth-feed=$LINK_ETH_FEED --subscription-balance=<SUBSCRIPTION AMOUNT> --uncompressed-pub-key=$PUB_KEY --oracle-address=$ORACLE_ADDRESS
go run . deploy-universe \
--link-address=$LINK \
--link-eth-feed=$LINK_ETH_FEED \
--subscription-balance=5000000000000000000 \ #5 LINK
--subscription-balance-native=1000000000000000000 \ #1 ETH
--uncompressed-pub-key=<VRF Uncompressed Public Key> \
--vrf-primary-node-sending-keys="<sending-key1-address,sending-key2-address>" \ #used to fund the keys and for sample VRF Job Spec generation
--sending-key-funding-amount 100000000000000000 \ #0.1 ETH, fund addresses specified in vrf-primary-node-sending-keys
--batch-fulfillment-enabled false \ #only used for sample VRF Job Spec generation
--register-vrf-key-against-address="<eoa address>" # from this address you can perform `coordinator.oracleWithdraw` to withdraw earned funds from rand request fulfilments
```

## Deploying the Consumer Contract
Expand Down
Loading

0 comments on commit 7be2d65

Please sign in to comment.