1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-27 10:22:34 +00:00

feat(core/ethereum): remove EIP-712 field size limitation of 1024 bytes

This commit is contained in:
grdddj 2023-01-13 11:18:39 +01:00 committed by Jiří Musil
parent 72ef41664f
commit c068c668fa
3 changed files with 9 additions and 15 deletions

View File

@ -0,0 +1 @@
Ethereum's EIP-712 signing no longer restricts the maximum field size to 1024 bytes.

View File

@ -1,4 +1,3 @@
from micropython import const
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from trezor.enums import EthereumDataType from trezor.enums import EthereumDataType
@ -21,10 +20,6 @@ if TYPE_CHECKING:
) )
# Maximum data size we support
_MAX_VALUE_BYTE_SIZE = const(1024)
@with_keychain_from_path(*PATTERNS_ADDRESS) @with_keychain_from_path(*PATTERNS_ADDRESS)
async def sign_typed_data( async def sign_typed_data(
ctx: Context, msg: EthereumSignTypedData, keychain: Keychain ctx: Context, msg: EthereumSignTypedData, keychain: Keychain
@ -426,14 +421,12 @@ def _validate_value(field: EthereumFieldType, value: bytes) -> None:
Raise DataError if encountering a problem, so clients are notified. Raise DataError if encountering a problem, so clients are notified.
""" """
# Checking if the size corresponds to what is defined in types, # Checking if the size corresponds to what is defined in types.
# and also setting our maximum supported size in bytes # Not having any maximum field size - it is a responsibility of the client
if field.size is not None: # (and message creator) to make sure the data is not too large to cause problems
if len(value) != field.size: # on the Trezor side.
if field.size is not None and len(value) != field.size:
raise DataError("Invalid length") raise DataError("Invalid length")
else:
if len(value) > _MAX_VALUE_BYTE_SIZE:
raise DataError(f"Invalid length, bigger than {_MAX_VALUE_BYTE_SIZE}")
# Specific tests for some data types # Specific tests for some data types
if field.data_type == EthereumDataType.BOOL: if field.data_type == EthereumDataType.BOOL:

View File

@ -582,8 +582,8 @@ class TestEthereumSignTypedData(unittest.TestCase):
), ),
( (
EFT(data_type=EDT.STRING, size=None), EFT(data_type=EDT.STRING, size=None),
[b"\x7f", b"a" * 1024], [b"\x7f"],
[b"\x80", b"a" * 1025], [b"\x80"],
), ),
( (
EFT(data_type=EDT.ADDRESS, size=None), EFT(data_type=EDT.ADDRESS, size=None),