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

Commit

Permalink
feat() add granularity on prices
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Jan 10, 2024
1 parent b5f12bb commit 9b3026d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions fhevm/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 8 additions & 5 deletions fhevm/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 9b3026d

Please sign in to comment.