ABI-Struct Mapping
Converting EVM input data to Go structures
ABI-Struct Mapping is the technique used in Maroo precompiles to transform raw or generic EVM input arguments into strongly-typed Go structs. This is achieved by marshaling the input arguments to JSON and then unmarshaling them into a target struct, leveraging Go's json struct tags to map field names.
Why JSON Intermediate?
Directly mapping
[]interface{} from the ABI unpacker to a specific struct can be brittle and requires manual type assertions for every field. Using JSON as an intermediate layer allows developers to use standard struct tags (json:"fieldName") to define the mapping declarative, reducing boilerplate code.Performance Considerations
While convenient, this double-serialization (Marshal -> Unmarshal) incurs a CPU cost. For extremely high-frequency precompiles (like basic math operations), manual type assertion is preferred. However, for complex business logic (like PCL or Identity), the overhead is negligible compared to the logic execution time.