-
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
EcMul Precompile Contract Behaves Differently when Using Delegatecall #426
Comments
141345 marked the issue as sufficient quality report |
High Impact (as result is false), low probablity (usually static call is used). There is no proof that anyone need this behaviour. Medium is fair. |
miladpiri (sponsor) confirmed |
The Warden has shown an inconsistency in the behaviour of EcMul when using Because the goal of the zkSync EVM is to be the EVM compatible, Medium Severity seems appropriate |
GalloDaSballo marked the issue as selected for report |
GalloDaSballo marked the issue as unsatisfactory: |
Lines of code
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/EcMul.yul#L5
Vulnerability details
Impact
The behavior of the EcMul precompile contract in zkSync Era, when accessed through
delegatecall
, deviates from the expected Ethereum Virtual Machine (EVM) behavior.Proof of Concept
In the context of zkSync Era, an inconsistency has surfaced in the behavior of the EcMul precompile contract, which is located at address 0x07, when it is accessed through a
delegatecall
. This behavior differs from the standard behavior observed within the Ethereum Virtual Machine (EVM), where results remain consistent regardless of whether you usecall
,staticcall
, ordelegatecall
methods.https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/EcMul.yul#L5
In zkSync Era, when the EcMul precompile contract is invoked using a
delegatecall
, it behaves like a normal delegate call in which the code is executed within the context of the caller. As a consequence, the value returned from this operation does not align with the expected result of aprecompileCall
.To illustrate this inconsistency, consider the following example: In the Ethereum Virtual Machine, running the provided code consistently produces a struct
G1Point
with the following values:This consistent behavior is observed for all three scenarios:
ecMulStaticcall
,ecMulCall
, andecMulDelegatecall
. However, in the zkSync Era, whileecMulStaticcall
andecMulCall
exhibit the same results as in the EVM,ecMulDelegatecall
produces an incorrect outcome, which is zero.This discrepancy carries significance because it deviates from the expected behavior within the Ethereum Virtual Machine. It is worth noting that the likelihood of encountering this issue is not high in practice, as precompile contracts are typically invoked using
staticcall
rather thandelegatecall
. Nevertheless, this finding is noteworthy as it highlights an inconsistency that should be addressed and understood 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: