Skip to content

Commit

Permalink
remove repeated use of environment.ComputationKindEVMEncodeABI
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored and m-Peter committed Dec 19, 2023
1 parent 78f8094 commit b01b1f3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions fvm/evm/stdlib/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func reportABIEncodingComputation(
inter *interpreter.Interpreter,
values *interpreter.ArrayValue,
evmAddressTypeID common.TypeID,
reportComputation func(compKind common.ComputationKind, intensity uint),
reportComputation func(intensity uint),
) {
values.Iterate(inter, func(element interpreter.Value) (resume bool) {
switch value := element.(type) {
Expand All @@ -119,7 +119,8 @@ func reportABIEncodingComputation(
stringLength := len(value.Str)
chunks := math.Ceil(float64(stringLength) / float64(abiEncodingByteSize))
computation += uint(chunks * abiEncodingByteSize)
reportComputation(environment.ComputationKindEVMEncodeABI, computation)
reportComputation(computation)

case interpreter.BoolValue,
interpreter.UInt8Value,
interpreter.UInt16Value,
Expand All @@ -133,14 +134,16 @@ func reportABIEncodingComputation(
interpreter.Int64Value,
interpreter.Int128Value,
interpreter.Int256Value:

// Numeric and bool variables are also static variables
// with a fixed size of 32 bytes.
reportComputation(environment.ComputationKindEVMEncodeABI, abiEncodingByteSize)
reportComputation(abiEncodingByteSize)

case *interpreter.CompositeValue:
if value.TypeID() == evmAddressTypeID {
// EVM addresses are static variables with a fixed
// size of 32 bytes.
reportComputation(environment.ComputationKindEVMEncodeABI, abiEncodingByteSize)
reportComputation(abiEncodingByteSize)
} else {
panic(abiEncodingError{
Type: value.StaticType(inter),
Expand All @@ -154,8 +157,9 @@ func reportABIEncodingComputation(
// array occupies, and the third chunk contains the
// values of the array itself.
computation := uint(2 * abiEncodingByteSize)
reportComputation(environment.ComputationKindEVMEncodeABI, computation)
reportComputation(computation)
reportABIEncodingComputation(inter, value, evmAddressTypeID, reportComputation)

default:
panic(abiEncodingError{
Type: element.StaticType(inter),
Expand Down Expand Up @@ -209,7 +213,9 @@ func newInternalEVMTypeEncodeABIFunction(
inter,
valuesArray,
evmAddressTypeID,
invocation.Interpreter.ReportComputation,
func(intensity uint) {
inter.ReportComputation(environment.ComputationKindEVMEncodeABI, intensity)
},
)

size := valuesArray.Count()
Expand Down

0 comments on commit b01b1f3

Please sign in to comment.