-
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
Delegatecall Behavioral Inconsistency with SHA256 Precompile #174
Comments
bytes032 marked the issue as primary issue |
141345 marked the issue as sufficient quality report |
High impact, low probablity ⇒ medium |
miladpiri (sponsor) confirmed |
The Warden has shown an inconsistency in the behaviour of sha256 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 |
This finding is valid and the behaviour is inconsistent, Medium Severity is appropriate |
GalloDaSballo marked the issue as duplicate of #175 |
GalloDaSballo marked the issue as not selected for report |
GalloDaSballo marked the issue as satisfactory |
Lines of code
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/SHA256.yul#L9
Vulnerability details
Impact
The behavioral discrepancy in zkSync Era when using
delegatecall
with the SHA256 precompile contract can have significant impacts:delegatecall
may not produce the expected results, affecting the integrity of data and contracts.Proof of Concept
It is observed that in the zkSync Era, there is a distinct inconsistency in the behavior of the SHA256 precompile contract (located at address 0x02) when accessed through a
delegatecall
. This behavior deviates from the standard Ethereum Virtual Machine (EVM) behavior, where the results acrosscall
,staticcall
, anddelegatecall
are consistent.https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/precompiles/SHA256.yul#L9
Within the zkSync Era, invoking the SHA256 precompile contract using a
delegatecall
takes a different path from the usual behavior. Instead of executing within the isolated context of the called contract, it delegates the call to the contract itself and runs its code within the caller's context. Consequently, the returned value is not in line with the expected outcome of aprecompileCall
. Instead, it consistently yieldsbytes32(0)
.For clarity, when executing the provided code below in the EVM, the returned
bytes32
value remains constant at0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925
for all three scenarios:sha256Staticcall
,sha256Call
, andsha256Delegatecall
. However, in the zkSync Era, whilesha256Staticcall
andsha256Call
deliver results consistent with the EVM,sha256Delegatecall
produces an inaccurate 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 thandelegatecall
.Tools Used
Recommended Mitigation Steps
It is advisable to substitute a
delegatecall
with astaticcall
whenever the target address for the operation is the SHA256 precompiled contract.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: