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

Commit

Permalink
feat() adjust gas with 64bits
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Feb 5, 2024
1 parent c115801 commit 0a99e3b
Showing 1 changed file with 56 additions and 39 deletions.
95 changes: 56 additions & 39 deletions fhevm/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package fhevm
// Base gas costs of existing EVM operations. Used for setting gas costs relative to them.
// These constants are used just for readability.
const EvmNetSstoreInitGas uint64 = 20000
const AdjustFHEGas uint64 = 10000
const ColdSloadCostEIP2929 uint64 = 2100

var (
Expand Down Expand Up @@ -82,69 +83,82 @@ type GasCosts struct {
func DefaultGasCosts() GasCosts {
return GasCosts{
FheAddSub: map[FheUintType]uint64{
FheUint8: 120000,
FheUint16: 150000,
FheUint32: 180000,
FheUint8: 84000 + AdjustFHEGas,
FheUint16: 123000 + AdjustFHEGas,
FheUint32: 152000 + AdjustFHEGas,
FheUint64: 178000 + AdjustFHEGas,
},
FheDecrypt: map[FheUintType]uint64{
FheUint8: 500000,
FheUint16: 500000,
FheUint32: 500000,
FheUint64: 500000,
},
FheBitwiseOp: map[FheUintType]uint64{
FheUint8: 30000,
FheUint16: 33000,
FheUint32: 36000,
FheUint8: 24000 + AdjustFHEGas,
FheUint16: 24000 + AdjustFHEGas,
FheUint32: 25000 + AdjustFHEGas,
FheUint64: 28000 + AdjustFHEGas,
},
FheMul: map[FheUintType]uint64{
FheUint8: 200000,
FheUint16: 260000,
FheUint32: 380000,
FheUint8: 187000 + AdjustFHEGas,
FheUint16: 252000 + AdjustFHEGas,
FheUint32: 349000 + AdjustFHEGas,
FheUint64: 631000 + AdjustFHEGas,
},
FheScalarMul: map[FheUintType]uint64{
FheUint8: 135000,
FheUint16: 140000,
FheUint32: 170000,
FheUint8: 149000 + AdjustFHEGas,
FheUint16: 198000 + AdjustFHEGas,
FheUint32: 254000 + AdjustFHEGas,
FheUint64: 346000 + AdjustFHEGas,
},
FheScalarDiv: map[FheUintType]uint64{
FheUint8: 450000,
FheUint16: 500000,
FheUint32: 550000,
FheUint8: 228000 + AdjustFHEGas,
FheUint16: 304000 + AdjustFHEGas,
FheUint32: 388000 + AdjustFHEGas,
FheUint64: 574000 + AdjustFHEGas,
},
FheScalarRem: map[FheUintType]uint64{
FheUint8: 450000,
FheUint16: 500000,
FheUint32: 550000,
FheUint8: 450000 + AdjustFHEGas,
FheUint16: 612000 + AdjustFHEGas,
FheUint32: 795000 + AdjustFHEGas,
FheUint64: 1095000 + AdjustFHEGas,
},
FheShift: map[FheUintType]uint64{
FheUint8: 150000,
FheUint16: 180000,
FheUint32: 210000,
FheUint8: 123000 + AdjustFHEGas,
FheUint16: 143000 + AdjustFHEGas,
FheUint32: 173000 + AdjustFHEGas,
FheUint64: 217000 + AdjustFHEGas,
},
FheScalarShift: map[FheUintType]uint64{
FheUint8: 32000,
FheUint16: 32000,
FheUint32: 32000,
FheUint8: 25000 + AdjustFHEGas,
FheUint16: 25000 + AdjustFHEGas,
FheUint32: 25000 + AdjustFHEGas,
FheUint64: 28000 + AdjustFHEGas,
},
FheLe: map[FheUintType]uint64{
FheUint8: 56000,
FheUint16: 67000,
FheUint32: 89000,
FheUint8: 46000 + AdjustFHEGas,
FheUint16: 46000 + AdjustFHEGas,
FheUint32: 72000 + AdjustFHEGas,
FheUint64: 76000 + AdjustFHEGas,
},
FheMinMax: map[FheUintType]uint64{
FheUint8: 220000,
FheUint16: 280000,
FheUint32: 340000,
FheUint8: 94000 + AdjustFHEGas,
FheUint16: 120000 + AdjustFHEGas,
FheUint32: 148000 + AdjustFHEGas,
FheUint64: 189000 + AdjustFHEGas,
},
FheScalarMinMax: map[FheUintType]uint64{
FheUint8: 140000,
FheUint16: 165000,
FheUint32: 190000,
FheUint8: 114000 + AdjustFHEGas,
FheUint16: 140000 + AdjustFHEGas,
FheUint32: 154000 + AdjustFHEGas,
FheUint64: 182000 + AdjustFHEGas,
},
FheNegNot: map[FheUintType]uint64{
FheUint8: 29000,
FheUint16: 31000,
FheUint32: 33000,
FheUint8: 79000 + AdjustFHEGas,
FheUint16: 114000 + AdjustFHEGas,
FheUint32: 150000 + AdjustFHEGas,
FheUint64: 189000 + AdjustFHEGas,
},
// TODO: Costs will depend on the complexity of doing reencryption/decryption by the oracle.
FheReencrypt: map[FheUintType]uint64{
Expand All @@ -157,11 +171,13 @@ func DefaultGasCosts() GasCosts {
FheUint8: 200,
FheUint16: 300,
FheUint32: 400,
FheUint64: 800,
},
FheTrivialEncrypt: map[FheUintType]uint64{
FheUint8: 100,
FheUint16: 200,
FheUint32: 300,
FheUint64: 600,
},
// TODO: These will change once we have an FHE-based random generaration.
FheRand: map[FheUintType]uint64{
Expand All @@ -171,9 +187,10 @@ func DefaultGasCosts() GasCosts {
FheUint64: EvmNetSstoreInitGas + 100000,
},
FheIfThenElse: map[FheUintType]uint64{
FheUint8: 60000,
FheUint16: 65000,
FheUint32: 70000,
FheUint8: 37000 + AdjustFHEGas,
FheUint16: 37000 + AdjustFHEGas,
FheUint32: 40000 + AdjustFHEGas,
FheUint64: 43000 + AdjustFHEGas,
},
// TODO: As of now, only support FheUint8. All optimistic require predicates are
// downcast to FheUint8 at the solidity level. Eventually move to ebool.
Expand Down

0 comments on commit 0a99e3b

Please sign in to comment.