@@ -450,6 +450,7 @@ func (context *VMHooksImpl) MBufferAppendBytes(accumulatorHandle int32, dataOffs
450450func (context * VMHooksImpl ) MBufferToBigIntUnsigned (mBufferHandle int32 , bigIntHandle int32 ) int32 {
451451 managedType := context .GetManagedTypesContext ()
452452 metering := context .GetMeteringContext ()
453+ enableEpochsHandler := context .GetEnableEpochsHandler ()
453454
454455 gasToUse := metering .GasSchedule ().ManagedBufferAPICost .MBufferToBigIntUnsigned
455456 err := metering .UseGasBoundedAndAddTracedGas (mBufferToBigIntUnsignedName , gasToUse )
@@ -464,6 +465,15 @@ func (context *VMHooksImpl) MBufferToBigIntUnsigned(mBufferHandle int32, bigIntH
464465 return 1
465466 }
466467
468+ if enableEpochsHandler .IsFlagEnabled (vmhost .BarnardOpcodesFlag ) {
469+ gasToUse = math .MulUint64 (metering .GasSchedule ().BaseOperationCost .DataCopyPerByte , uint64 (len (managedBuffer )))
470+ err = metering .UseGasBounded (gasToUse )
471+ if err != nil {
472+ context .FailExecution (err )
473+ return 1
474+ }
475+ }
476+
467477 bigInt := managedType .GetBigIntOrCreate (bigIntHandle )
468478 bigInt .SetBytes (managedBuffer )
469479
@@ -475,6 +485,7 @@ func (context *VMHooksImpl) MBufferToBigIntUnsigned(mBufferHandle int32, bigIntH
475485func (context * VMHooksImpl ) MBufferToBigIntSigned (mBufferHandle int32 , bigIntHandle int32 ) int32 {
476486 managedType := context .GetManagedTypesContext ()
477487 metering := context .GetMeteringContext ()
488+ enableEpochsHandler := context .GetEnableEpochsHandler ()
478489
479490 gasToUse := metering .GasSchedule ().ManagedBufferAPICost .MBufferToBigIntSigned
480491 err := metering .UseGasBoundedAndAddTracedGas (mBufferToBigIntSignedName , gasToUse )
@@ -489,6 +500,15 @@ func (context *VMHooksImpl) MBufferToBigIntSigned(mBufferHandle int32, bigIntHan
489500 return 1
490501 }
491502
503+ if enableEpochsHandler .IsFlagEnabled (vmhost .BarnardOpcodesFlag ) {
504+ gasToUse = math .MulUint64 (metering .GasSchedule ().BaseOperationCost .DataCopyPerByte , uint64 (len (managedBuffer )))
505+ err = metering .UseGasBounded (gasToUse )
506+ if err != nil {
507+ context .FailExecution (err )
508+ return 1
509+ }
510+ }
511+
492512 bigInt := managedType .GetBigIntOrCreate (bigIntHandle )
493513 twos .SetBytes (bigInt , managedBuffer )
494514
@@ -560,6 +580,14 @@ func (context *VMHooksImpl) MBufferToSmallIntUnsigned(mBufferHandle int32) int64
560580 context .FailExecution (err )
561581 return 1
562582 }
583+
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
589+ }
590+
563591 bigInt := big .NewInt (0 ).SetBytes (data )
564592 if ! bigInt .IsUint64 () {
565593 context .FailExecution (vmhost .ErrBytesExceedUint64 )
@@ -586,6 +614,14 @@ func (context *VMHooksImpl) MBufferToSmallIntSigned(mBufferHandle int32) int64 {
586614 context .FailExecution (err )
587615 return 1
588616 }
617+
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
623+ }
624+
589625 bigInt := twos .SetBytes (big .NewInt (0 ), data )
590626 if ! bigInt .IsInt64 () {
591627 context .FailExecution (vmhost .ErrBytesExceedInt64 )
0 commit comments