# decode_legacy_tx allows validation of signatures with chain_id that are larger than felt, and overflows

decode_legacy_tx fails to bound chain_id data_len to <=31, so oversized chain_id overflows bytes_to_felt and passes signature validation.

- Payout: Audit contest
- Severity: medium
- Program: Kakarot
- Found by: Emmanuel
- Disclosed: 2024-12-10
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-09-kakarot-findings/issues/69
- Library page: https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AM-04
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:signature-replay

**Target:** Legacy transaction decoder (decode_legacy_tx / bytes_to_felt)
**Root cause:** bytes_to_felt shifts current by 256 per byte; with len>31 the value exceeds the 2^252 felt range and wraps, so an oversized chain_id decodes to a truncated value that still validates.
**Steps:**
1. Locate decode_legacy_tx reading chain_id from items[6].data via bytes_to_felt.
2. Note bytes_to_felt has no len<=31 constraint; loop does current = current*256 + byte.
3. Craft a legacy EIP-155 tx with chain_id data_len > 31 bytes.
4. bytes_to_felt overflows modulo felt prime, yielding a truncated chain_id.
5. Signature validation passes against the wrapped value.
**How found:** Code review of bytes_to_felt helper: noticed the loop multiplies by 256 per byte with no length bound, and that decode_legacy_tx does not constrain items[6].data_len, so len>31 overflows the felt.
**Insight:** In Cairo/felt arithmetic, any byte-to-felt decoder must bound input length to 31 bytes; audit every bytes_to_felt-style loop for missing len<=31 asserts, especially where the decoded value feeds signature validation.

