alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
786 stars 149 forks source link

fix(dyn-abi): enable `DynSolType.coerce_json` to convert array of numbers to bytes #541

Closed evchip closed 8 months ago

evchip commented 8 months ago

Motivation

In the course of implementing dynamic EIP-712 typed data signing on the alloy repo, I encountered an issue (see this comment) where bytes are being encoded as an array of numbers by TypedData::from_struct, causing an error when eip712_signing_hash() is called on the returned value: TypeMismatch { expected: "bytes", actual: "[102,105,122,122]" } .

@prestwich suggested the code (see comment) that is contained in this PR in order to resolve the issue.

Solution

add logic to the bytes() function used in DynSolType.coerce_json_simple() to handle case where the input value is an array of numbers instead of a string.

PR Checklist