From f330a1ec8ab88a3f0ef3483fd0cf1008a47d1e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Mon, 5 Feb 2024 17:13:41 +0100 Subject: [PATCH] fix() fix not and neg prices --- fhevm/params.go | 11 +++++++++-- fhevm/precompiles.go | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/fhevm/params.go b/fhevm/params.go index 2634810..af9bdc5 100644 --- a/fhevm/params.go +++ b/fhevm/params.go @@ -70,7 +70,8 @@ type GasCosts struct { FheLe map[FheUintType]uint64 FheMinMax map[FheUintType]uint64 FheScalarMinMax map[FheUintType]uint64 - FheNegNot map[FheUintType]uint64 + FheNot map[FheUintType]uint64 + FheNeg map[FheUintType]uint64 FheReencrypt map[FheUintType]uint64 FheTrivialEncrypt map[FheUintType]uint64 FheRand map[FheUintType]uint64 @@ -154,7 +155,13 @@ func DefaultGasCosts() GasCosts { FheUint32: 154000 + AdjustFHEGas, FheUint64: 182000 + AdjustFHEGas, }, - FheNegNot: map[FheUintType]uint64{ + FheNot: map[FheUintType]uint64{ + FheUint8: 25000 + AdjustFHEGas, + FheUint16: 25000 + AdjustFHEGas, + FheUint32: 26000 + AdjustFHEGas, + FheUint64: 27000 + AdjustFHEGas, + }, + FheNeg: map[FheUintType]uint64{ FheUint8: 79000 + AdjustFHEGas, FheUint16: 114000 + AdjustFHEGas, FheUint32: 150000 + AdjustFHEGas, diff --git a/fhevm/precompiles.go b/fhevm/precompiles.go index fcc9a50..4012881 100644 --- a/fhevm/precompiles.go +++ b/fhevm/precompiles.go @@ -497,12 +497,22 @@ func fheNegRequiredGas(environment EVMEnvironment, input []byte) uint64 { logger.Error("fheNeg input not verified", "input", hex.EncodeToString(input)) return 0 } - return environment.FhevmParams().GasCosts.FheNegNot[ct.ciphertext.fheUintType] + return environment.FhevmParams().GasCosts.FheNeg[ct.ciphertext.fheUintType] } func fheNotRequiredGas(environment EVMEnvironment, input []byte) uint64 { // Implement in terms of neg, because costs are currently the same. - return fheNegRequiredGas(environment, input) + logger := environment.GetLogger() + if len(input) != 32 { + logger.Error("fheNot input needs to contain one 256-bit sized value", "input", hex.EncodeToString(input)) + return 0 + } + ct := getVerifiedCiphertext(environment, common.BytesToHash(input[0:32])) + if ct == nil { + logger.Error("fheNot input not verified", "input", hex.EncodeToString(input)) + return 0 + } + return environment.FhevmParams().GasCosts.FheNot[ct.ciphertext.fheUintType] } func fheDivRequiredGas(environment EVMEnvironment, input []byte) uint64 {