Skip to content

Invalid TypedData encoding with specific int/uint sizes (e.g. int24) #25932

@valdikamenarov

Description

@valdikamenarov

System information

Geth version: 1.10.25
OS & Version: Ubuntu 20.04.5 LTS

Description

Typed Data providing int/uint types that differ from the primitive golang types are not supported while being valid Solidity types.

According to EIP-712 atomic types of type int/uint can be a size ranging between 8 - 256 bits

Expected behaviour

Should be able to successfully encode typed data with valid int/uint types between 8 - 256.

Actual behaviour

Encoding fails due to unknown primitive type.

Steps to reproduce the behaviour

package main

import (
	"github.com/ethereum/go-ethereum/common/math"
	"github.com/ethersphere/bee/pkg/crypto/eip712"
)

func main() {
	typedData := eip712.TypedData{
		Domain: eip712.TypedDataDomain{
			Name:    "ABC",
			Version: "0.0.1",
			ChainId: math.NewHexOrDecimal256(1),
		},
		Types: eip712.Types{
			"EIP712Domain": {
				{Name: "name", Type: "string"},
				{Name: "version", Type: "string"},
				{Name: "chainId", Type: "uint256"},
				{Name: "verifyingContract", Type: "address"},
			},
			"MainType": {
				{Name: "number1", Type: "int160"}, // missing valid Solidity type.
				{Name: "number2", Type: "int24"},  // missing valid Solidity type.
			},
		},
		PrimaryType: "MainType",
		Message: eip712.TypedDataMessage{
			"number1": "13",
			"number2": "13",
		},
	}

	_, err := typedData.HashStruct("EIP712Domain", typedData.Domain.Map())
	if err != nil {
		panic(err)
	}
	_, err = typedData.HashStruct(typedData.PrimaryType, typedData.Message)
	if err != nil {
		panic(err)
	}
}

Error

unknown type "int160"
unknown type "int24"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions