From d3b4d9a95c938ffea325e58c8da259a7efced4ed Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 20 Feb 2023 14:18:59 -0500 Subject: [PATCH] Update avalanchego to v1.9.9-rc.3 (#1191) * Update avalanchego to v1.9.9-rc.2 * bump avalanchego version --- go.mod | 2 +- go.sum | 4 +- plugin/evm/client.go | 10 +-- plugin/evm/export_tx.go | 13 ++-- plugin/evm/export_tx_test.go | 80 ++++++++++----------- plugin/evm/formatting.go | 12 ++-- plugin/evm/import_tx.go | 6 +- plugin/evm/import_tx_test.go | 42 +++++------ plugin/evm/mempool_atomic_gossiping_test.go | 4 +- plugin/evm/service.go | 8 +-- plugin/evm/syncervm_test.go | 6 +- plugin/evm/tx.go | 10 +-- plugin/evm/user.go | 22 ++---- plugin/evm/vm.go | 30 ++++---- plugin/evm/vm_test.go | 73 ++++++++++--------- scripts/versions.sh | 2 +- 16 files changed, 157 insertions(+), 167 deletions(-) diff --git a/go.mod b/go.mod index bd5b80ee6e..72a3a00447 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.9.8 + github.com/ava-labs/avalanchego v1.9.9-rc.3 github.com/cespare/cp v0.1.0 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 diff --git a/go.sum b/go.sum index 62f66da3b3..d683ca33c1 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= -github.com/ava-labs/avalanchego v1.9.8 h1:5SHKqkWpBn9Pqxg2qpzDZ7FQqYFapzaCZwArapBdqAA= -github.com/ava-labs/avalanchego v1.9.8/go.mod h1:t9+R55TgRJxYCekRf/EicIjHBeeEQT04TQxpaF98+yM= +github.com/ava-labs/avalanchego v1.9.9-rc.3 h1:PKxLivTARExhTd9chSLV9jvRmxpoTDw45iojH8m3Mfs= +github.com/ava-labs/avalanchego v1.9.9-rc.3/go.mod h1:Xw2i8k6FjAaMyETEpn8zCTHtOeA6IFw/R14ThCt1SxU= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= diff --git a/plugin/evm/client.go b/plugin/evm/client.go index 6f313cf271..4e0163a208 100644 --- a/plugin/evm/client.go +++ b/plugin/evm/client.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/api" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/rpc" @@ -28,8 +28,8 @@ type Client interface { GetAtomicTx(ctx context.Context, txID ids.ID) ([]byte, error) GetAtomicUTXOs(ctx context.Context, addrs []string, sourceChain string, limit uint32, startAddress, startUTXOID string) ([][]byte, api.Index, error) ListAddresses(ctx context.Context, userPass api.UserPass) ([]string, error) - ExportKey(ctx context.Context, userPass api.UserPass, addr string) (*crypto.PrivateKeySECP256K1R, string, error) - ImportKey(ctx context.Context, userPass api.UserPass, privateKey *crypto.PrivateKeySECP256K1R) (string, error) + ExportKey(ctx context.Context, userPass api.UserPass, addr string) (*secp256k1.PrivateKey, string, error) + ImportKey(ctx context.Context, userPass api.UserPass, privateKey *secp256k1.PrivateKey) (string, error) Import(ctx context.Context, userPass api.UserPass, to string, sourceChain string) (ids.ID, error) ExportAVAX(ctx context.Context, userPass api.UserPass, amount uint64, to string) (ids.ID, error) Export(ctx context.Context, userPass api.UserPass, amount uint64, to string, assetID string) (ids.ID, error) @@ -135,7 +135,7 @@ func (c *client) ListAddresses(ctx context.Context, user api.UserPass) ([]string // ExportKey returns the private key corresponding to [addr] controlled by [user] // in both Avalanche standard format and hex format -func (c *client) ExportKey(ctx context.Context, user api.UserPass, addr string) (*crypto.PrivateKeySECP256K1R, string, error) { +func (c *client) ExportKey(ctx context.Context, user api.UserPass, addr string) (*secp256k1.PrivateKey, string, error) { res := &ExportKeyReply{} err := c.requester.SendRequest(ctx, "avax.exportKey", &ExportKeyArgs{ UserPass: user, @@ -145,7 +145,7 @@ func (c *client) ExportKey(ctx context.Context, user api.UserPass, addr string) } // ImportKey imports [privateKey] to [user] -func (c *client) ImportKey(ctx context.Context, user api.UserPass, privateKey *crypto.PrivateKeySECP256K1R) (string, error) { +func (c *client) ImportKey(ctx context.Context, user api.UserPass, privateKey *secp256k1.PrivateKey) (string, error) { res := &api.JSONAddress{} err := c.requester.SendRequest(ctx, "avax.importKey", &ImportKeyArgs{ UserPass: user, diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index a780bd4466..52b39babcb 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/wrappers" @@ -229,15 +229,10 @@ func (utx *UnsignedExportTx) SemanticVerify( if len(cred.Sigs) != 1 { return fmt.Errorf("expected one signature for EVM Input Credential, but found: %d", len(cred.Sigs)) } - pubKeyIntf, err := vm.secpFactory.RecoverPublicKey(utx.Bytes(), cred.Sigs[0][:]) + pubKey, err := vm.secpFactory.RecoverPublicKey(utx.Bytes(), cred.Sigs[0][:]) if err != nil { return err } - pubKey, ok := pubKeyIntf.(*crypto.PublicKeySECP256K1R) - if !ok { - // This should never happen - return fmt.Errorf("expected *crypto.PublicKeySECP256K1R but got %T", pubKeyIntf) - } if input.Address != PublicKeyToEthAddress(pubKey) { return errPublicKeySignatureMismatch } @@ -287,7 +282,7 @@ func (vm *VM) newExportTx( chainID ids.ID, // Chain to send the UTXOs to to ids.ShortID, // Address of chain recipient baseFee *big.Int, // fee to use post-AP3 - keys []*crypto.PrivateKeySECP256K1R, // Pay the fee and provide the tokens + keys []*secp256k1.PrivateKey, // Pay the fee and provide the tokens ) (*Tx, error) { outs := []*avax.TransferableOutput{{ Asset: avax.Asset{ID: assetID}, @@ -304,7 +299,7 @@ func (vm *VM) newExportTx( var ( avaxNeeded uint64 = 0 ins, avaxIns []EVMInput - signers, avaxSigners [][]*crypto.PrivateKeySECP256K1R + signers, avaxSigners [][]*secp256k1.PrivateKey err error ) diff --git a/plugin/evm/export_tx_test.go b/plugin/evm/export_tx_test.go index 9e95566a66..50b782e17d 100644 --- a/plugin/evm/export_tx_test.go +++ b/plugin/evm/export_tx_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/ids" engCommon "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -54,7 +54,7 @@ func createExportTxOptions(t *testing.T, vm *VM, issuer chan engCommon.Message, } // Import the funds - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -85,7 +85,7 @@ func createExportTxOptions(t *testing.T, vm *VM, issuer chan engCommon.Message, // Use the funds to create 3 conflicting export transactions sending the funds to each of the test addresses exportTxs := make([]*Tx, 0, 3) for _, addr := range testShortIDAddrs { - exportTx, err := vm.newExportTx(vm.ctx.AVAXAssetID, uint64(5000000), vm.ctx.XChainID, addr, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + exportTx, err := vm.newExportTx(vm.ctx.AVAXAssetID, uint64(5000000), vm.ctx.XChainID, addr, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -366,7 +366,7 @@ func TestExportTxEVMStateTransfer(t *testing.T) { t.Fatal(err) } - tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -523,7 +523,7 @@ func TestExportTxSemanticVerify(t *testing.T) { tests := []struct { name string tx *Tx - signers [][]*crypto.PrivateKeySECP256K1R + signers [][]*secp256k1.PrivateKey baseFee *big.Int rules params.Rules shouldErr bool @@ -531,7 +531,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "valid", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -547,7 +547,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = constants.PlatformChainID return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, }, baseFee: initialBaseFee, @@ -561,7 +561,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = constants.PlatformChainID return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, }, baseFee: initialBaseFee, @@ -575,7 +575,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = ids.GenerateTestID() return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, }, baseFee: initialBaseFee, @@ -589,7 +589,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = constants.PlatformChainID return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -605,7 +605,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = constants.PlatformChainID return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -621,7 +621,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.DestinationChain = ids.GenerateTestID() return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -637,7 +637,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.ExportedOutputs = nil return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -653,7 +653,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.NetworkID++ return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -669,7 +669,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.BlockchainID = ids.GenerateTestID() return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -686,7 +686,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.Ins[2].Amount = 0 return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -711,7 +711,7 @@ func TestExportTxSemanticVerify(t *testing.T) { }} return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -752,7 +752,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.ExportedOutputs = exportOutputs return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -769,7 +769,7 @@ func TestExportTxSemanticVerify(t *testing.T) { validExportTx.Ins[2] = validExportTx.Ins[1] return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -796,7 +796,7 @@ func TestExportTxSemanticVerify(t *testing.T) { } return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -823,7 +823,7 @@ func TestExportTxSemanticVerify(t *testing.T) { } return &Tx{UnsignedAtomicTx: &validExportTx} }(), - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -835,7 +835,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "too many signatures", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -848,7 +848,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "too few signatures", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key}, {key}, }, @@ -859,7 +859,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "too many signatures on credential", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {key, testKeys[1]}, {key}, {key}, @@ -871,7 +871,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "too few signatures on credential", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {}, {key}, {key}, @@ -883,7 +883,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "wrong signature on credential", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{ + signers: [][]*secp256k1.PrivateKey{ {testKeys[1]}, {key}, {key}, @@ -895,7 +895,7 @@ func TestExportTxSemanticVerify(t *testing.T) { { name: "no signatures", tx: &Tx{UnsignedAtomicTx: validExportTx}, - signers: [][]*crypto.PrivateKeySECP256K1R{}, + signers: [][]*secp256k1.PrivateKey{}, baseFee: initialBaseFee, rules: apricotRulesPhase3, shouldErr: true, @@ -986,7 +986,7 @@ func TestExportTxAccept(t *testing.T) { tx := &Tx{UnsignedAtomicTx: exportTx} - signers := [][]*crypto.PrivateKeySECP256K1R{ + signers := [][]*secp256k1.PrivateKey{ {key}, {key}, {key}, @@ -1120,7 +1120,7 @@ func TestExportTxVerify(t *testing.T) { avax.SortTransferableOutputs(exportTx.ExportedOutputs, Codec) // Pass in a list of signers here with the appropriate length // to avoid causing a nil-pointer error in the helper method - emptySigners := make([][]*crypto.PrivateKeySECP256K1R, 2) + emptySigners := make([][]*secp256k1.PrivateKey, 2) SortEVMInputsAndSigners(exportTx.Ins, emptySigners) ctx := NewContext() @@ -1374,7 +1374,7 @@ func TestExportTxGasCost(t *testing.T) { tests := map[string]struct { UnsignedExportTx *UnsignedExportTx - Keys [][]*crypto.PrivateKeySECP256K1R + Keys [][]*secp256k1.PrivateKey BaseFee *big.Int ExpectedGasUsed uint64 @@ -1408,7 +1408,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 1230, ExpectedFee: 1, BaseFee: big.NewInt(1), @@ -1440,7 +1440,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 11230, ExpectedFee: 1, BaseFee: big.NewInt(1), @@ -1473,7 +1473,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 1230, ExpectedFee: 30750, BaseFee: big.NewInt(25 * params.GWei), @@ -1505,7 +1505,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 1230, ExpectedFee: 276750, BaseFee: big.NewInt(225 * params.GWei), @@ -1549,7 +1549,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0], testKeys[0], testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0], testKeys[0], testKeys[0]}}, ExpectedGasUsed: 3366, ExpectedFee: 84150, BaseFee: big.NewInt(25 * params.GWei), @@ -1593,7 +1593,7 @@ func TestExportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0], testKeys[0], testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0], testKeys[0], testKeys[0]}}, ExpectedGasUsed: 3366, ExpectedFee: 757350, BaseFee: big.NewInt(225 * params.GWei), @@ -1721,7 +1721,7 @@ func TestNewExportTx(t *testing.T) { t.Fatal(err) } - tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1752,7 +1752,7 @@ func TestNewExportTx(t *testing.T) { parent = vm.LastAcceptedBlockInternal().(*Block) exportAmount := uint64(5000000) - tx, err = vm.newExportTx(vm.ctx.AVAXAssetID, exportAmount, vm.ctx.XChainID, testShortIDAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err = vm.newExportTx(vm.ctx.AVAXAssetID, exportAmount, vm.ctx.XChainID, testShortIDAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1911,7 +1911,7 @@ func TestNewExportTxMulticoin(t *testing.T) { t.Fatal(err) } - tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1948,7 +1948,7 @@ func TestNewExportTxMulticoin(t *testing.T) { t.Fatal(err) } - tx, err = vm.newExportTx(tid, exportAmount, vm.ctx.XChainID, exportId, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err = vm.newExportTx(tid, exportAmount, vm.ctx.XChainID, exportId, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } diff --git a/plugin/evm/formatting.go b/plugin/evm/formatting.go index 505d987561..a586a4558e 100644 --- a/plugin/evm/formatting.go +++ b/plugin/evm/formatting.go @@ -8,10 +8,10 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ethereum/go-ethereum/common" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" ) // ParseLocalAddress takes in an address for this chain and produces the ID @@ -52,11 +52,11 @@ func ParseEthAddress(addrStr string) (common.Address, error) { } // GetEthAddress returns the ethereum address derived from [privKey] -func GetEthAddress(privKey *crypto.PrivateKeySECP256K1R) common.Address { - return PublicKeyToEthAddress(privKey.PublicKey().(*crypto.PublicKeySECP256K1R)) +func GetEthAddress(privKey *secp256k1.PrivateKey) common.Address { + return PublicKeyToEthAddress(privKey.PublicKey()) } // PublicKeyToEthAddress returns the ethereum address derived from [pubKey] -func PublicKeyToEthAddress(pubKey *crypto.PublicKeySECP256K1R) common.Address { - return ethcrypto.PubkeyToAddress(*(pubKey.ToECDSA())) +func PublicKeyToEthAddress(pubKey *secp256k1.PublicKey) common.Address { + return crypto.PubkeyToAddress(*(pubKey.ToECDSA())) } diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index 1511fa266a..93686875dc 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -278,7 +278,7 @@ func (vm *VM) newImportTx( chainID ids.ID, // chain to import from to common.Address, // Address of recipient baseFee *big.Int, // fee to use post-AP3 - keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds + keys []*secp256k1.PrivateKey, // Keys to import the funds ) (*Tx, error) { kc := secp256k1fx.NewKeychain() for _, key := range keys { @@ -302,7 +302,7 @@ func (vm *VM) newImportTxWithUTXOs( atomicUTXOs []*avax.UTXO, // UTXOs to spend ) (*Tx, error) { importedInputs := []*avax.TransferableInput{} - signers := [][]*crypto.PrivateKeySECP256K1R{} + signers := [][]*secp256k1.PrivateKey{} importedAmount := make(map[ids.ID]uint64) now := vm.clock.Unix() diff --git a/plugin/evm/import_tx_test.go b/plugin/evm/import_tx_test.go index 981f1e69e6..d292ef953e 100644 --- a/plugin/evm/import_tx_test.go +++ b/plugin/evm/import_tx_test.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -53,7 +53,7 @@ func createImportTxOptions(t *testing.T, vm *VM, sharedMemory *atomic.Memory) [] importTxs := make([]*Tx, 0, 3) for _, ethAddr := range testEthAddrs { - importTx, err := vm.newImportTx(vm.ctx.XChainID, ethAddr, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, ethAddr, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -432,7 +432,7 @@ func TestNewImportTx(t *testing.T) { t.Fatal(err) } - tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + tx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -542,7 +542,7 @@ func TestImportTxGasCost(t *testing.T) { tests := map[string]struct { UnsignedImportTx *UnsignedImportTx - Keys [][]*crypto.PrivateKeySECP256K1R + Keys [][]*secp256k1.PrivateKey ExpectedGasUsed uint64 ExpectedFee uint64 @@ -568,7 +568,7 @@ func TestImportTxGasCost(t *testing.T) { AssetID: avaxAssetID, }}, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 1230, ExpectedFee: 30750, BaseFee: big.NewInt(25 * params.GWei), @@ -592,7 +592,7 @@ func TestImportTxGasCost(t *testing.T) { AssetID: avaxAssetID, }}, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 1230, ExpectedFee: 1, BaseFee: big.NewInt(1), @@ -616,7 +616,7 @@ func TestImportTxGasCost(t *testing.T) { AssetID: avaxAssetID, }}, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}}, ExpectedGasUsed: 11230, ExpectedFee: 1, BaseFee: big.NewInt(1), @@ -653,7 +653,7 @@ func TestImportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}, {testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}, {testKeys[0]}}, ExpectedGasUsed: 2318, ExpectedFee: 57950, BaseFee: big.NewInt(25 * params.GWei), @@ -694,7 +694,7 @@ func TestImportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}, {testKeys[0]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0]}, {testKeys[0]}}, ExpectedGasUsed: 2378, ExpectedFee: 59450, BaseFee: big.NewInt(25 * params.GWei), @@ -718,7 +718,7 @@ func TestImportTxGasCost(t *testing.T) { AssetID: avaxAssetID, }}, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{{testKeys[0], testKeys[1]}}, + Keys: [][]*secp256k1.PrivateKey{{testKeys[0], testKeys[1]}}, ExpectedGasUsed: 2234, ExpectedFee: 55850, BaseFee: big.NewInt(25 * params.GWei), @@ -818,7 +818,7 @@ func TestImportTxGasCost(t *testing.T) { }, }, }, - Keys: [][]*crypto.PrivateKeySECP256K1R{ + Keys: [][]*secp256k1.PrivateKey{ {testKeys[0]}, {testKeys[0]}, {testKeys[0]}, @@ -888,7 +888,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -917,7 +917,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -957,7 +957,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -991,7 +991,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -1024,7 +1024,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -1058,7 +1058,7 @@ func TestImportTxSemanticVerify(t *testing.T) { AssetID: assetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -1125,7 +1125,7 @@ func TestImportTxSemanticVerify(t *testing.T) { }}, }} // Sign the transaction with the incorrect key - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[1]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[1]}}); err != nil { t.Fatal(err) } return tx @@ -1165,7 +1165,7 @@ func TestImportTxSemanticVerify(t *testing.T) { }, }, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -1211,7 +1211,7 @@ func TestImportTxEVMStateTransfer(t *testing.T) { AssetID: vm.ctx.AVAXAssetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx @@ -1256,7 +1256,7 @@ func TestImportTxEVMStateTransfer(t *testing.T) { AssetID: assetID, }}, }} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } return tx diff --git a/plugin/evm/mempool_atomic_gossiping_test.go b/plugin/evm/mempool_atomic_gossiping_test.go index f2d5d6493c..84a9dd10f5 100644 --- a/plugin/evm/mempool_atomic_gossiping_test.go +++ b/plugin/evm/mempool_atomic_gossiping_test.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/chain" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -172,7 +172,7 @@ func createImportTx(t *testing.T, vm *VM, txID ids.ID, feeAmount uint64) *Tx { tx := &Tx{UnsignedAtomicTx: importTx} // Sign with the correct key - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{testKeys[0]}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{testKeys[0]}}); err != nil { t.Fatal(err) } diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 19e7985983..5d5af42301 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -12,7 +12,7 @@ import ( "github.com/ava-labs/avalanchego/api" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/set" @@ -100,8 +100,8 @@ type ExportKeyArgs struct { // ExportKeyReply is the response for ExportKey type ExportKeyReply struct { // The decrypted PrivateKey for the Address provided in the arguments - PrivateKey *crypto.PrivateKeySECP256K1R `json:"privateKey"` - PrivateKeyHex string `json:"privateKeyHex"` + PrivateKey *secp256k1.PrivateKey `json:"privateKey"` + PrivateKeyHex string `json:"privateKeyHex"` } // ExportKey returns a private key from the provided user @@ -134,7 +134,7 @@ func (service *AvaxAPI) ExportKey(r *http.Request, args *ExportKeyArgs, reply *E // ImportKeyArgs are arguments for ImportKey type ImportKeyArgs struct { api.UserPass - PrivateKey *crypto.PrivateKeySECP256K1R `json:"privateKey"` + PrivateKey *secp256k1.PrivateKey `json:"privateKey"` } // ImportKey adds a private key to the provided user diff --git a/plugin/evm/syncervm_test.go b/plugin/evm/syncervm_test.go index 9af5b8c69e..156e59e2ef 100644 --- a/plugin/evm/syncervm_test.go +++ b/plugin/evm/syncervm_test.go @@ -22,7 +22,7 @@ import ( "github.com/ava-labs/avalanchego/snow/choices" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" @@ -280,7 +280,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest) *syncVMSetup { switch i { case 0: // spend the UTXOs from shared memory - importTx, err = serverVM.newImportTx(serverVM.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err = serverVM.newImportTx(serverVM.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -295,7 +295,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest) *syncVMSetup { serverVM.ctx.XChainID, testShortIDAddrs[0], initialBaseFee, - []*crypto.PrivateKeySECP256K1R{testKeys[0]}, + []*secp256k1.PrivateKey{testKeys[0]}, ) if err != nil { t.Fatal(err) diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go index 9067ac740f..fc7cce7449 100644 --- a/plugin/evm/tx.go +++ b/plugin/evm/tx.go @@ -20,7 +20,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/wrappers" @@ -127,7 +127,7 @@ type Tx struct { } // Sign this transaction with the provided signers -func (tx *Tx) Sign(c codec.Manager, signers [][]*crypto.PrivateKeySECP256K1R) error { +func (tx *Tx) Sign(c codec.Manager, signers [][]*secp256k1.PrivateKey) error { unsignedBytes, err := c.Marshal(codecVersion, &tx.UnsignedAtomicTx) if err != nil { return fmt.Errorf("couldn't marshal UnsignedAtomicTx: %w", err) @@ -137,7 +137,7 @@ func (tx *Tx) Sign(c codec.Manager, signers [][]*crypto.PrivateKeySECP256K1R) er hash := hashing.ComputeHash256(unsignedBytes) for _, keys := range signers { cred := &secp256k1fx.Credential{ - Sigs: make([][crypto.SECP256K1RSigLen]byte, len(keys)), + Sigs: make([][secp256k1.SignatureLen]byte, len(keys)), } for i, key := range keys { sig, err := key.SignHash(hash) // Sign hash @@ -194,7 +194,7 @@ func (tx *Tx) BlockFeeContribution(fixedFee bool, avaxAssetID ids.ID, baseFee *b // innerSortInputsAndSigners implements sort.Interface for EVMInput type innerSortInputsAndSigners struct { inputs []EVMInput - signers [][]*crypto.PrivateKeySECP256K1R + signers [][]*secp256k1.PrivateKey } func (ins *innerSortInputsAndSigners) Less(i, j int) bool { @@ -213,7 +213,7 @@ func (ins *innerSortInputsAndSigners) Swap(i, j int) { } // SortEVMInputsAndSigners sorts the list of EVMInputs based on the addresses and assetIDs -func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*crypto.PrivateKeySECP256K1R) { +func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*secp256k1.PrivateKey) { sort.Sort(&innerSortInputsAndSigners{inputs: inputs, signers: signers}) } diff --git a/plugin/evm/user.go b/plugin/evm/user.go index e1902598e0..51a3fa382c 100644 --- a/plugin/evm/user.go +++ b/plugin/evm/user.go @@ -5,11 +5,10 @@ package evm import ( "errors" - "fmt" "github.com/ava-labs/avalanchego/database/encdb" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ethereum/go-ethereum/common" ) @@ -23,7 +22,7 @@ var ( ) type user struct { - secpFactory *crypto.FactorySECP256K1R + secpFactory *secp256k1.Factory // This user's database, acquired from the keystore db *encdb.Database } @@ -66,7 +65,7 @@ func (u *user) controlsAddress(address common.Address) (bool, error) { } // putAddress persists that this user controls address controlled by [privKey] -func (u *user) putAddress(privKey *crypto.PrivateKeySECP256K1R) error { +func (u *user) putAddress(privKey *secp256k1.PrivateKey) error { if privKey == nil { return errKeyNil } @@ -106,7 +105,7 @@ func (u *user) putAddress(privKey *crypto.PrivateKeySECP256K1R) error { } // Key returns the private key that controls the given address -func (u *user) getKey(address common.Address) (*crypto.PrivateKeySECP256K1R, error) { +func (u *user) getKey(address common.Address) (*secp256k1.PrivateKey, error) { if u.db == nil { return nil, errDBNil //} else if address.IsZero() { @@ -117,23 +116,16 @@ func (u *user) getKey(address common.Address) (*crypto.PrivateKeySECP256K1R, err if err != nil { return nil, err } - sk, err := u.secpFactory.ToPrivateKey(bytes) - if err != nil { - return nil, err - } - if sk, ok := sk.(*crypto.PrivateKeySECP256K1R); ok { - return sk, nil - } - return nil, fmt.Errorf("expected private key to be type *crypto.PrivateKeySECP256K1R but is type %T", sk) + return u.secpFactory.ToPrivateKey(bytes) } // Return all private keys controlled by this user -func (u *user) getKeys() ([]*crypto.PrivateKeySECP256K1R, error) { +func (u *user) getKeys() ([]*secp256k1.PrivateKey, error) { addrs, err := u.getAddresses() if err != nil { return nil, err } - keys := make([]*crypto.PrivateKeySECP256K1R, len(addrs)) + keys := make([]*secp256k1.PrivateKey, len(addrs)) for i, addr := range addrs { key, err := u.getKey(addr) if err != nil { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index f749112f82..a5399260cb 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -71,7 +71,7 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math" @@ -267,7 +267,7 @@ type VM struct { shutdownWg sync.WaitGroup fx secp256k1fx.Fx - secpFactory crypto.FactorySECP256K1R + secpFactory secp256k1.Factory // Continuous Profiler profiler profiler.ContinuousProfiler @@ -482,7 +482,11 @@ func (vm *VM) Initialize( vm.chainConfig = g.Config vm.networkID = vm.ethConfig.NetworkId - vm.secpFactory = crypto.FactorySECP256K1R{Cache: cache.LRU[ids.ID, *crypto.PublicKeySECP256K1R]{Size: secpFactoryCacheSize}} + vm.secpFactory = secp256k1.Factory{ + Cache: cache.LRU[ids.ID, *secp256k1.PublicKey]{ + Size: secpFactoryCacheSize, + }, + } vm.codec = Codec @@ -1484,21 +1488,21 @@ func (vm *VM) GetAtomicUTXOs( // GetSpendableFunds returns a list of EVMInputs and keys (in corresponding // order) to total [amount] of [assetID] owned by [keys]. -// Note: we return [][]*crypto.PrivateKeySECP256K1R even though each input +// Note: we return [][]*secp256k1.PrivateKey even though each input // corresponds to a single key, so that the signers can be passed in to // [tx.Sign] which supports multiple keys on a single input. func (vm *VM) GetSpendableFunds( - keys []*crypto.PrivateKeySECP256K1R, + keys []*secp256k1.PrivateKey, assetID ids.ID, amount uint64, -) ([]EVMInput, [][]*crypto.PrivateKeySECP256K1R, error) { +) ([]EVMInput, [][]*secp256k1.PrivateKey, error) { // Note: current state uses the state of the preferred block. state, err := vm.blockChain.State() if err != nil { return nil, nil, err } inputs := []EVMInput{} - signers := [][]*crypto.PrivateKeySECP256K1R{} + signers := [][]*secp256k1.PrivateKey{} // Note: we assume that each key in [keys] is unique, so that iterating over // the keys will not produce duplicated nonces in the returned EVMInput slice. for _, key := range keys { @@ -1530,7 +1534,7 @@ func (vm *VM) GetSpendableFunds( AssetID: assetID, Nonce: nonce, }) - signers = append(signers, []*crypto.PrivateKeySECP256K1R{key}) + signers = append(signers, []*secp256k1.PrivateKey{key}) amount -= balance } @@ -1546,15 +1550,15 @@ func (vm *VM) GetSpendableFunds( // This function accounts for the added cost of the additional inputs needed to // create the transaction and makes sure to skip any keys with a balance that is // insufficient to cover the additional fee. -// Note: we return [][]*crypto.PrivateKeySECP256K1R even though each input +// Note: we return [][]*secp256k1.PrivateKey even though each input // corresponds to a single key, so that the signers can be passed in to // [tx.Sign] which supports multiple keys on a single input. func (vm *VM) GetSpendableAVAXWithFee( - keys []*crypto.PrivateKeySECP256K1R, + keys []*secp256k1.PrivateKey, amount uint64, cost uint64, baseFee *big.Int, -) ([]EVMInput, [][]*crypto.PrivateKeySECP256K1R, error) { +) ([]EVMInput, [][]*secp256k1.PrivateKey, error) { // Note: current state uses the state of the preferred block. state, err := vm.blockChain.State() if err != nil { @@ -1573,7 +1577,7 @@ func (vm *VM) GetSpendableAVAXWithFee( amount = newAmount inputs := []EVMInput{} - signers := [][]*crypto.PrivateKeySECP256K1R{} + signers := [][]*secp256k1.PrivateKey{} // Note: we assume that each key in [keys] is unique, so that iterating over // the keys will not produce duplicated nonces in the returned EVMInput slice. for _, key := range keys { @@ -1630,7 +1634,7 @@ func (vm *VM) GetSpendableAVAXWithFee( AssetID: vm.ctx.AVAXAssetID, Nonce: nonce, }) - signers = append(signers, []*crypto.PrivateKeySECP256K1R{key}) + signers = append(signers, []*secp256k1.PrivateKey{key}) amount -= inputAmount } diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 7c593d88b1..ee940fef3f 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -19,7 +19,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -41,7 +41,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/cb58" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/logging" @@ -70,7 +70,7 @@ var ( testCChainID = ids.ID{'c', 'c', 'h', 'a', 'i', 'n', 't', 'e', 's', 't'} testXChainID = ids.ID{'t', 'e', 's', 't', 'x'} nonExistentID = ids.ID{'F'} - testKeys []*crypto.PrivateKeySECP256K1R + testKeys []*secp256k1.PrivateKey testEthAddrs []common.Address // testEthAddrs[i] corresponds to testKeys[i] testShortIDAddrs []ids.ShortID testAvaxAssetID = ids.ID{1, 2, 3} @@ -106,7 +106,7 @@ var ( func init() { var b []byte - factory := crypto.FactorySECP256K1R{} + factory := secp256k1.Factory{} for _, key := range []string{ "24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5", @@ -115,9 +115,8 @@ func init() { } { b, _ = cb58.Decode(key) pk, _ := factory.ToPrivateKey(b) - secpKey := pk.(*crypto.PrivateKeySECP256K1R) - testKeys = append(testKeys, secpKey) - testEthAddrs = append(testEthAddrs, GetEthAddress(secpKey)) + testKeys = append(testKeys, pk) + testEthAddrs = append(testEthAddrs, GetEthAddress(pk)) testShortIDAddrs = append(testShortIDAddrs, pk.PublicKey().Address()) } } @@ -384,7 +383,7 @@ func TestCrossChainMessagestoVM(t *testing.T) { newTxPoolHeadChan := make(chan core.NewTxPoolReorgEvent, 1) vm.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan) - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) require.NoError(err) err = vm.issueTx(importTx, true /*=local*/) @@ -432,8 +431,8 @@ func TestCrossChainMessagestoVM(t *testing.T) { for _, err := range errs { require.NoError(err) } - testAddr := ethcrypto.PubkeyToAddress(testKeys[0].ToECDSA().PublicKey) - contractAddress := ethcrypto.CreateAddress(testAddr, 0) + testAddr := crypto.PubkeyToAddress(testKeys[0].ToECDSA().PublicKey) + contractAddress := crypto.CreateAddress(testAddr, 0) <-issuer @@ -672,7 +671,7 @@ func TestIssueAtomicTxs(t *testing.T) { } }() - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -714,7 +713,7 @@ func TestIssueAtomicTxs(t *testing.T) { t.Fatalf("Expected last accepted blockID to be the accepted block: %s, but found %s", blk.ID(), lastAcceptedID) } - exportTx, err := vm.newExportTx(vm.ctx.AVAXAssetID, importAmount-(2*params.AvalancheAtomicTxFee), vm.ctx.XChainID, testShortIDAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + exportTx, err := vm.newExportTx(vm.ctx.AVAXAssetID, importAmount-(2*params.AvalancheAtomicTxFee), vm.ctx.XChainID, testShortIDAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -781,7 +780,7 @@ func TestBuildEthTxBlock(t *testing.T) { newTxPoolHeadChan := make(chan core.NewTxPoolReorgEvent, 1) vm.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan) - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -942,14 +941,14 @@ func testConflictingImportTxs(t *testing.T, genesis string) { importTxs := make([]*Tx, 0, 3) conflictTxs := make([]*Tx, 0, 3) for i, key := range testKeys { - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[i], initialBaseFee, []*crypto.PrivateKeySECP256K1R{key}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[i], initialBaseFee, []*secp256k1.PrivateKey{key}) if err != nil { t.Fatal(err) } importTxs = append(importTxs, importTx) conflictAddr := testEthAddrs[(i+1)%len(testEthAddrs)] - conflictTx, err := vm.newImportTx(vm.ctx.XChainID, conflictAddr, initialBaseFee, []*crypto.PrivateKeySECP256K1R{key}) + conflictTx, err := vm.newImportTx(vm.ctx.XChainID, conflictAddr, initialBaseFee, []*secp256k1.PrivateKey{key}) if err != nil { t.Fatal(err) } @@ -1278,7 +1277,7 @@ func TestSetPreferenceRace(t *testing.T) { newTxPoolHeadChan2 := make(chan core.NewTxPoolReorgEvent, 1) vm2.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan2) - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, testEthAddrs[1], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, testEthAddrs[1], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1522,12 +1521,12 @@ func TestConflictingTransitiveAncestryWithGap(t *testing.T) { newTxPoolHeadChan := make(chan core.NewTxPoolReorgEvent, 1) vm.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan) - importTx0A, err := vm.newImportTx(vm.ctx.XChainID, key.Address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{key0}) + importTx0A, err := vm.newImportTx(vm.ctx.XChainID, key.Address, initialBaseFee, []*secp256k1.PrivateKey{key0}) if err != nil { t.Fatal(err) } // Create a conflicting transaction - importTx0B, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[2], initialBaseFee, []*crypto.PrivateKeySECP256K1R{key0}) + importTx0B, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[2], initialBaseFee, []*secp256k1.PrivateKey{key0}) if err != nil { t.Fatal(err) } @@ -1585,7 +1584,7 @@ func TestConflictingTransitiveAncestryWithGap(t *testing.T) { t.Fatal(err) } - importTx1, err := vm.newImportTx(vm.ctx.XChainID, key.Address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{key1}) + importTx1, err := vm.newImportTx(vm.ctx.XChainID, key.Address, initialBaseFee, []*secp256k1.PrivateKey{key1}) if err != nil { t.Fatalf("Failed to issue importTx1 due to: %s", err) } @@ -1664,7 +1663,7 @@ func TestBonusBlocksTxs(t *testing.T) { t.Fatal(err) } - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1756,7 +1755,7 @@ func TestReorgProtection(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -1937,7 +1936,7 @@ func TestNonCanonicalAccept(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2111,7 +2110,7 @@ func TestStickyPreference(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2383,7 +2382,7 @@ func TestUncleBlock(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2566,7 +2565,7 @@ func TestEmptyBlock(t *testing.T) { } }() - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2646,7 +2645,7 @@ func TestAcceptReorg(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2841,7 +2840,7 @@ func TestFutureBlock(t *testing.T) { } }() - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -2906,7 +2905,7 @@ func TestBuildApricotPhase1Block(t *testing.T) { key := testKeys[0].ToECDSA() address := testEthAddrs[0] - importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -3022,7 +3021,7 @@ func TestLastAcceptedBlockNumberAllow(t *testing.T) { } }() - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -3100,7 +3099,7 @@ func TestReissueAtomicTx(t *testing.T) { t.Fatal(err) } - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -3278,7 +3277,7 @@ func TestBuildInvalidBlockHead(t *testing.T) { SourceChain: vm.ctx.XChainID, } tx := &Tx{UnsignedAtomicTx: utx} - if err := tx.Sign(vm.codec, [][]*crypto.PrivateKeySECP256K1R{{key0}}); err != nil { + if err := tx.Sign(vm.codec, [][]*secp256k1.PrivateKey{{key0}}); err != nil { t.Fatal(err) } @@ -3429,7 +3428,7 @@ func TestBuildApricotPhase4Block(t *testing.T) { t.Fatal(err) } - importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -3611,7 +3610,7 @@ func TestBuildApricotPhase5Block(t *testing.T) { t.Fatal(err) } - importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, address, initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -3818,7 +3817,7 @@ func TestAtomicTxBuildBlockDropsConflicts(t *testing.T) { // Create a conflict set for each pair of transactions conflictSets := make([]set.Set[ids.ID], len(testKeys)) for index, key := range testKeys { - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[index], initialBaseFee, []*crypto.PrivateKeySECP256K1R{key}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[index], initialBaseFee, []*secp256k1.PrivateKey{key}) if err != nil { t.Fatal(err) } @@ -3826,7 +3825,7 @@ func TestAtomicTxBuildBlockDropsConflicts(t *testing.T) { t.Fatal(err) } conflictSets[index].Add(importTx.ID()) - conflictTx, err := vm.newImportTx(vm.ctx.XChainID, conflictKey.Address, initialBaseFee, []*crypto.PrivateKeySECP256K1R{key}) + conflictTx, err := vm.newImportTx(vm.ctx.XChainID, conflictKey.Address, initialBaseFee, []*secp256k1.PrivateKey{key}) if err != nil { t.Fatal(err) } @@ -3946,7 +3945,7 @@ func TestExtraStateChangeAtomicGasLimitExceeded(t *testing.T) { // Double the initial base fee used when estimating the cost of this transaction to ensure that when it is // used in ApricotPhase5 it still pays a sufficient fee with the fixed fee per atomic transaction. - importTx, err := vm1.newImportTx(vm1.ctx.XChainID, testEthAddrs[0], new(big.Int).Mul(common.Big2, initialBaseFee), []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm1.newImportTx(vm1.ctx.XChainID, testEthAddrs[0], new(big.Int).Mul(common.Big2, initialBaseFee), []*secp256k1.PrivateKey{testKeys[0]}) if err != nil { t.Fatal(err) } @@ -4012,7 +4011,7 @@ func TestSkipChainConfigCheckCompatible(t *testing.T) { // Since rewinding is permitted for last accepted height of 0, we must // accept one block to test the SkipUpgradeCheck functionality. - importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*crypto.PrivateKeySECP256K1R{testKeys[0]}) + importTx, err := vm.newImportTx(vm.ctx.XChainID, testEthAddrs[0], initialBaseFee, []*secp256k1.PrivateKey{testKeys[0]}) require.NoError(t, err) require.NoError(t, vm.issueTx(importTx, true /*=local*/)) <-issuer diff --git a/scripts/versions.sh b/scripts/versions.sh index 7473a71702..8e048b4d2f 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -3,4 +3,4 @@ # Set up the versions to be used coreth_version=${CORETH_VERSION:-'v0.11.7'} # Don't export them as they're used in the context of other calls -avalanche_version=${AVALANCHE_VERSION:-'v1.9.8'} +avalanche_version=${AVALANCHE_VERSION:-'v1.9.9-rc.3'}