diff --git a/fhevm/params.go b/fhevm/params.go index 5180cbe..068f20a 100644 --- a/fhevm/params.go +++ b/fhevm/params.go @@ -61,11 +61,14 @@ type GasCosts struct { FheDecrypt map[FheUintType]uint64 FheBitwiseOp map[FheUintType]uint64 FheMul map[FheUintType]uint64 - FheDiv map[FheUintType]uint64 - FheRem map[FheUintType]uint64 + FheScalarMul map[FheUintType]uint64 + FheScalarDiv map[FheUintType]uint64 + FheScalarRem map[FheUintType]uint64 FheShift map[FheUintType]uint64 + FheScalarShift map[FheUintType]uint64 FheLe map[FheUintType]uint64 FheMinMax map[FheUintType]uint64 + FheScalarMinMax map[FheUintType]uint64 FheNegNot map[FheUintType]uint64 FheReencrypt map[FheUintType]uint64 FheTrivialEncrypt map[FheUintType]uint64 @@ -79,9 +82,9 @@ type GasCosts struct { func DefaultGasCosts() GasCosts { return GasCosts{ FheAddSub: map[FheUintType]uint64{ - FheUint8: 83000, - FheUint16: 108000, - FheUint32: 130000, + FheUint8: 108000, + FheUint16: 138000, + FheUint32: 169000, }, FheDecrypt: map[FheUintType]uint64{ FheUint8: 500000, @@ -89,44 +92,59 @@ func DefaultGasCosts() GasCosts { FheUint32: 500000, }, FheBitwiseOp: map[FheUintType]uint64{ - FheUint8: 20000, - FheUint16: 21000, - FheUint32: 22000, + FheUint8: 30000, + FheUint16: 31000, + FheUint32: 32000, }, FheMul: map[FheUintType]uint64{ - FheUint8: 150000, - FheUint16: 200000, - FheUint32: 270000, + FheUint8: 185000, + FheUint16: 252000, + FheUint32: 361000, + }, + FheScalarMul: map[FheUintType]uint64{ + FheUint8: 128000, + FheUint16: 132000, + FheUint32: 168000, }, - FheDiv: map[FheUintType]uint64{ - FheUint8: 1370000, - FheUint16: 3500000, - FheUint32: 9120000, + FheScalarDiv: map[FheUintType]uint64{ + FheUint8: 200000, + FheUint16: 400000, + FheUint32: 800000, }, - FheRem: map[FheUintType]uint64{ - FheUint8: 1370000, // TODO: check again rem gas - FheUint16: 3500000, - FheUint32: 9120000, + FheScalarRem: map[FheUintType]uint64{ + FheUint8: 200000, + FheUint16: 400000, + FheUint32: 800000, }, FheShift: map[FheUintType]uint64{ - FheUint8: 105000, - FheUint16: 128000, - FheUint32: 160000, + FheUint8: 218000, + FheUint16: 273000, + FheUint32: 335000, + }, + FheScalarShift: map[FheUintType]uint64{ + FheUint8: 135000, + FheUint16: 161000, + FheUint32: 188000, }, FheLe: map[FheUintType]uint64{ - FheUint8: 61000, - FheUint16: 83000, - FheUint32: 109000, + FheUint8: 50000, + FheUint16: 53000, + FheUint32: 56000, }, FheMinMax: map[FheUintType]uint64{ - FheUint8: 108000, - FheUint16: 134000, - FheUint32: 150000, + FheUint8: 215000, + FheUint16: 272000, + FheUint32: 332000, + }, + FheScalarMinMax: map[FheUintType]uint64{ + FheUint8: 131000, + FheUint16: 159000, + 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{ @@ -152,9 +170,9 @@ func DefaultGasCosts() GasCosts { FheUint32: EvmNetSstoreInitGas + 400000, }, FheIfThenElse: map[FheUintType]uint64{ - FheUint8: 61000, - FheUint16: 83000, - FheUint32: 109000, + FheUint8: 55000, + FheUint16: 60000, + FheUint32: 65000, }, // TODO: As of now, only support FheUint8. All optimistic require predicates are // downcast to FheUint8 at the solidity level. Eventually move to ebool. 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 {