Skip to content

Commit 366bf2b

Browse files
committed
update gas usage for hooks
1 parent 46d7893 commit 366bf2b

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

config/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
BigFloatAbs = 10
154154
BigFloatSqrt = 10
155155
BigFloatPow = 10
156+
BigFloatPowPerIteration = 10
156157
BigFloatFloor = 10
157158
BigFloatCeil = 10
158159
BigFloatIsInt = 10

config/gasCost.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,25 @@ type BigIntAPICost struct {
157157

158158
// BigFloatAPICost defines the big float operations gas cost config structure
159159
type BigFloatAPICost struct {
160-
BigFloatNewFromParts uint64
161-
BigFloatAdd uint64
162-
BigFloatSub uint64
163-
BigFloatMul uint64
164-
BigFloatDiv uint64
165-
BigFloatTruncate uint64
166-
BigFloatNeg uint64
167-
BigFloatClone uint64
168-
BigFloatCmp uint64
169-
BigFloatAbs uint64
170-
BigFloatSqrt uint64
171-
BigFloatPow uint64
172-
BigFloatFloor uint64
173-
BigFloatCeil uint64
174-
BigFloatIsInt uint64
175-
BigFloatSetBigInt uint64
176-
BigFloatSetInt64 uint64
177-
BigFloatGetConst uint64
160+
BigFloatNewFromParts uint64
161+
BigFloatAdd uint64
162+
BigFloatSub uint64
163+
BigFloatMul uint64
164+
BigFloatDiv uint64
165+
BigFloatTruncate uint64
166+
BigFloatNeg uint64
167+
BigFloatClone uint64
168+
BigFloatCmp uint64
169+
BigFloatAbs uint64
170+
BigFloatSqrt uint64
171+
BigFloatPow uint64
172+
BigFloatPowPerIteration uint64
173+
BigFloatFloor uint64
174+
BigFloatCeil uint64
175+
BigFloatIsInt uint64
176+
BigFloatSetBigInt uint64
177+
BigFloatSetInt64 uint64
178+
BigFloatGetConst uint64
178179
}
179180

180181
// CryptoAPICost defines the crypto operations gas cost config structure

config/gasSchedule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ func FillGasMapBigFloatAPICosts(value uint64) map[string]uint64 {
431431
gasMap["BigFloatAbs"] = value
432432
gasMap["BigFloatSqrt"] = value
433433
gasMap["BigFloatPow"] = value
434+
gasMap["BigFloatPowPerIteration"] = value
434435
gasMap["BigFloatFloor"] = value
435436
gasMap["BigFloatCeil"] = value
436437
gasMap["BigFloatIsInt"] = value

scenario/gasSchedules/gasScheduleEmbedGenerated.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scenario/gasSchedules/gasScheduleV3.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
BigFloatAbs = 5000
210210
BigFloatSqrt = 7000
211211
BigFloatPow = 10000
212+
BigFloatPowPerIteration = 10000
212213
BigFloatFloor = 5000
213214
BigFloatCeil = 5000
214215
BigFloatIsInt = 3000

scenario/gasSchedules/gasScheduleV4.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
BigFloatAbs = 5000
212212
BigFloatSqrt = 7000
213213
BigFloatPow = 10000
214+
BigFloatPowPerIteration = 10000
214215
BigFloatFloor = 5000
215216
BigFloatCeil = 5000
216217
BigFloatIsInt = 3000

vmhost/vmhooks/bigFloatOps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,13 @@ func (context *VMHooksImpl) BigFloatPow(destinationHandle, opHandle, exponent in
481481
managedType := context.GetManagedTypesContext()
482482
metering := context.GetMeteringContext()
483483
metering.StartGasTracing(bigFloatPowName)
484+
enableEpochsHandler := context.GetEnableEpochsHandler()
484485

485486
gasToUse := metering.GasSchedule().BigFloatAPICost.BigFloatPow
487+
if enableEpochsHandler.IsFlagEnabled(vmhost.BarnardOpcodesFlag) {
488+
gasToUse += vmMath.MulUint64(metering.GasSchedule().BigFloatAPICost.BigFloatPowPerIteration, uint64(exponent))
489+
}
490+
486491
err := metering.UseGasBounded(gasToUse)
487492
if err != nil {
488493
context.FailExecution(err)

0 commit comments

Comments
 (0)