Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
fix() fix not and neg prices
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Feb 5, 2024
1 parent 0a99e3b commit f330a1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions fhevm/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions fhevm/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f330a1e

Please sign in to comment.