Skip to content

Commit

Permalink
fix: v2plus superscript (#11156)
Browse files Browse the repository at this point in the history
  • Loading branch information
kidambisrinivas authored Nov 3, 2023
1 parent 5cc88a8 commit ed9dc15
Showing 1 changed file with 54 additions and 37 deletions.
91 changes: 54 additions & 37 deletions core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)")

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down

0 comments on commit ed9dc15

Please sign in to comment.