Skip to content

Commit f92b26c

Browse files
committed
update gas usage for hooks
1 parent 14b1f29 commit f92b26c

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

vmhost/vmhooks/manBufOps.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ func (context *VMHooksImpl) MBufferFromBigIntSigned(mBufferHandle int32, bigIntH
567567
func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64 {
568568
managedType := context.GetManagedTypesContext()
569569
metering := context.GetMeteringContext()
570-
enableEpochsHandler := context.GetEnableEpochsHandler()
571570

572571
gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntUnsigned
573572
err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntUnsignedName, gasToUse)
@@ -582,13 +581,11 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64
582581
return 1
583582
}
584583

585-
if enableEpochsHandler.IsFlagEnabled(vmhost.BarnardOpcodesFlag) {
586-
gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(data)))
587-
err = metering.UseGasBounded(gasToUse)
588-
if err != nil {
589-
context.FailExecution(err)
590-
return 1
591-
}
584+
gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(data)))
585+
err = metering.UseGasBounded(gasToUse)
586+
if err != nil {
587+
context.FailExecution(err)
588+
return 1
592589
}
593590

594591
bigInt := big.NewInt(0).SetBytes(data)
@@ -604,7 +601,6 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64
604601
func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 {
605602
managedType := context.GetManagedTypesContext()
606603
metering := context.GetMeteringContext()
607-
enableEpochsHandler := context.GetEnableEpochsHandler()
608604

609605
gasToUse := metering.GasSchedule().ManagedBufferAPICost.MBufferToSmallIntSigned
610606
err := metering.UseGasBoundedAndAddTracedGas(mBufferToSmallIntSignedName, gasToUse)
@@ -619,13 +615,11 @@ func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 {
619615
return 1
620616
}
621617

622-
if enableEpochsHandler.IsFlagEnabled(vmhost.BarnardOpcodesFlag) {
623-
gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(data)))
624-
err = metering.UseGasBounded(gasToUse)
625-
if err != nil {
626-
context.FailExecution(err)
627-
return 1
628-
}
618+
gasToUse = math.MulUint64(metering.GasSchedule().BaseOperationCost.DataCopyPerByte, uint64(len(data)))
619+
err = metering.UseGasBounded(gasToUse)
620+
if err != nil {
621+
context.FailExecution(err)
622+
return 1
629623
}
630624

631625
bigInt := twos.SetBytes(big.NewInt(0), data)

vmhost/vmhookstest/manBuffers_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,6 @@ func TestManBuffers_Ints_WithNoBarnardOpcodesFlag(t *testing.T) {
365365
assert.Nil(t, err)
366366
assert.True(t, bigIntResult.Cmp(big.NewInt(0x00_ff_00_ff_00_ff_00_ff)) == 0)
367367

368-
smallInt := hooks.MBufferToSmallIntSigned(sourceBuffer)
369-
assert.True(t, smallInt == 0x00_ff_00_ff_00_ff_00_ff)
370-
371-
smallInt = hooks.MBufferToSmallIntUnsigned(sourceBuffer)
372-
assert.True(t, smallInt == 0x00_ff_00_ff_00_ff_00_ff)
373-
374368
return instance
375369
})
376370
})).
@@ -387,8 +381,8 @@ func TestManBuffers_Ints_WithNoBarnardOpcodesFlag(t *testing.T) {
387381
}).
388382
AndAssertResults(func(world *worldmock.MockWorld, verify *test.VMOutputVerifier) {
389383
verify.Ok().
390-
GasRemaining(gasProvided-37).
391-
GasUsed(test.ParentAddress, 37)
384+
GasRemaining(gasProvided-35).
385+
GasUsed(test.ParentAddress, 35)
392386
})
393387
assert.Nil(t, err)
394388
}

0 commit comments

Comments
 (0)