|
1 | 1 | --- |
2 | 2 | rskip: 552 |
3 | | -title: Title |
| 3 | +title: Improve Blake2F Input Validation |
4 | 4 | created: 16-MAR-26 |
5 | 5 | author: FML (@fmacleal) |
6 | | -purpose: Sca,Usa,Fair,Sec or ST |
7 | | -layer: Core |
| 6 | +purpose: Sec |
| 7 | +layer: Core |
8 | 8 | complexity: 1 |
9 | | -status: Draft,Accepted,Adopted,Deferred or Rejected |
10 | | -description: |
| 9 | +status: Draft |
| 10 | +description: Add null-safety checks to Blake2F precompiled contract input handling |
11 | 11 | --- |
12 | 12 |
|
13 | | -|RSKIP | 552 | |
14 | | -| :------------ |:--------------------------------------------| |
15 | | -|**Title** | Title | |
16 | | -|**Created** | 16-MAR-26 | |
17 | | -|**Author** | FML | |
18 | | -|**Purpose** | Sca,Usa,Fair,Sec or ST | |
19 | | -|**Layer** | Core | |
20 | | -|**Complexity** | 1 | |
21 | | -|**Status** | Draft,Accepted,Adopted,Deferred or Rejected | |
| 13 | +# Improve Blake2F Input Validation |
| 14 | + |
| 15 | +|RSKIP | 552 | |
| 16 | +| :------------ |:---------------------------------------------| |
| 17 | +|**Title** | Improve Blake2F Input Validation | |
| 18 | +|**Created** | 16-MAR-26 | |
| 19 | +|**Author** | FML | |
| 20 | +|**Purpose** | Sec | |
| 21 | +|**Layer** | Core | |
| 22 | +|**Complexity** | 1 | |
| 23 | +|**Status** | Draft | |
22 | 24 |
|
23 | 25 | ## Abstract |
24 | 26 |
|
25 | | -To be completed... |
| 27 | +This RSKIP improves the input validation of the Blake2F precompiled contract (address `0x0000000000000000000000000000000000000009`) introduced by [RSKIP-153](https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP153.md). The change ensures that the Blake2F precompile handles all possible calldata states correctly, including edge cases not covered by the original implementation. Additionally, the exception handling in the precompile execution path within the EVM is improved to increase robustness. |
26 | 28 |
|
27 | 29 | ## Motivation |
28 | 30 |
|
29 | | -To be completed... |
| 31 | +The Blake2F precompiled contract, enabled via RSKIP-153, expects calldata of exactly 213 bytes. The precompile validates the input length before proceeding. However, the current implementation does not handle all possible calldata edge cases consistently. |
| 32 | + |
| 33 | +To ensure the Blake2F precompile handles all possible input states consistently and deterministically, explicit validation should be added for edge cases not covered by the original implementation. This aligns the precompile with defensive programming best practices and strengthens the overall robustness of the consensus execution path. |
30 | 34 |
|
31 | 35 | ## Specification |
32 | 36 |
|
33 | | -To be completed... |
| 37 | +This RSKIP introduces the following changes, activated conditionally via a new consensus rule (`RSKIP552`): |
| 38 | + |
| 39 | +### 1. Improved input validation in gas calculation |
| 40 | + |
| 41 | +When `RSKIP552` is active, the gas calculation logic for the Blake2F precompile handles all possible input states, including edge-case calldata. Invalid inputs return zero gas, consistent with the existing behavior for malformed input of incorrect length. |
| 42 | + |
| 43 | +### 2. Improved input validation in execution |
34 | 44 |
|
35 | | -### Subsection 1 of Specification such as format. |
| 45 | +When `RSKIP552` is active, the execution logic for the Blake2F precompile handles all possible input states. Edge-case calldata is rejected with the existing error for incorrect input length, consistent with how other malformed inputs are handled. |
36 | 46 |
|
37 | | -To be completed... |
| 47 | +### 3. Improved exception handling in precompile execution |
| 48 | + |
| 49 | +The exception handling in the EVM's precompile execution path is improved to ensure that all error conditions during precompile execution are properly caught and handled, resulting in the call returning zero to the caller. |
| 50 | + |
| 51 | +## Backward Compatibility |
| 52 | + |
| 53 | +This change is activated via a consensus rule (`RSKIP552`) and will take effect at a specific network upgrade block height. Before activation, the behavior of the Blake2F precompile remains unchanged. After activation, the only behavioral difference is that transactions targeting the Blake2F precompile with edge-case calldata will be handled consistently with other malformed-input scenarios. |
38 | 54 |
|
39 | 55 | ## Rationale |
40 | 56 |
|
41 | | -Discuss design decisions, community debates and possible attacks. |
| 57 | +Precompiled contracts should handle all possible input states gracefully, following the principle of defensive input validation. This change ensures that the Blake2F precompile behaves consistently and deterministically regardless of how the calling transaction is encoded. |
42 | 58 |
|
43 | 59 | ## References |
44 | 60 |
|
45 | | -[1] Other RSKIP https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP??.md |
| 61 | +[1] [RSKIP-153 - Add BLAKE2 Compression Function F Precompile](https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP153.md) |
| 62 | + |
| 63 | +[2] [EIP-152 - BLAKE2b F Compression Function](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md) |
46 | 64 |
|
47 | 65 | ### Copyright |
48 | 66 |
|
49 | | -Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
| 67 | +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
0 commit comments