Skip to content

Commit

Permalink
offchain changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Dec 13, 2023
1 parent 11ff2f5 commit e456aac
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
2 changes: 0 additions & 2 deletions core/scripts/vrfv2plus/testnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ func main() {
coordinatorReregisterKey := flag.NewFlagSet("coordinator-register-key", flag.ExitOnError)
coordinatorAddress := coordinatorReregisterKey.String("coordinator-address", "", "coordinator address")
uncompressedPubKey := coordinatorReregisterKey.String("pubkey", "", "uncompressed pubkey")
newOracleAddress := coordinatorReregisterKey.String("new-oracle-address", "", "oracle address")
skipDeregister := coordinatorReregisterKey.Bool("skip-deregister", false, "if true, key will not be deregistered")
helpers.ParseArgs(coordinatorReregisterKey, os.Args[2:], "coordinator-address", "pubkey", "new-oracle-address")

Expand All @@ -1097,7 +1096,6 @@ func main() {
// Use a higher gas price for the register call
e.Owner.GasPrice.Mul(e.Owner.GasPrice, big.NewInt(2))
registerTx, err := coordinator.RegisterProvingKey(e.Owner,
common.HexToAddress(*newOracleAddress),
[2]*big.Int{pk.X, pk.Y})
helpers.PanicErr(err)
fmt.Println("Register transaction", helpers.ExplorerLink(e.ChainID, registerTx.Hash()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func SmokeTestVRF(e helpers.Environment) {
x, y := secp256k1.Coordinates(point)
fmt.Println("proving key points x:", x, ", y:", y)
fmt.Println("proving key points from unmarshal:", pk.X, pk.Y)
tx, err := coordinator.RegisterProvingKey(e.Owner, e.Owner.From, [2]*big.Int{x, y})
tx, err := coordinator.RegisterProvingKey(e.Owner, [2]*big.Int{x, y})
helpers.PanicErr(err)
registerReceipt := helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "register proving key on", coordinatorAddress.String())
var provingKeyRegisteredLog *vrf_coordinator_v2_5.VRFCoordinatorV25ProvingKeyRegistered
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/vrfv2plus/testnet/v2plusscripts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"encoding/hex"
"fmt"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics"
"math/big"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -181,7 +182,6 @@ func RegisterCoordinatorProvingKey(e helpers.Environment,
pk, err := crypto.UnmarshalPubkey(pubBytes)
helpers.PanicErr(err)
tx, err := coordinator.RegisterProvingKey(e.Owner,
common.HexToAddress(oracleAddress),
[2]*big.Int{pk.X, pk.Y})
helpers.PanicErr(err)
helpers.ConfirmTXMined(
Expand Down
24 changes: 18 additions & 6 deletions core/services/vrf/v2/coordinator_v2x_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ type CoordinatorV2_X interface {
GetConfig(opts *bind.CallOpts) (Config, error)
ParseLog(log types.Log) (generated.AbigenLog, error)
OracleWithdraw(opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*types.Transaction, error)
Withdraw(opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*types.Transaction, error)
LogsWithTopics(keyHash common.Hash) map[common.Hash][][]log.Topic
Version() vrfcommon.Version
RegisterProvingKey(opts *bind.TransactOpts, oracle common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error)
RegisterProvingKey(opts *bind.TransactOpts, oracle *common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error)
FilterSubscriptionCreated(opts *bind.FilterOpts, subID []*big.Int) (SubscriptionCreatedIterator, error)
FilterRandomWordsRequested(opts *bind.FilterOpts, keyHash [][32]byte, subID []*big.Int, sender []common.Address) (RandomWordsRequestedIterator, error)
FilterRandomWordsFulfilled(opts *bind.FilterOpts, requestID []*big.Int, subID []*big.Int) (RandomWordsFulfilledIterator, error)
Expand Down Expand Up @@ -130,6 +131,10 @@ func (c *coordinatorV2) OracleWithdraw(opts *bind.TransactOpts, recipient common
return c.coordinator.OracleWithdraw(opts, recipient, amount)
}

func (c *coordinatorV2) Withdraw(opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*types.Transaction, error) {
return nil, errors.New("withdraw not implemented for v2")
}

func (c *coordinatorV2) LogsWithTopics(keyHash common.Hash) map[common.Hash][][]log.Topic {
return map[common.Hash][][]log.Topic{
vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested{}.Topic(): {
Expand All @@ -144,8 +149,8 @@ func (c *coordinatorV2) Version() vrfcommon.Version {
return c.vrfVersion
}

func (c *coordinatorV2) RegisterProvingKey(opts *bind.TransactOpts, oracle common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error) {
return c.coordinator.RegisterProvingKey(opts, oracle, publicProvingKey)
func (c *coordinatorV2) RegisterProvingKey(opts *bind.TransactOpts, oracle *common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error) {
return c.coordinator.RegisterProvingKey(opts, *oracle, publicProvingKey)
}

func (c *coordinatorV2) FilterSubscriptionCreated(opts *bind.FilterOpts, subID []*big.Int) (SubscriptionCreatedIterator, error) {
Expand Down Expand Up @@ -281,7 +286,11 @@ func (c *coordinatorV2_5) ParseLog(log types.Log) (generated.AbigenLog, error) {
}

func (c *coordinatorV2_5) OracleWithdraw(opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*types.Transaction, error) {
return c.coordinator.OracleWithdraw(opts, recipient, amount)
return nil, errors.New("oracle withdraw not implemented for v2.5")
}

func (c *coordinatorV2_5) Withdraw(opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*types.Transaction, error) {
return c.coordinator.Withdraw(opts, recipient, amount)
}

func (c *coordinatorV2_5) LogsWithTopics(keyHash common.Hash) map[common.Hash][][]log.Topic {
Expand All @@ -298,8 +307,11 @@ func (c *coordinatorV2_5) Version() vrfcommon.Version {
return c.vrfVersion
}

func (c *coordinatorV2_5) RegisterProvingKey(opts *bind.TransactOpts, oracle common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error) {
return c.coordinator.RegisterProvingKey(opts, oracle, publicProvingKey)
func (c *coordinatorV2_5) RegisterProvingKey(opts *bind.TransactOpts, oracle *common.Address, publicProvingKey [2]*big.Int) (*types.Transaction, error) {
if oracle != nil {
return nil, errors.New("oracle address not supported for registering proving key in v2.5")
}
return c.coordinator.RegisterProvingKey(opts, publicProvingKey)
}

func (c *coordinatorV2_5) FilterSubscriptionCreated(opts *bind.FilterOpts, subID []*big.Int) (SubscriptionCreatedIterator, error) {
Expand Down
9 changes: 7 additions & 2 deletions core/services/vrf/v2/integration_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1683,8 +1683,13 @@ func testMaliciousConsumer(
// Register a proving key associated with the VRF job.
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = uni.rootContract.RegisterProvingKey(
uni.neil, uni.nallory.From, pair(secp256k1.Coordinates(p)))
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)

subFunding := decimal.RequireFromString("1000000000000000000")
Expand Down
4 changes: 2 additions & 2 deletions core/services/vrf/v2/integration_v2_plus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func TestVRFV2PlusIntegration_RequestCost(t *testing.T) {
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = uni.rootContract.RegisterProvingKey(
uni.neil, uni.neil.From, pair(secp256k1.Coordinates(p)))
uni.neil, nil, pair(secp256k1.Coordinates(p)))
require.NoError(t, err)
uni.backend.Commit()
t.Run("non-proxied consumer", func(tt *testing.T) {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func TestVRFV2PlusIntegration_FulfillmentCost(t *testing.T) {
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = uni.rootContract.RegisterProvingKey(
uni.neil, uni.neil.From, pair(secp256k1.Coordinates(p)))
uni.neil, nil, pair(secp256k1.Coordinates(p)))
require.NoError(t, err)
uni.backend.Commit()

Expand Down
27 changes: 21 additions & 6 deletions core/services/vrf/v2/integration_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,8 +1482,13 @@ func registerProvingKeyHelper(t *testing.T, uni coordinatorV2UniverseCommon, coo
// Register a proving key associated with the VRF job.
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = coordinator.RegisterProvingKey(
uni.neil, uni.nallory.From, pair(secp256k1.Coordinates(p)))
if uni.rootContract.Version() == vrfcommon.V2Plus {
_, err = coordinator.RegisterProvingKey(
uni.neil, nil, pair(secp256k1.Coordinates(p)))
} else {
_, err = coordinator.RegisterProvingKey(
uni.neil, &uni.nallory.From, pair(secp256k1.Coordinates(p)))
}
require.NoError(t, err)
uni.backend.Commit()
}
Expand Down Expand Up @@ -1805,8 +1810,13 @@ func TestRequestCost(t *testing.T) {
require.NoError(t, err)
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = uni.rootContract.RegisterProvingKey(
uni.neil, uni.neil.From, pair(secp256k1.Coordinates(p)))
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()

Expand Down Expand Up @@ -1919,8 +1929,13 @@ func TestFulfillmentCost(t *testing.T) {
require.NoError(t, err)
p, err := vrfkey.PublicKey.Point()
require.NoError(t, err)
_, err = uni.rootContract.RegisterProvingKey(
uni.neil, uni.neil.From, pair(secp256k1.Coordinates(p)))
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()
}
Expand Down

0 comments on commit e456aac

Please sign in to comment.