From ed9dc15b98c2f0cbf105d0f1b5fd40cf7571998c Mon Sep 17 00:00:00 2001 From: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:39:34 +0000 Subject: [PATCH] fix: v2plus superscript (#11156) --- .../testnet/v2plusscripts/super_scripts.go | 91 +++++++++++-------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go index f805e7b74f0..752e06bbb25 100644 --- a/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go @@ -6,15 +6,16 @@ import ( "encoding/hex" "flag" "fmt" + "math/big" + "os" + "strings" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2plus_interface" - "math/big" - "os" - "strings" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -467,12 +468,12 @@ func DeployUniverseViaCLI(e helpers.Environment) { deployCmd := flag.NewFlagSet("deploy-universe", flag.ExitOnError) // required flags - linkAddress := *deployCmd.String("link-address", "", "address of link token") - linkEthAddress := *deployCmd.String("link-eth-feed", "", "address of link eth feed") - bhsContractAddressString := *deployCmd.String("bhs-address", "", "address of BHS contract") - batchBHSAddressString := *deployCmd.String("batch-bhs-address", "", "address of Batch BHS contract") - coordinatorAddressString := *deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") - batchCoordinatorAddressString := *deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") + linkAddress := deployCmd.String("link-address", "", "address of link token") + linkEthAddress := deployCmd.String("link-eth-feed", "", "address of link eth feed") + bhsContractAddressString := deployCmd.String("bhs-address", "", "address of BHS contract") + batchBHSAddressString := deployCmd.String("batch-bhs-address", "", "address of Batch BHS contract") + coordinatorAddressString := deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") + batchCoordinatorAddressString := deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") subscriptionBalanceJuelsString := deployCmd.String("subscription-balance", "1e19", "amount to fund subscription with Link token (Juels)") subscriptionBalanceNativeWeiString := deployCmd.String("subscription-balance-native", "1e18", "amount to fund subscription with native token (Wei)") @@ -513,14 +514,14 @@ func DeployUniverseViaCLI(e helpers.Environment) { SendingKeyFundingAmount: fundingAmount, } - bhsContractAddress := common.HexToAddress(bhsContractAddressString) - batchBHSAddress := common.HexToAddress(batchBHSAddressString) - coordinatorAddress := common.HexToAddress(coordinatorAddressString) - batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) + bhsContractAddress := common.HexToAddress(*bhsContractAddressString) + batchBHSAddress := common.HexToAddress(*batchBHSAddressString) + coordinatorAddress := common.HexToAddress(*coordinatorAddressString) + batchCoordinatorAddress := common.HexToAddress(*batchCoordinatorAddressString) contractAddresses := model.ContractAddresses{ - LinkAddress: linkAddress, - LinkEthAddress: linkEthAddress, + LinkAddress: *linkAddress, + LinkEthAddress: *linkEthAddress, BhsContractAddress: bhsContractAddress, BatchBHSAddress: batchBHSAddress, CoordinatorAddress: coordinatorAddress, @@ -563,28 +564,32 @@ func VRFV2PlusDeployUniverse(e helpers.Environment, batchFulfillmentEnabled bool, nodesMap map[string]model.Node, ) model.JobSpecs { - // Put key in ECDSA format - if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { - *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) - } + var compressedPkHex string + var keyHash common.Hash + if len(*registerKeyUncompressedPubKey) > 0 { + // Put key in ECDSA format + if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { + *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) + } - // Generate compressed public key and key hash - pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) - helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) - helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) - } - var newPK secp256k1.PublicKey - copy(newPK[:], pkBytes) + // Generate compressed public key and key hash + pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) + helpers.PanicErr(err) + pk, err := crypto.UnmarshalPubkey(pubBytes) + helpers.PanicErr(err) + var pkBytes []byte + if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { + pkBytes = append(pk.X.Bytes(), 1) + } else { + pkBytes = append(pk.X.Bytes(), 0) + } + var newPK secp256k1.PublicKey + copy(newPK[:], pkBytes) - compressedPkHex := hexutil.Encode(pkBytes) - keyHash, err := newPK.Hash() - helpers.PanicErr(err) + compressedPkHex = hexutil.Encode(pkBytes) + keyHash, err = newPK.Hash() + helpers.PanicErr(err) + } if len(contractAddresses.LinkAddress) == 0 { fmt.Println("\nDeploying LINK Token...") @@ -689,7 +694,13 @@ func VRFV2PlusDeployUniverse(e helpers.Environment, e.ChainID, //evmChainID strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, + func() string { + if keys := nodesMap[model.VRFPrimaryNodeName].SendingKeys; len(keys) > 0 { + return keys[0].Address + } else { + return common.HexToAddress("0x0").String() + } + }(), contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) @@ -704,7 +715,13 @@ func VRFV2PlusDeployUniverse(e helpers.Environment, e.ChainID, //evmChainID strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], + func() string { + if keys := nodesMap[model.VRFPrimaryNodeName].SendingKeys; len(keys) > 0 { + return keys[0].Address + } else { + return common.HexToAddress("0x0").String() + } + }(), contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, )