Skip to content

BigInteger JSON serialization should be string if their value is bigger than 2^53 #981

@AlexandreBossard

Description

@AlexandreBossard

BigInteger serialization does not respect the JSON specification when value is above 2^53

Expected Behavior

The serialized json value should be of type string, and not number, when value is above the 2^53.

Current Behavior

The value is serialized as number json, which is not guaranteed to be interoperable across json implementation. For example Hardhat refuses it.

Possible Solution

Declaring the C# type as string instead of BigInteger works, at least for Hardhat.

Steps to Reproduce

(coming soon)

Context (Environment)

.Net7 Core on linux + Hardhat 2.17.3 + Nethereum 4.17.1

Detailed Description

Using the EIP2612 Permit model and assigning the deadline field to the max uint256 value 115792089237316195423570985008687907853269984665640564039457584007913129639935 will make Hardhat's eth_signTypedData_v4 call assert.

Possible Implementation

I believe the bug is somewhere around:

private static List<JProperty> GetJProperties(string mainTypeName, MemberValue[] values, TypedDataRaw typedDataRaw)

It should not insert the BigInteger value as is, but check for maximum (and minimum) value and serialize it to string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions