Merge PR #2046: auth: Make gas cost take into account cryptosystem
* auth: Make gas cost take into account cryptosystem This will make including the multisig easier. The ratio for ed25519 vs secp256k1 are based on the ratio of their verification times, using the benchmarks in tendermint/crypto.
This commit is contained in:
parent
011e61a8de
commit
419cf85433
|
@ -20,7 +20,6 @@ BREAKING CHANGES
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FEATURES
|
FEATURES
|
||||||
|
|
||||||
* Gaia REST API (`gaiacli advanced rest-server`)
|
* Gaia REST API (`gaiacli advanced rest-server`)
|
||||||
|
@ -42,7 +41,8 @@ IMPROVEMENTS
|
||||||
* Gaia CLI (`gaiacli`)
|
* Gaia CLI (`gaiacli`)
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
* [x/stake] [#2023](https://github.com/cosmos/cosmos-sdk/pull/2023) Terminate iteration loop in `UpdateBondedValidators` and `UpdateBondedValidatorsFull` when the first revoked validator is encountered and perform a sanity check.
|
* [x/stake] [#2023](https://github.com/cosmos/cosmos-sdk/pull/2023) Terminate iteration loop in `UpdateBondedValidators` and `UpdateBondedValidatorsFull` when the first revoked validator is encountered and perform a sanity check.
|
||||||
|
* [x/auth] Signature verification's gas cost now accounts for pubkey type. [#2046](https://github.com/tendermint/tendermint/pull/2046)
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
|
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
|
||||||
|
|
|
@ -5,13 +5,17 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
deductFeesCost sdk.Gas = 10
|
deductFeesCost sdk.Gas = 10
|
||||||
memoCostPerByte sdk.Gas = 1
|
memoCostPerByte sdk.Gas = 1
|
||||||
verifyCost = 100
|
ed25519VerifyCost = 59
|
||||||
maxMemoCharacters = 100
|
secp256k1VerifyCost = 100
|
||||||
|
maxMemoCharacters = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewAnteHandler returns an AnteHandler that checks
|
// NewAnteHandler returns an AnteHandler that checks
|
||||||
|
@ -187,7 +191,7 @@ func processSig(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check sig.
|
// Check sig.
|
||||||
ctx.GasMeter().ConsumeGas(verifyCost, "ante verify")
|
consumeSignatureVerificationGas(ctx.GasMeter(), pubKey)
|
||||||
if !pubKey.VerifyBytes(signBytes, sig.Signature) {
|
if !pubKey.VerifyBytes(signBytes, sig.Signature) {
|
||||||
return nil, sdk.ErrUnauthorized("signature verification failed").Result()
|
return nil, sdk.ErrUnauthorized("signature verification failed").Result()
|
||||||
}
|
}
|
||||||
|
@ -195,6 +199,17 @@ func processSig(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func consumeSignatureVerificationGas(meter sdk.GasMeter, pubkey crypto.PubKey) {
|
||||||
|
switch pubkey.(type) {
|
||||||
|
case ed25519.PubKeyEd25519:
|
||||||
|
meter.ConsumeGas(ed25519VerifyCost, "ante verify: ed25519")
|
||||||
|
case secp256k1.PubKeySecp256k1:
|
||||||
|
meter.ConsumeGas(secp256k1VerifyCost, "ante verify: secp256k1")
|
||||||
|
default:
|
||||||
|
panic("Unrecognized signature type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Deduct the fee from the account.
|
// Deduct the fee from the account.
|
||||||
// We could use the CoinKeeper (in addition to the AccountMapper,
|
// We could use the CoinKeeper (in addition to the AccountMapper,
|
||||||
// because the CoinKeeper doesn't give us accounts), but it seems easier to do this.
|
// because the CoinKeeper doesn't give us accounts), but it seems easier to do this.
|
||||||
|
|
Loading…
Reference in New Issue