From 9b3026d326e0efa6edab958e2b8a99e8eb43ccd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Wed, 10 Jan 2024 19:42:55 +0100 Subject: [PATCH] feat() add granularity on prices --- fhevm/params.go | 6 +++--- fhevm/precompiles.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/fhevm/params.go b/fhevm/params.go index 550bfc8..ebec909 100644 --- a/fhevm/params.go +++ b/fhevm/params.go @@ -139,9 +139,9 @@ func DefaultGasCosts() GasCosts { FheUint32: 189000, }, FheNegNot: map[FheUintType]uint64{ - FheUint8: 83000, - FheUint16: 108000, - FheUint32: 130000, + FheUint8: 30000, + FheUint16: 31000, + FheUint32: 32000, }, // TODO: Costs will depend on the complexity of doing reencryption/decryption by the oracle. FheReencrypt: map[FheUintType]uint64{ diff --git a/fhevm/precompiles.go b/fhevm/precompiles.go index 2d22f7a..3e77a4c 100644 --- a/fhevm/precompiles.go +++ b/fhevm/precompiles.go @@ -354,14 +354,15 @@ func fheMulRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheMul RequiredGas() operand type mismatch", "lhs", lhs.ciphertext.fheUintType, "rhs", rhs.ciphertext.fheUintType) return 0 } + return environment.FhevmParams().GasCosts.FheMul[lhs.ciphertext.fheUintType] } else { lhs, _, err = getScalarOperands(environment, input) if err != nil { logger.Error("fheMul RequiredGas() scalar inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 } + return environment.FhevmParams().GasCosts.FheScalarMul[lhs.ciphertext.fheUintType] } - return environment.FhevmParams().GasCosts.FheMul[lhs.ciphertext.fheUintType] } func fheLeRequiredGas(environment EVMEnvironment, input []byte) uint64 { @@ -435,14 +436,15 @@ func fheShlRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheShift RequiredGas() operand type mismatch", "lhs", lhs.ciphertext.fheUintType, "rhs", rhs.ciphertext.fheUintType) return 0 } + return environment.FhevmParams().GasCosts.FheShift[lhs.ciphertext.fheUintType] } else { lhs, _, err = getScalarOperands(environment, input) if err != nil { logger.Error("fheShift RequiredGas() scalar inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 } + return environment.FhevmParams().GasCosts.FheScalarShift[lhs.ciphertext.fheUintType] } - return environment.FhevmParams().GasCosts.FheShift[lhs.ciphertext.fheUintType] } func fheShrRequiredGas(environment EVMEnvironment, input []byte) uint64 { @@ -468,14 +470,15 @@ func fheMinRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheMin/Max RequiredGas() operand type mismatch", "lhs", lhs.ciphertext.fheUintType, "rhs", rhs.ciphertext.fheUintType) return 0 } + return environment.FhevmParams().GasCosts.FheMinMax[lhs.ciphertext.fheUintType] } else { lhs, _, err = getScalarOperands(environment, input) if err != nil { logger.Error("fheMin/Max RequiredGas() scalar inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 } + return environment.FhevmParams().GasCosts.FheScalarMinMax[lhs.ciphertext.fheUintType] } - return environment.FhevmParams().GasCosts.FheMinMax[lhs.ciphertext.fheUintType] } func fheMaxRequiredGas(environment EVMEnvironment, input []byte) uint64 { @@ -519,8 +522,8 @@ func fheDivRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheDiv RequiredGas() scalar inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 } + return environment.FhevmParams().GasCosts.FheScalarDiv[lhs.ciphertext.fheUintType] } - return environment.FhevmParams().GasCosts.FheDiv[lhs.ciphertext.fheUintType] } func fheRemRequiredGas(environment EVMEnvironment, input []byte) uint64 { @@ -540,8 +543,8 @@ func fheRemRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheRem RequiredGas() scalar inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 } + return environment.FhevmParams().GasCosts.FheScalarRem[lhs.ciphertext.fheUintType] } - return environment.FhevmParams().GasCosts.FheRem[lhs.ciphertext.fheUintType] } func fheBitAndRequiredGas(environment EVMEnvironment, input []byte) uint64 {