Skip to content

Commit

Permalink
Report computation for EVM.encodeABI & EVM.decodeABI methods
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Dec 13, 2023
1 parent c3585e6 commit 5b16ed6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions fvm/environment/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const (
ComputationKindRLPEncoding = 2038
ComputationKindRLPDecoding = 2039
ComputationKindEncodeEvent = 2040
_ = 2041
ComputationKindEVMEncodeABI = 2042
ComputationKindEVMDecodeABI = 2042
)

type Meter interface {
Expand Down
17 changes: 15 additions & 2 deletions fvm/evm/stdlib/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/stdlib"

"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/evm/types"
"github.com/onflow/flow-go/model/flow"
)
Expand Down Expand Up @@ -158,12 +159,19 @@ func newInternalEVMTypeEncodeABIFunction(
return true
})

encodedValues, err := arguments.Pack(values...)
hexData, err := arguments.Pack(values...)
if err != nil {
panic(abiEncodingError{})
}

return interpreter.ByteSliceToByteArrayValue(inter, encodedValues)
encodedValues := interpreter.ByteSliceToByteArrayValue(inter, hexData)

invocation.Interpreter.ReportComputation(
environment.ComputationKindEVMEncodeABI,
uint(encodedValues.Count()),
)

return encodedValues
},
)
}
Expand Down Expand Up @@ -526,6 +534,11 @@ func newInternalEVMTypeDecodeABIFunction(
panic(errors.NewUnreachableError())
}

invocation.Interpreter.ReportComputation(
environment.ComputationKindEVMDecodeABI,
uint(dataValue.Count()),
)

data, err := interpreter.ByteArrayValueToByteSlice(inter, dataValue, locationRange)
if err != nil {
panic(err)
Expand Down

0 comments on commit 5b16ed6

Please sign in to comment.