-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong Result When EcAdd Precompile Contract is Called in Delegatecall #25
Comments
bytes032 marked the issue as low quality report |
GalloDaSballo marked the issue as selected for report |
Similarly with other repots, the Warden has shown an inconsistent behaviour of a precompile, when using |
@miladpiri just pinging in case this was missed |
miladpiri (sponsor) confirmed |
GalloDaSballo marked the issue as unsatisfactory: |
Lines of code
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/EcAdd.yul#L5
Vulnerability details
Impact
The observed inconsistency in the behavior of the EcAdd precompile contract when accessed via delegatecall introduces unpredictability within the zkSync Era environment. This inconsistency may affect the reliability and expected functionality of contracts using this precompile.
Proof of Concept
Within the zkSync Era environment, an inconsistency emerges regarding the behavior of the EcAdd precompile contract, found at address 0x06, when accessed through a
delegatecall
. This behavior diverges from the standard Ethereum Virtual Machine (EVM) operation, where the outcomes are consistent acrosscall
,staticcall
, anddelegatecall
methods.https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/EcAdd.yul#L5
In the zkSync Era, when the EcAdd precompile contract is invoked using
delegatecall
, it deviates from the typical behavior. Instead of performing as a precompile contract, it delegates the call to the body of the contract itself and executes its code within the caller's context. Consequently, the returned value does not align with the expected outcome of aprecompileCall
.To illustrate this discrepancy, consider the following example. In the Ethereum Virtual Machine, when executing the provided code, the returned struct
G1Point
value consistently appears as follows:for all three scenarios:
ecAddStaticcall
,ecAddCall
, andecAddDelegatecall
. However, in the zkSync Era, whileecAddStaticcall
andecAddCall
produce the same results as in the EVM,ecAddDelegatecall
yields an incorrect outcome.This discrepancy is of particular significance because it deviates from the expected EVM response. While the likelihood of encountering this issue is not high, as precompile contracts are typically invoked through
staticcall
rather thandelegatecall
, it remains a point of concern within the zkSync Era environment.Tools Used
Recommended Mitigation Steps
The following revised code is recommended:
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/libraries/EfficientCall.sol#L88
Assessed type
Context
The text was updated successfully, but these errors were encountered: