Submitted by anon, also found by anon and zkrunner
The discrepancy in delegatecall behavior with the ECRECOVER precompile contract in zkSync Era can have significant impact leading to incorrect signature validation, potentially compromising data integrity and user funds.
In the context of zkSync Era, there exists a noticeable inconsistency in how the ECRECOVER precompile contract (located at address 0x01) behaves when accessed via delegatecall. This behavior differs from the standard Ethereum Virtual Machine (EVM) behavior, where the outcomes remain uniform across call, staticcall, and delegatecall.
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/Ecrecover.yul#L7
In zkSync Era, when the ECRECOVER precompile contract is invoked using delegatecall, it diverges from the usual behavior by delegating the call to the contract itself and executing its code within the callers context. This results in a returned value that does not align with the anticipated outcome of a precompileCall. Instead, it yields bytes32(0).
To illustrate, in the following example, when executing the provided code in the EVM, the returned bytes32 value consistently appears as 0x000000000000000000000000759389e8e5c1aa1f511e9ea98b6caedd262bff0b for all three scenarios: ecrecoverStaticcall, ecrecoverCall, and ecrecoverDelegatecall. However, in the zkSync Era, while ecrecoverStaticcall and ecrecoverCall maintain the same results as in the EVM, ecrecoverDelegatecall produces an incorrect outcome:
This discrepancy is critical in its impact because it introduces a divergence from the expected EVM response. While the likelihood of encountering this issue is not high, as precompile contracts are typically invoked through staticcall rather than delegatecall.
The following revised code is recommended:
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/libraries/EfficientCall.sol#L88
Context
miladpiri (zkSync) confirmed and commented:
Alex the Entreprenerd (judge) commented:
Alex the Entreprenerd (judge) commented:
Note: for full discussion, see here.
