From 1dc64e265b127bc5183621dd720b868128ef679a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:36:04 -0500 Subject: [PATCH 01/11] ACP-103: Finalize complexity calculations --- utils/crypto/bls/bls_benchmark_test.go | 37 +++--- .../signer/proof_of_possession_test.go | 10 ++ vms/platformvm/txs/fee/calculator_test.go | 80 ++++++------- vms/platformvm/txs/fee/complexity.go | 106 ++++++++++++------ vms/platformvm/txs/fee/complexity_test.go | 30 ++--- 5 files changed, 159 insertions(+), 104 deletions(-) diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go index ca2c70182777..386965be22e9 100644 --- a/utils/crypto/bls/bls_benchmark_test.go +++ b/utils/crypto/bls/bls_benchmark_test.go @@ -12,20 +12,27 @@ import ( "github.com/ava-labs/avalanchego/utils" ) -var sizes = []int{ - 2, - 4, - 8, - 16, - 32, - 64, - 128, - 256, - 512, - 1024, - 2048, - 4096, -} +var ( + sizes = []int{ + 1, + 2, + 4, + 8, + 16, + 32, + 64, + 128, + 256, + 512, + 1024, + 2048, + 4096, + 8192, + 16384, + 32768, + } + biggestSize = sizes[len(sizes)-1] +) func BenchmarkSign(b *testing.B) { privateKey, err := NewSecretKey() @@ -63,7 +70,7 @@ func BenchmarkVerify(b *testing.B) { } func BenchmarkAggregatePublicKeys(b *testing.B) { - keys := make([]*PublicKey, 4096) + keys := make([]*PublicKey, biggestSize) for i := range keys { privateKey, err := NewSecretKey() require.NoError(b, err) diff --git a/vms/platformvm/signer/proof_of_possession_test.go b/vms/platformvm/signer/proof_of_possession_test.go index 9674d63985fc..746e92484459 100644 --- a/vms/platformvm/signer/proof_of_possession_test.go +++ b/vms/platformvm/signer/proof_of_possession_test.go @@ -49,6 +49,16 @@ func TestNewProofOfPossessionDeterministic(t *testing.T) { require.Equal(blsPOP0, blsPOP1) } +func BenchmarkProofOfPossessionVerify(b *testing.B) { + pop, err := newProofOfPossession() + require.NoError(b, err) + + b.ResetTimer() + for range b.N { + _ = pop.Verify() + } +} + func newProofOfPossession() (*ProofOfPossession, error) { sk, err := bls.NewSecretKey() if err != nil { diff --git a/vms/platformvm/txs/fee/calculator_test.go b/vms/platformvm/txs/fee/calculator_test.go index c128c278c856..a44b08ecbcfd 100644 --- a/vms/platformvm/txs/fee/calculator_test.go +++ b/vms/platformvm/txs/fee/calculator_test.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/gas" ) -const testDynamicPrice = 100 +const testDynamicPrice = gas.Price(100 * units.NanoAvax) var ( testStaticConfig = StaticConfig{ @@ -23,9 +23,9 @@ var ( } testDynamicWeights = gas.Dimensions{ gas.Bandwidth: 1, - gas.DBRead: 200, - gas.DBWrite: 300, - gas.Compute: 0, // TODO: Populate + gas.DBRead: 2000, + gas.DBWrite: 20000, + gas.Compute: 10, } // TODO: Rather than hardcoding transactions, consider implementing and @@ -76,9 +76,9 @@ var ( gas.Bandwidth: 691, // The length of the tx in bytes gas.DBRead: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicBLSVerifyCompute + intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 229_100, + expectedDynamicFee: 13_419_100 * units.NanoAvax, }, { name: "AddPermissionlessValidatorTx for subnet", @@ -88,9 +88,9 @@ var ( gas.Bandwidth: 748, // The length of the tx in bytes gas.DBRead: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBRead] + 2*intrinsicInputDBRead, gas.DBWrite: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBWrite] + 2*intrinsicInputDBWrite + 3*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 314_800, + expectedDynamicFee: 16_974_800 * units.NanoAvax, }, { name: "AddPermissionlessDelegatorTx for primary network", @@ -100,9 +100,9 @@ var ( gas.Bandwidth: 499, // The length of the tx in bytes gas.DBRead: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBRead] + 1*intrinsicInputDBRead, gas.DBWrite: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBWrite] + 1*intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 209_900, + expectedDynamicFee: 10_599_900 * units.NanoAvax, }, { name: "AddPermissionlessDelegatorTx for subnet", @@ -112,9 +112,9 @@ var ( gas.Bandwidth: 720, // The length of the tx in bytes gas.DBRead: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBRead] + 2*intrinsicInputDBRead, gas.DBWrite: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBWrite] + 2*intrinsicInputDBWrite + 3*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 312_000, + expectedDynamicFee: 14_972_000 * units.NanoAvax, }, { name: "AddSubnetValidatorTx", @@ -124,9 +124,9 @@ var ( gas.Bandwidth: 460, // The length of the tx in bytes gas.DBRead: IntrinsicAddSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicAddSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 196_000, + expectedDynamicFee: 11_146_000 * units.NanoAvax, }, { name: "BaseTx", @@ -136,9 +136,9 @@ var ( gas.Bandwidth: 399, // The length of the tx in bytes gas.DBRead: IntrinsicBaseTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicBaseTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 149_900, + expectedDynamicFee: 6_389_900 * units.NanoAvax, }, { name: "CreateChainTx", @@ -148,9 +148,9 @@ var ( gas.Bandwidth: 509, // The length of the tx in bytes gas.DBRead: IntrinsicCreateChainTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicCreateChainTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 180_900, + expectedDynamicFee: 7_150_900 * units.NanoAvax, }, { name: "CreateSubnetTx", @@ -160,9 +160,9 @@ var ( gas.Bandwidth: 339, // The length of the tx in bytes gas.DBRead: IntrinsicCreateSubnetTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicCreateSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 143_900, + expectedDynamicFee: 6_383_900 * units.NanoAvax, }, { name: "ExportTx", @@ -172,9 +172,9 @@ var ( gas.Bandwidth: 435, // The length of the tx in bytes gas.DBRead: IntrinsicExportTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicExportTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 153_500, + expectedDynamicFee: 6_393_500 * units.NanoAvax, }, { name: "ImportTx", @@ -184,9 +184,9 @@ var ( gas.Bandwidth: 335, // The length of the tx in bytes gas.DBRead: IntrinsicImportTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicImportTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 113_500, + expectedDynamicFee: 4_383_500 * units.NanoAvax, }, { name: "RemoveSubnetValidatorTx", @@ -196,9 +196,9 @@ var ( gas.Bandwidth: 436, // The length of the tx in bytes gas.DBRead: IntrinsicRemoveSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicRemoveSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 193_600, + expectedDynamicFee: 10_743_600 * units.NanoAvax, }, { name: "TransformSubnetTx", @@ -215,9 +215,9 @@ var ( gas.Bandwidth: 436, // The length of the tx in bytes gas.DBRead: IntrinsicTransferSubnetOwnershipTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicTransferSubnetOwnershipTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 173_600, + expectedDynamicFee: 6_743_600 * units.NanoAvax, }, { name: "ConvertSubnetTx", @@ -227,9 +227,9 @@ var ( gas.Bandwidth: 656, // The length of the tx in bytes gas.DBRead: IntrinsicConvertSubnetTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicConvertSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite + intrinsicConvertSubnetValidatorDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: 2*intrinsicSECP256k1FxSignatureCompute + intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 365_600, + expectedDynamicFee: 17_965_600 * units.NanoAvax, }, { name: "RegisterSubnetValidatorTx", @@ -237,11 +237,11 @@ var ( expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 710, // The length of the tx in bytes - gas.DBRead: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBRead: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead + intrinsicWarpDBReads, gas.DBWrite: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSAggregateCompute + 2*intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 151_000, + expectedDynamicFee: 23_625_000 * units.NanoAvax, }, { name: "SetSubnetValidatorWeightTx", @@ -249,11 +249,11 @@ var ( expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 518, // The length of the tx in bytes - gas.DBRead: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBRead: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBRead] + intrinsicInputDBRead + intrinsicWarpDBReads, gas.DBWrite: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSAggregateCompute + intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 131_800, + expectedDynamicFee: 20_405_800 * units.NanoAvax, }, { name: "IncreaseBalanceTx", @@ -263,9 +263,9 @@ var ( gas.Bandwidth: 339, // The length of the tx in bytes gas.DBRead: IntrinsicIncreaseBalanceTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicIncreaseBalanceTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 113_900, + expectedDynamicFee: 14_583_900 * units.NanoAvax, }, { name: "DisableSubnetValidatorTx", @@ -275,9 +275,9 @@ var ( gas.Bandwidth: 347, // The length of the tx in bytes gas.DBRead: IntrinsicDisableSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicDisableSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: 0, // TODO: implement + gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 114_700, + expectedDynamicFee: 16_584_700 * units.NanoAvax, }, } ) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index acea57d2c986..fa12dbab193b 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -21,6 +21,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/stakeable" "github.com/ava-labs/avalanchego/vms/platformvm/txs" + "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/secp256k1fx" ) @@ -64,6 +65,8 @@ const ( intrinsicSECP256k1FxSignatureBandwidth = wrappers.IntLen + // signature index secp256k1.SignatureLen // signature length + intrinsicSECP256k1FxSignatureCompute = 150 // secp256k1 signature verification time is around 150us + intrinsicConvertSubnetValidatorBandwidth = wrappers.IntLen + // nodeID length wrappers.LongLen + // weight wrappers.LongLen + // balance @@ -72,6 +75,11 @@ const ( wrappers.IntLen + // deactivation owner threshold wrappers.IntLen // deactivation owner num addresses + intrinsicBLSAggregateCompute = 4 // BLS public key aggregation time is around 4us + intrinsicBLSVerifyCompute = 800 // BLS verification time is around 800us + + intrinsicWarpDBReads = 3 + 20 // chainID -> subnetID mapping + apply weight diffs + apply pk diffs + diff application reads + intrinsicPoPBandwidth = bls.PublicKeyLen + // public key bls.SignatureLen // signature @@ -79,7 +87,7 @@ const ( intrinsicInputDBWrite = 1 intrinsicOutputDBWrite = 1 - intrinsicConvertSubnetValidatorDBWrite = 4 // weight diff + pub key diff + subnetID/nodeID + validationID + intrinsicConvertSubnetValidatorDBWrite = 5 // weight diff + pub key diff + subnetID/nodeID + validationID + l1 weight ) var ( @@ -90,8 +98,8 @@ var ( intrinsicSubnetValidatorBandwidth + // subnetValidator wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID - gas.DBRead: 2, - gas.DBWrite: 1, + gas.DBRead: 3, // get subnet auth + check for subnet transformation + check for subnet conversion + gas.DBWrite: 3, // put current staker + write weight diff + write pk diff gas.Compute: 0, } IntrinsicCreateChainTxComplexities = gas.Dimensions{ @@ -103,15 +111,15 @@ var ( wrappers.IntLen + // genesis length wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID - gas.DBRead: 1, - gas.DBWrite: 1, + gas.DBRead: 3, // get subnet auth + check for subnet transformation + check for subnet conversion + gas.DBWrite: 1, // put chain gas.Compute: 0, } IntrinsicCreateSubnetTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + wrappers.IntLen, // owner typeID gas.DBRead: 0, - gas.DBWrite: 1, + gas.DBWrite: 1, // write subnet owner gas.Compute: 0, } IntrinsicImportTxComplexities = gas.Dimensions{ @@ -136,8 +144,8 @@ var ( ids.IDLen + // subnetID wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID - gas.DBRead: 2, - gas.DBWrite: 1, + gas.DBRead: 1, // read subnet auth + gas.DBWrite: 3, // delete validator + write weight diff + write pk diff gas.Compute: 0, } IntrinsicAddPermissionlessValidatorTxComplexities = gas.Dimensions{ @@ -149,8 +157,8 @@ var ( wrappers.IntLen + // validator rewards typeID wrappers.IntLen + // delegator rewards typeID wrappers.IntLen, // delegation shares - gas.DBRead: 1, - gas.DBWrite: 1, + gas.DBRead: 1, // get staking config + gas.DBWrite: 3, // put current staker + write weight diff + write pk diff gas.Compute: 0, } IntrinsicAddPermissionlessDelegatorTxComplexities = gas.Dimensions{ @@ -159,8 +167,8 @@ var ( ids.IDLen + // subnetID wrappers.IntLen + // num stake outs wrappers.IntLen, // delegator rewards typeID - gas.DBRead: 1, - gas.DBWrite: 1, + gas.DBRead: 1, // get staking config + gas.DBWrite: 2, // put current staker + write weight diff gas.Compute: 0, } IntrinsicTransferSubnetOwnershipTxComplexities = gas.Dimensions{ @@ -169,8 +177,8 @@ var ( wrappers.IntLen + // subnetAuth typeID wrappers.IntLen + // owner typeID wrappers.IntLen, // subnetAuthCredential typeID - gas.DBRead: 1, - gas.DBWrite: 1, + gas.DBRead: 1, // read subnet auth + gas.DBWrite: 1, // set subnet owner gas.Compute: 0, } IntrinsicBaseTxComplexities = gas.Dimensions{ @@ -194,8 +202,8 @@ var ( wrappers.IntLen + // validators length wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID - gas.DBRead: 2, // subnet auth + manager lookup - gas.DBWrite: 2, // manager + weight + gas.DBRead: 3, // subnet auth + transformation lookup + conversion lookup + gas.DBWrite: 1, // write conversion manager gas.Compute: 0, } IntrinsicRegisterSubnetValidatorTxComplexities = gas.Dimensions{ @@ -203,23 +211,23 @@ var ( wrappers.LongLen + // balance bls.SignatureLen + // proof of possession wrappers.IntLen, // message length - gas.DBRead: 0, // TODO - gas.DBWrite: 0, // TODO - gas.Compute: 0, // TODO: Include PoP verification time + gas.DBRead: 5, // conversion owner + expiry lookup + sov lookup + subnetID/nodeID lookup + weight lookup + gas.DBWrite: 6, // write current staker + expiry + write weight diff + write pk diff + subnetID/nodeID lookup + weight lookup + gas.Compute: intrinsicBLSVerifyCompute, } IntrinsicSetSubnetValidatorWeightTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + wrappers.IntLen, // message length - gas.DBRead: 0, // TODO - gas.DBWrite: 0, // TODO + gas.DBRead: 3, // read staker + read conversion + read weight + gas.DBWrite: 5, // remaining balance utxo + write weight diff + write pk diff + weights lookup + validator write gas.Compute: 0, } IntrinsicIncreaseBalanceTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // validationID wrappers.LongLen, // balance - gas.DBRead: 0, // TODO - gas.DBWrite: 0, // TODO + gas.DBRead: 1, // read staker + gas.DBWrite: 5, // weight diff + deactivated weight diff + public key diff + delete staker + write staker gas.Compute: 0, } IntrinsicDisableSubnetValidatorTxComplexities = gas.Dimensions{ @@ -227,8 +235,8 @@ var ( ids.IDLen + // validationID wrappers.IntLen + // auth typeID wrappers.IntLen, // authCredential typeID - gas.DBRead: 0, // TODO - gas.DBWrite: 0, // TODO + gas.DBRead: 1, // read staker + gas.DBWrite: 6, // write remaining balance utxo + weight diff + deactivated weight diff + public key diff + delete staker + write staker gas.Compute: 0, } @@ -327,7 +335,6 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { gas.Bandwidth: intrinsicInputBandwidth + intrinsicSECP256k1FxTransferableInputBandwidth, gas.DBRead: intrinsicInputDBRead, gas.DBWrite: intrinsicInputDBWrite, - gas.Compute: 0, // TODO: Add compute complexity } inIntf := in.In @@ -342,11 +349,21 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { } numSignatures := uint64(len(secp256k1In.SigIndices)) + // Add signature bandwidth signatureBandwidth, err := math.Mul(numSignatures, intrinsicSECP256k1FxSignatureBandwidth) if err != nil { return gas.Dimensions{}, err } complexity[gas.Bandwidth], err = math.Add(complexity[gas.Bandwidth], signatureBandwidth) + if err != nil { + return gas.Dimensions{}, err + } + + // Add signature compute + complexity[gas.Compute], err = math.Mul(numSignatures, intrinsicSECP256k1FxSignatureCompute) + if err != nil { + return gas.Dimensions{}, err + } return complexity, err } @@ -373,7 +390,7 @@ func convertSubnetValidatorComplexity(sov *txs.ConvertSubnetValidator) (gas.Dime gas.Bandwidth: intrinsicConvertSubnetValidatorBandwidth, gas.DBRead: 0, gas.DBWrite: intrinsicConvertSubnetValidatorDBWrite, - gas.Compute: 0, // TODO: Add compute complexity + gas.Compute: 0, } signerComplexity, err := SignerComplexity(&sov.Signer) @@ -445,11 +462,16 @@ func AuthComplexity(authIntf verify.Verifiable) (gas.Dimensions, error) { return gas.Dimensions{}, err } + signatureCompute, err := math.Mul(numSignatures, intrinsicSECP256k1FxSignatureCompute) + if err != nil { + return gas.Dimensions{}, err + } + return gas.Dimensions{ gas.Bandwidth: bandwidth, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: Add compute complexity + gas.Compute: signatureCompute, }, nil } @@ -464,7 +486,7 @@ func SignerComplexity(s signer.Signer) (gas.Dimensions, error) { gas.Bandwidth: intrinsicPoPBandwidth, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: Add compute complexity + gas.Compute: intrinsicBLSVerifyCompute, }, nil default: return gas.Dimensions{}, errUnsupportedSigner @@ -473,9 +495,29 @@ func SignerComplexity(s signer.Signer) (gas.Dimensions, error) { // WarpComplexity returns the complexity a warp message adds to a transaction. func WarpComplexity(message []byte) (gas.Dimensions, error) { - // TODO: Implement me + msg, err := warp.ParseMessage(message) + if err != nil { + return gas.Dimensions{}, err + } + + numSigners, err := msg.Signature.NumSigners() + if err != nil { + return gas.Dimensions{}, err + } + aggregationCompute, err := math.Mul(uint64(numSigners), intrinsicBLSAggregateCompute) + if err != nil { + return gas.Dimensions{}, err + } + + compute, err := math.Add(aggregationCompute, intrinsicBLSVerifyCompute) + if err != nil { + return gas.Dimensions{}, err + } + return gas.Dimensions{ gas.Bandwidth: uint64(len(message)), + gas.DBRead: intrinsicWarpDBReads, + gas.Compute: compute, }, nil } @@ -576,7 +618,6 @@ func (c *complexityVisitor) ImportTx(tx *txs.ImportTx) error { if err != nil { return err } - // TODO: Should imported inputs be more complex? inputsComplexity, err := InputComplexity(tx.ImportedInputs...) if err != nil { return err @@ -593,7 +634,6 @@ func (c *complexityVisitor) ExportTx(tx *txs.ExportTx) error { if err != nil { return err } - // TODO: Should exported outputs be more complex? outputsComplexity, err := OutputComplexity(tx.ExportedOutputs...) if err != nil { return err @@ -622,7 +662,6 @@ func (c *complexityVisitor) RemoveSubnetValidatorTx(tx *txs.RemoveSubnetValidato } func (c *complexityVisitor) AddPermissionlessValidatorTx(tx *txs.AddPermissionlessValidatorTx) error { - // TODO: Should we include additional complexity for subnets? baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err @@ -654,7 +693,6 @@ func (c *complexityVisitor) AddPermissionlessValidatorTx(tx *txs.AddPermissionle } func (c *complexityVisitor) AddPermissionlessDelegatorTx(tx *txs.AddPermissionlessDelegatorTx) error { - // TODO: Should we include additional complexity for subnets? baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index d0767317df3b..bcfc38fbfe0a 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -262,7 +262,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 92, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 0, // TODO: implement + gas.Compute: 0, }, expectedErr: nil, }, @@ -282,7 +282,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 161, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 0, // TODO: implement + gas.Compute: 150, }, expectedErr: nil, }, @@ -302,7 +302,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 299, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 0, // TODO: implement + gas.Compute: 450, }, expectedErr: nil, }, @@ -324,7 +324,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 311, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 0, // TODO: implement + gas.Compute: 450, }, expectedErr: nil, }, @@ -385,8 +385,8 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 200, gas.DBRead: 0, - gas.DBWrite: 4, - gas.Compute: 0, // TODO: implement + gas.DBWrite: 5, + gas.Compute: 800, }, }, { @@ -405,8 +405,8 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBRead: 0, - gas.DBWrite: 4, - gas.Compute: 0, // TODO: implement + gas.DBWrite: 5, + gas.Compute: 800, }, }, { @@ -425,8 +425,8 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBRead: 0, - gas.DBWrite: 4, - gas.Compute: 0, // TODO: implement + gas.DBWrite: 5, + gas.Compute: 800, }, }, } @@ -541,7 +541,7 @@ func TestAuthComplexity(t *testing.T) { gas.Bandwidth: 8, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: implement + gas.Compute: 0, }, expectedErr: nil, }, @@ -557,7 +557,7 @@ func TestAuthComplexity(t *testing.T) { gas.Bandwidth: 77, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: implement + gas.Compute: 150, }, expectedErr: nil, }, @@ -573,7 +573,7 @@ func TestAuthComplexity(t *testing.T) { gas.Bandwidth: 215, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: implement + gas.Compute: 450, }, expectedErr: nil, }, @@ -585,7 +585,7 @@ func TestAuthComplexity(t *testing.T) { gas.Bandwidth: 0, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: implement + gas.Compute: 0, }, expectedErr: errUnsupportedAuth, }, @@ -639,7 +639,7 @@ func TestSignerComplexity(t *testing.T) { gas.Bandwidth: 144, gas.DBRead: 0, gas.DBWrite: 0, - gas.Compute: 0, // TODO: implement + gas.Compute: 800, }, expectedErr: nil, }, From 8c069305fdfd41c73557b7656322c53478078d22 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:38:45 -0500 Subject: [PATCH 02/11] nit --- vms/platformvm/txs/fee/complexity.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index fa12dbab193b..7d76264a89e1 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -335,6 +335,7 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { gas.Bandwidth: intrinsicInputBandwidth + intrinsicSECP256k1FxTransferableInputBandwidth, gas.DBRead: intrinsicInputDBRead, gas.DBWrite: intrinsicInputDBWrite, + gas.Compute: 0, } inIntf := in.In From 7ae157f53f4914ec92764ccd043e6828c152262e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:42:05 -0500 Subject: [PATCH 03/11] Reprice subnet conversion --- vms/platformvm/txs/fee/complexity.go | 4 ++-- vms/platformvm/txs/fee/complexity_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index 7d76264a89e1..c316a573e90f 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -87,7 +87,7 @@ const ( intrinsicInputDBWrite = 1 intrinsicOutputDBWrite = 1 - intrinsicConvertSubnetValidatorDBWrite = 5 // weight diff + pub key diff + subnetID/nodeID + validationID + l1 weight + intrinsicConvertSubnetValidatorDBWrite = 4 // weight diff + pub key diff + subnetID/nodeID + validationID ) var ( @@ -203,7 +203,7 @@ var ( wrappers.IntLen + // subnetAuth typeID wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 3, // subnet auth + transformation lookup + conversion lookup - gas.DBWrite: 1, // write conversion manager + gas.DBWrite: 2, // write conversion manager + total weight gas.Compute: 0, } IntrinsicRegisterSubnetValidatorTxComplexities = gas.Dimensions{ diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index bcfc38fbfe0a..68ae7a681de3 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -385,7 +385,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 200, gas.DBRead: 0, - gas.DBWrite: 5, + gas.DBWrite: 4, gas.Compute: 800, }, }, @@ -405,7 +405,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBRead: 0, - gas.DBWrite: 5, + gas.DBWrite: 4, gas.Compute: 800, }, }, @@ -425,7 +425,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBRead: 0, - gas.DBWrite: 5, + gas.DBWrite: 4, gas.Compute: 800, }, }, From 5aca596db85c21119c176c9274a660cecd7cddc3 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:48:24 -0500 Subject: [PATCH 04/11] nit --- vms/platformvm/txs/fee/complexity.go | 36 ---------- vms/platformvm/txs/fee/complexity_test.go | 81 ++++------------------- 2 files changed, 13 insertions(+), 104 deletions(-) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index c316a573e90f..e2c40f53112f 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -100,7 +100,6 @@ var ( wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 3, // get subnet auth + check for subnet transformation + check for subnet conversion gas.DBWrite: 3, // put current staker + write weight diff + write pk diff - gas.Compute: 0, } IntrinsicCreateChainTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -113,30 +112,21 @@ var ( wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 3, // get subnet auth + check for subnet transformation + check for subnet conversion gas.DBWrite: 1, // put chain - gas.Compute: 0, } IntrinsicCreateSubnetTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + wrappers.IntLen, // owner typeID - gas.DBRead: 0, gas.DBWrite: 1, // write subnet owner - gas.Compute: 0, } IntrinsicImportTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // source chainID wrappers.IntLen, // num importing inputs - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, } IntrinsicExportTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // destination chainID wrappers.IntLen, // num exported outputs - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, } IntrinsicRemoveSubnetValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -146,7 +136,6 @@ var ( wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 1, // read subnet auth gas.DBWrite: 3, // delete validator + write weight diff + write pk diff - gas.Compute: 0, } IntrinsicAddPermissionlessValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -159,7 +148,6 @@ var ( wrappers.IntLen, // delegation shares gas.DBRead: 1, // get staking config gas.DBWrite: 3, // put current staker + write weight diff + write pk diff - gas.Compute: 0, } IntrinsicAddPermissionlessDelegatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -169,7 +157,6 @@ var ( wrappers.IntLen, // delegator rewards typeID gas.DBRead: 1, // get staking config gas.DBWrite: 2, // put current staker + write weight diff - gas.Compute: 0, } IntrinsicTransferSubnetOwnershipTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -179,7 +166,6 @@ var ( wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 1, // read subnet auth gas.DBWrite: 1, // set subnet owner - gas.Compute: 0, } IntrinsicBaseTxComplexities = gas.Dimensions{ gas.Bandwidth: codec.VersionSize + // codecVersion @@ -190,9 +176,6 @@ var ( wrappers.IntLen + // number of inputs wrappers.IntLen + // length of memo wrappers.IntLen, // number of credentials - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, } IntrinsicConvertSubnetTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -204,7 +187,6 @@ var ( wrappers.IntLen, // subnetAuthCredential typeID gas.DBRead: 3, // subnet auth + transformation lookup + conversion lookup gas.DBWrite: 2, // write conversion manager + total weight - gas.Compute: 0, } IntrinsicRegisterSubnetValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -220,7 +202,6 @@ var ( wrappers.IntLen, // message length gas.DBRead: 3, // read staker + read conversion + read weight gas.DBWrite: 5, // remaining balance utxo + write weight diff + write pk diff + weights lookup + validator write - gas.Compute: 0, } IntrinsicIncreaseBalanceTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -228,7 +209,6 @@ var ( wrappers.LongLen, // balance gas.DBRead: 1, // read staker gas.DBWrite: 5, // weight diff + deactivated weight diff + public key diff + delete staker + write staker - gas.Compute: 0, } IntrinsicDisableSubnetValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -237,7 +217,6 @@ var ( wrappers.IntLen, // authCredential typeID gas.DBRead: 1, // read staker gas.DBWrite: 6, // write remaining balance utxo + weight diff + deactivated weight diff + public key diff + delete staker + write staker - gas.Compute: 0, } errUnsupportedOutput = errors.New("unsupported output type") @@ -287,9 +266,7 @@ func OutputComplexity(outs ...*avax.TransferableOutput) (gas.Dimensions, error) func outputComplexity(out *avax.TransferableOutput) (gas.Dimensions, error) { complexity := gas.Dimensions{ gas.Bandwidth: intrinsicOutputBandwidth + intrinsicSECP256k1FxOutputBandwidth, - gas.DBRead: 0, gas.DBWrite: intrinsicOutputDBWrite, - gas.Compute: 0, } outIntf := out.Out @@ -335,7 +312,6 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { gas.Bandwidth: intrinsicInputBandwidth + intrinsicSECP256k1FxTransferableInputBandwidth, gas.DBRead: intrinsicInputDBRead, gas.DBWrite: intrinsicInputDBWrite, - gas.Compute: 0, } inIntf := in.In @@ -389,9 +365,7 @@ func ConvertSubnetValidatorComplexity(sovs ...*txs.ConvertSubnetValidator) (gas. func convertSubnetValidatorComplexity(sov *txs.ConvertSubnetValidator) (gas.Dimensions, error) { complexity := gas.Dimensions{ gas.Bandwidth: intrinsicConvertSubnetValidatorBandwidth, - gas.DBRead: 0, gas.DBWrite: intrinsicConvertSubnetValidatorDBWrite, - gas.Compute: 0, } signerComplexity, err := SignerComplexity(&sov.Signer) @@ -436,9 +410,6 @@ func OwnerComplexity(ownerIntf fx.Owner) (gas.Dimensions, error) { return gas.Dimensions{ gas.Bandwidth: bandwidth, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, }, nil } @@ -470,8 +441,6 @@ func AuthComplexity(authIntf verify.Verifiable) (gas.Dimensions, error) { return gas.Dimensions{ gas.Bandwidth: bandwidth, - gas.DBRead: 0, - gas.DBWrite: 0, gas.Compute: signatureCompute, }, nil } @@ -485,8 +454,6 @@ func SignerComplexity(s signer.Signer) (gas.Dimensions, error) { case *signer.ProofOfPossession: return gas.Dimensions{ gas.Bandwidth: intrinsicPoPBandwidth, - gas.DBRead: 0, - gas.DBWrite: 0, gas.Compute: intrinsicBLSVerifyCompute, }, nil default: @@ -577,9 +544,6 @@ func (c *complexityVisitor) CreateChainTx(tx *txs.CreateChainTx) error { } dynamicComplexity := gas.Dimensions{ gas.Bandwidth: bandwidth, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, } baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index 68ae7a681de3..c15cf66bf1a7 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -144,9 +144,7 @@ func TestOutputComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 60, - gas.DBRead: 0, gas.DBWrite: 1, - gas.Compute: 0, }, expectedErr: nil, }, @@ -161,9 +159,7 @@ func TestOutputComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 80, - gas.DBRead: 0, gas.DBWrite: 1, - gas.Compute: 0, }, expectedErr: nil, }, @@ -178,9 +174,7 @@ func TestOutputComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 120, - gas.DBRead: 0, gas.DBWrite: 1, - gas.Compute: 0, }, expectedErr: nil, }, @@ -197,9 +191,7 @@ func TestOutputComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 132, - gas.DBRead: 0, gas.DBWrite: 1, - gas.Compute: 0, }, expectedErr: nil, }, @@ -208,12 +200,7 @@ func TestOutputComplexity(t *testing.T) { out: &avax.TransferableOutput{ Out: nil, }, - expected: gas.Dimensions{ - gas.Bandwidth: 0, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, - }, + expected: gas.Dimensions{}, expectedErr: errUnsupportedOutput, }, } @@ -262,7 +249,6 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 92, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 0, }, expectedErr: nil, }, @@ -333,13 +319,8 @@ func TestInputComplexity(t *testing.T) { in: &avax.TransferableInput{ In: nil, }, - cred: nil, - expected: gas.Dimensions{ - gas.Bandwidth: 0, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, - }, + cred: nil, + expected: gas.Dimensions{}, expectedErr: errUnsupportedInput, }, } @@ -384,7 +365,6 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 200, - gas.DBRead: 0, gas.DBWrite: 4, gas.Compute: 800, }, @@ -404,7 +384,6 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 220, - gas.DBRead: 0, gas.DBWrite: 4, gas.Compute: 800, }, @@ -424,7 +403,6 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 220, - gas.DBRead: 0, gas.DBWrite: 4, gas.Compute: 800, }, @@ -461,9 +439,6 @@ func TestOwnerComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 16, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, }, expectedErr: nil, }, @@ -474,9 +449,6 @@ func TestOwnerComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 36, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, }, expectedErr: nil, }, @@ -487,9 +459,6 @@ func TestOwnerComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 76, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, }, expectedErr: nil, }, @@ -539,9 +508,6 @@ func TestAuthComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 8, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, }, expectedErr: nil, }, @@ -555,8 +521,6 @@ func TestAuthComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 77, - gas.DBRead: 0, - gas.DBWrite: 0, gas.Compute: 150, }, expectedErr: nil, @@ -571,22 +535,15 @@ func TestAuthComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 215, - gas.DBRead: 0, - gas.DBWrite: 0, gas.Compute: 450, }, expectedErr: nil, }, { - name: "invalid auth type", - auth: nil, - cred: nil, - expected: gas.Dimensions{ - gas.Bandwidth: 0, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, - }, + name: "invalid auth type", + auth: nil, + cred: nil, + expected: gas.Dimensions{}, expectedErr: errUnsupportedAuth, }, } @@ -622,14 +579,9 @@ func TestSignerComplexity(t *testing.T) { expectedErr error }{ { - name: "empty", - signer: &signer.Empty{}, - expected: gas.Dimensions{ - gas.Bandwidth: 0, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, - }, + name: "empty", + signer: &signer.Empty{}, + expected: gas.Dimensions{}, expectedErr: nil, }, { @@ -637,21 +589,14 @@ func TestSignerComplexity(t *testing.T) { signer: &signer.ProofOfPossession{}, expected: gas.Dimensions{ gas.Bandwidth: 144, - gas.DBRead: 0, - gas.DBWrite: 0, gas.Compute: 800, }, expectedErr: nil, }, { - name: "invalid signer type", - signer: nil, - expected: gas.Dimensions{ - gas.Bandwidth: 0, - gas.DBRead: 0, - gas.DBWrite: 0, - gas.Compute: 0, - }, + name: "invalid signer type", + signer: nil, + expected: gas.Dimensions{}, expectedErr: errUnsupportedSigner, }, } From db6e663a6ab2d9c7328c183c8cd231f9184e880e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:55:59 -0500 Subject: [PATCH 05/11] fix test --- .../txs/executor/standard_tx_executor_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 793121a44917..791a04578915 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -3642,16 +3642,17 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { nil, // chainIDs ) - message := test.message - if message == nil { - message = increaseWeightWarpMessage.Bytes() - } setSubnetValidatorWeightTx, err := wallet.IssueSetSubnetValidatorWeightTx( - message, + increaseWeightWarpMessage.Bytes(), test.builderOptions..., ) require.NoError(err) + unsignedTx := setSubnetValidatorWeightTx.Unsigned.(*txs.SetSubnetValidatorWeightTx) + if test.message != nil { + unsignedTx.Message = test.message + } + diff, err := state.NewDiffOn(baseState) require.NoError(err) From b0d4519a3bf2706c5f99b6218f38fd058ae24434 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 11:57:47 -0500 Subject: [PATCH 06/11] nit --- vms/platformvm/txs/executor/standard_tx_executor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 791a04578915..1d47c68b76ef 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -3648,8 +3648,8 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { ) require.NoError(err) - unsignedTx := setSubnetValidatorWeightTx.Unsigned.(*txs.SetSubnetValidatorWeightTx) if test.message != nil { + unsignedTx := setSubnetValidatorWeightTx.Unsigned.(*txs.SetSubnetValidatorWeightTx) unsignedTx.Message = test.message } From 9088b40cfecd22e201511b430bd2ce33c648ee44 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 15:03:59 -0500 Subject: [PATCH 07/11] Update signature costs --- vms/platformvm/txs/fee/calculator_test.go | 36 +++++++++++------------ vms/platformvm/txs/fee/complexity.go | 6 ++-- vms/platformvm/txs/fee/complexity_test.go | 18 ++++++------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/vms/platformvm/txs/fee/calculator_test.go b/vms/platformvm/txs/fee/calculator_test.go index a44b08ecbcfd..2e3715aba731 100644 --- a/vms/platformvm/txs/fee/calculator_test.go +++ b/vms/platformvm/txs/fee/calculator_test.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/gas" ) -const testDynamicPrice = gas.Price(100 * units.NanoAvax) +const testDynamicPrice = gas.Price(units.NanoAvax) var ( testStaticConfig = StaticConfig{ @@ -78,7 +78,7 @@ var ( gas.DBWrite: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, gas.Compute: intrinsicBLSVerifyCompute + intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 13_419_100 * units.NanoAvax, + expectedDynamicFee: 136_691 * units.NanoAvax, }, { name: "AddPermissionlessValidatorTx for subnet", @@ -90,7 +90,7 @@ var ( gas.DBWrite: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBWrite] + 2*intrinsicInputDBWrite + 3*intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 16_974_800 * units.NanoAvax, + expectedDynamicFee: 170_748 * units.NanoAvax, }, { name: "AddPermissionlessDelegatorTx for primary network", @@ -102,7 +102,7 @@ var ( gas.DBWrite: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBWrite] + 1*intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 10_599_900 * units.NanoAvax, + expectedDynamicFee: 106_499 * units.NanoAvax, }, { name: "AddPermissionlessDelegatorTx for subnet", @@ -114,7 +114,7 @@ var ( gas.DBWrite: IntrinsicAddPermissionlessDelegatorTxComplexities[gas.DBWrite] + 2*intrinsicInputDBWrite + 3*intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 14_972_000 * units.NanoAvax, + expectedDynamicFee: 150_720 * units.NanoAvax, }, { name: "AddSubnetValidatorTx", @@ -126,7 +126,7 @@ var ( gas.DBWrite: IntrinsicAddSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 11_146_000 * units.NanoAvax, + expectedDynamicFee: 112_460 * units.NanoAvax, }, { name: "BaseTx", @@ -138,7 +138,7 @@ var ( gas.DBWrite: IntrinsicBaseTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 6_389_900 * units.NanoAvax, + expectedDynamicFee: 64_399 * units.NanoAvax, }, { name: "CreateChainTx", @@ -150,7 +150,7 @@ var ( gas.DBWrite: IntrinsicCreateChainTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 7_150_900 * units.NanoAvax, + expectedDynamicFee: 72_509 * units.NanoAvax, }, { name: "CreateSubnetTx", @@ -162,7 +162,7 @@ var ( gas.DBWrite: IntrinsicCreateSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 6_383_900 * units.NanoAvax, + expectedDynamicFee: 64_339 * units.NanoAvax, }, { name: "ExportTx", @@ -174,7 +174,7 @@ var ( gas.DBWrite: IntrinsicExportTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 6_393_500 * units.NanoAvax, + expectedDynamicFee: 64_435 * units.NanoAvax, }, { name: "ImportTx", @@ -186,7 +186,7 @@ var ( gas.DBWrite: IntrinsicImportTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 4_383_500 * units.NanoAvax, + expectedDynamicFee: 44_335 * units.NanoAvax, }, { name: "RemoveSubnetValidatorTx", @@ -198,7 +198,7 @@ var ( gas.DBWrite: IntrinsicRemoveSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 10_743_600 * units.NanoAvax, + expectedDynamicFee: 108_436 * units.NanoAvax, }, { name: "TransformSubnetTx", @@ -217,7 +217,7 @@ var ( gas.DBWrite: IntrinsicTransferSubnetOwnershipTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 2 * intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 6_743_600 * units.NanoAvax, + expectedDynamicFee: 68_436 * units.NanoAvax, }, { name: "ConvertSubnetTx", @@ -229,7 +229,7 @@ var ( gas.DBWrite: IntrinsicConvertSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite + intrinsicConvertSubnetValidatorDBWrite, gas.Compute: 2*intrinsicSECP256k1FxSignatureCompute + intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 17_965_600 * units.NanoAvax, + expectedDynamicFee: 182_656 * units.NanoAvax, }, { name: "RegisterSubnetValidatorTx", @@ -241,7 +241,7 @@ var ( gas.DBWrite: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSAggregateCompute + 2*intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 23_625_000 * units.NanoAvax, + expectedDynamicFee: 240_760 * units.NanoAvax, }, { name: "SetSubnetValidatorWeightTx", @@ -253,7 +253,7 @@ var ( gas.DBWrite: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSAggregateCompute + intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 20_405_800 * units.NanoAvax, + expectedDynamicFee: 206_568 * units.NanoAvax, }, { name: "IncreaseBalanceTx", @@ -265,7 +265,7 @@ var ( gas.DBWrite: IntrinsicIncreaseBalanceTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 14_583_900 * units.NanoAvax, + expectedDynamicFee: 146_339 * units.NanoAvax, }, { name: "DisableSubnetValidatorTx", @@ -277,7 +277,7 @@ var ( gas.DBWrite: IntrinsicDisableSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 16_584_700 * units.NanoAvax, + expectedDynamicFee: 166_347 * units.NanoAvax, }, } ) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index e2c40f53112f..cfa0c8fe3145 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -65,7 +65,7 @@ const ( intrinsicSECP256k1FxSignatureBandwidth = wrappers.IntLen + // signature index secp256k1.SignatureLen // signature length - intrinsicSECP256k1FxSignatureCompute = 150 // secp256k1 signature verification time is around 150us + intrinsicSECP256k1FxSignatureCompute = 200 // secp256k1 signature verification time is around 200us intrinsicConvertSubnetValidatorBandwidth = wrappers.IntLen + // nodeID length wrappers.LongLen + // weight @@ -75,8 +75,8 @@ const ( wrappers.IntLen + // deactivation owner threshold wrappers.IntLen // deactivation owner num addresses - intrinsicBLSAggregateCompute = 4 // BLS public key aggregation time is around 4us - intrinsicBLSVerifyCompute = 800 // BLS verification time is around 800us + intrinsicBLSAggregateCompute = 5 // BLS public key aggregation time is around 5us + intrinsicBLSVerifyCompute = 1_000 // BLS verification time is around 1000us intrinsicWarpDBReads = 3 + 20 // chainID -> subnetID mapping + apply weight diffs + apply pk diffs + diff application reads diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index c15cf66bf1a7..0e725f6cee48 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -268,7 +268,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 161, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 150, + gas.Compute: 200, }, expectedErr: nil, }, @@ -288,7 +288,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 299, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 450, + gas.Compute: 600, }, expectedErr: nil, }, @@ -310,7 +310,7 @@ func TestInputComplexity(t *testing.T) { gas.Bandwidth: 311, gas.DBRead: 1, gas.DBWrite: 1, - gas.Compute: 450, + gas.Compute: 600, }, expectedErr: nil, }, @@ -366,7 +366,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 200, gas.DBWrite: 4, - gas.Compute: 800, + gas.Compute: 1000, }, }, { @@ -385,7 +385,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBWrite: 4, - gas.Compute: 800, + gas.Compute: 1000, }, }, { @@ -404,7 +404,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBWrite: 4, - gas.Compute: 800, + gas.Compute: 1000, }, }, } @@ -521,7 +521,7 @@ func TestAuthComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 77, - gas.Compute: 150, + gas.Compute: 200, }, expectedErr: nil, }, @@ -535,7 +535,7 @@ func TestAuthComplexity(t *testing.T) { }, expected: gas.Dimensions{ gas.Bandwidth: 215, - gas.Compute: 450, + gas.Compute: 600, }, expectedErr: nil, }, @@ -589,7 +589,7 @@ func TestSignerComplexity(t *testing.T) { signer: &signer.ProofOfPossession{}, expected: gas.Dimensions{ gas.Bandwidth: 144, - gas.Compute: 800, + gas.Compute: 1000, }, expectedErr: nil, }, From 952e5513542d8fb4860d28b341a4c889814d4ddc Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 15:17:26 -0500 Subject: [PATCH 08/11] Add comment about AWS instance type --- vms/platformvm/txs/fee/complexity.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index cfa0c8fe3145..e664f86b133f 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -25,6 +25,8 @@ import ( "github.com/ava-labs/avalanchego/vms/secp256k1fx" ) +// Signature verification costs were conservatively based on benchmarks run on +// an AWS c5.xlarge instance. const ( intrinsicValidatorBandwidth = ids.NodeIDLen + // nodeID wrappers.LongLen + // start From a8ecc0c4c71695cf99f756db7f88f2c95074ad89 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 18:45:36 -0500 Subject: [PATCH 09/11] add comment --- vms/platformvm/txs/fee/complexity.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index e664f86b133f..675de185f242 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -454,6 +454,8 @@ func SignerComplexity(s signer.Signer) (gas.Dimensions, error) { case *signer.Empty: return gas.Dimensions{}, nil case *signer.ProofOfPossession: + // The PoP also decompresses and validates the public key, but that is + // insignificant compared to the signature verification. return gas.Dimensions{ gas.Bandwidth: intrinsicPoPBandwidth, gas.Compute: intrinsicBLSVerifyCompute, From d9c72cbe41013dc2b241d3b0b2c96a44c653d0df Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 18:55:42 -0500 Subject: [PATCH 10/11] Include decompression time --- vms/platformvm/txs/fee/calculator_test.go | 12 ++++++------ vms/platformvm/txs/fee/complexity.go | 12 ++++++------ vms/platformvm/txs/fee/complexity_test.go | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/vms/platformvm/txs/fee/calculator_test.go b/vms/platformvm/txs/fee/calculator_test.go index 2e3715aba731..f9b9d8edd49d 100644 --- a/vms/platformvm/txs/fee/calculator_test.go +++ b/vms/platformvm/txs/fee/calculator_test.go @@ -76,9 +76,9 @@ var ( gas.Bandwidth: 691, // The length of the tx in bytes gas.DBRead: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicAddPermissionlessValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + 2*intrinsicOutputDBWrite, - gas.Compute: intrinsicBLSVerifyCompute + intrinsicSECP256k1FxSignatureCompute, + gas.Compute: intrinsicBLSPoPVerifyCompute + intrinsicSECP256k1FxSignatureCompute, }, - expectedDynamicFee: 136_691 * units.NanoAvax, + expectedDynamicFee: 137_191 * units.NanoAvax, }, { name: "AddPermissionlessValidatorTx for subnet", @@ -227,9 +227,9 @@ var ( gas.Bandwidth: 656, // The length of the tx in bytes gas.DBRead: IntrinsicConvertSubnetTxComplexities[gas.DBRead] + intrinsicInputDBRead, gas.DBWrite: IntrinsicConvertSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite + intrinsicConvertSubnetValidatorDBWrite, - gas.Compute: 2*intrinsicSECP256k1FxSignatureCompute + intrinsicBLSVerifyCompute, + gas.Compute: 2*intrinsicSECP256k1FxSignatureCompute + intrinsicBLSPoPVerifyCompute, }, - expectedDynamicFee: 182_656 * units.NanoAvax, + expectedDynamicFee: 183_156 * units.NanoAvax, }, { name: "RegisterSubnetValidatorTx", @@ -239,9 +239,9 @@ var ( gas.Bandwidth: 710, // The length of the tx in bytes gas.DBRead: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead + intrinsicWarpDBReads, gas.DBWrite: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, - gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSAggregateCompute + 2*intrinsicBLSVerifyCompute, + gas.Compute: intrinsicSECP256k1FxSignatureCompute + intrinsicBLSPoPVerifyCompute + intrinsicBLSAggregateCompute + intrinsicBLSVerifyCompute, }, - expectedDynamicFee: 240_760 * units.NanoAvax, + expectedDynamicFee: 241_260 * units.NanoAvax, }, { name: "SetSubnetValidatorWeightTx", diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index 675de185f242..2b9155c9b54c 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -77,8 +77,10 @@ const ( wrappers.IntLen + // deactivation owner threshold wrappers.IntLen // deactivation owner num addresses - intrinsicBLSAggregateCompute = 5 // BLS public key aggregation time is around 5us - intrinsicBLSVerifyCompute = 1_000 // BLS verification time is around 1000us + intrinsicBLSAggregateCompute = 5 // BLS public key aggregation time is around 5us + intrinsicBLSVerifyCompute = 1_000 // BLS verification time is around 1000us + intrinsicBLSPublicKeyValidationCompute = 50 // BLS public key validation time is around 50us + intrinsicBLSPoPVerifyCompute = intrinsicBLSPublicKeyValidationCompute + intrinsicBLSVerifyCompute intrinsicWarpDBReads = 3 + 20 // chainID -> subnetID mapping + apply weight diffs + apply pk diffs + diff application reads @@ -197,7 +199,7 @@ var ( wrappers.IntLen, // message length gas.DBRead: 5, // conversion owner + expiry lookup + sov lookup + subnetID/nodeID lookup + weight lookup gas.DBWrite: 6, // write current staker + expiry + write weight diff + write pk diff + subnetID/nodeID lookup + weight lookup - gas.Compute: intrinsicBLSVerifyCompute, + gas.Compute: intrinsicBLSPoPVerifyCompute, } IntrinsicSetSubnetValidatorWeightTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + @@ -454,11 +456,9 @@ func SignerComplexity(s signer.Signer) (gas.Dimensions, error) { case *signer.Empty: return gas.Dimensions{}, nil case *signer.ProofOfPossession: - // The PoP also decompresses and validates the public key, but that is - // insignificant compared to the signature verification. return gas.Dimensions{ gas.Bandwidth: intrinsicPoPBandwidth, - gas.Compute: intrinsicBLSVerifyCompute, + gas.Compute: intrinsicBLSPoPVerifyCompute, }, nil default: return gas.Dimensions{}, errUnsupportedSigner diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index 0e725f6cee48..e74df96dd220 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -366,7 +366,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 200, gas.DBWrite: 4, - gas.Compute: 1000, + gas.Compute: 1050, }, }, { @@ -385,7 +385,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBWrite: 4, - gas.Compute: 1000, + gas.Compute: 1050, }, }, { @@ -404,7 +404,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { expected: gas.Dimensions{ gas.Bandwidth: 220, gas.DBWrite: 4, - gas.Compute: 1000, + gas.Compute: 1050, }, }, } @@ -589,7 +589,7 @@ func TestSignerComplexity(t *testing.T) { signer: &signer.ProofOfPossession{}, expected: gas.Dimensions{ gas.Bandwidth: 144, - gas.Compute: 1000, + gas.Compute: 1050, }, expectedErr: nil, }, From b94dc41dcae48e1374a5d7f9246f06bb8f82dd12 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 14 Nov 2024 19:08:57 -0500 Subject: [PATCH 11/11] Add sig benchmark --- utils/crypto/bls/bls_benchmark_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go index 386965be22e9..65684c6e9b8c 100644 --- a/utils/crypto/bls/bls_benchmark_test.go +++ b/utils/crypto/bls/bls_benchmark_test.go @@ -137,3 +137,17 @@ func BenchmarkPublicKeyFromValidUncompressedBytes(b *testing.B) { _ = PublicKeyFromValidUncompressedBytes(pkBytes) } } + +func BenchmarkSignatureFromBytes(b *testing.B) { + privateKey, err := NewSecretKey() + require.NoError(b, err) + + message := utils.RandomBytes(32) + signature := Sign(privateKey, message) + signatureBytes := SignatureToBytes(signature) + + b.ResetTimer() + for range b.N { + _, _ = SignatureFromBytes(signatureBytes) + } +}