CREATE opcode works differently in the zkSync chain
The protocol's createEdition function uses a clone helper that relies on the CREATE opcode, which behaves differently on zkSync Era and cannot deploy arbitrary bytecode. As a result, no editions can be created on zkSync Era, and since the function is payable, users may lose the creation fee.
ArsenLupin Follow with Kalogerone and me_na0mi
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-titles-judging/issues/91
The protocol has acknowledged this issue.
Found by
ArsenLupin, Kalogerone, me_na0mi
Summary
zkSync Era chain has differences in the usage of the create opcode compared to the EVM.
Vulnerability Detail
According to the contest README, the protocol can be deployed in zkSync Era (README)
The zkSync Era docs explain how it differs from Ethereum.
The description of CREATE and CREATE2 (zkSynce Era Docs) states that Create cannot be used for arbitrary code unknown to the compiler.
TitlesCore::createEdition function uses Solady's LibClone::clone function:
function createEdition(bytes calldata payload_, address referrer_) external payable returns (Edition edition) {
EditionPayload memory payload = abi.decode(payload_.cdDecompress(), (EditionPayload));
@> edition = Edition(editionImplementation.clone());
// wake-disable-next-line reentrancy
edition.initialize(
feeManager, graph, payload.work.creator.target, address(this), payload.metadata
);
// wake-disable-next-line unchecked-return-value
_publish(edition, payload.work, referrer_);
emit EditionCreated(
address(edition),
payload.work.creator.target,
payload.work.maxSupply,
payload.work.strategy,
abi.encode(payload.metadata)
);
}
function clone(uint256 value, address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x21, 0x5af43d3d93803e602a57fd5bf3)
mstore(0x14, implementation)
mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
@> instance := create(value, 0x0c, 0x35)
if iszero(instance) {
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
revert(0x1c, 0x04)
}
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
}
}
As mentioned by the zkSync docs: "The code will not function correctly because the compiler is not aware of the bytecode beforehand".
This will result in loss of funds, since there is a fee to create a new edition, hence the TitlesCore::createEdition function is payable.
Impact
No editions can be created in the zkSync Era chain.
Code Snippet
https://github.com/sherlock-audit/2024-04-titles/blob/d7f60952df22da00b772db5d3a8272a988546089/wallflower-contract-v2/src/TitlesCore.sol#L79 https://github.com/Vectorized/solady/blob/91d5f64b39a4d20a3ce1b5e985103b8ea4dc1cfc/src/utils/LibClone.sol#L137
Tool used
Manual Review
Recommendation
This can be solved by implementing CREATE2 directly and using type(Edition).creationCode as mentioned in the zkSync Era docs.
Discussion
midori-fuse
Escalate
This escalation raises two points:
The first point is that #353 and #440 are duplicates of this issue.
The second point is that this issue has been excluded without reasoning (nor do I see any signs of someone reviewing this issue), even though evidence has been provided, and the impacts have been shown:
- The relevant part of the zkEVM docs has been linked within the report.
- The contract is bricked for this issue, which fits into the "rendering the contract useless" in the medium severity criteria.
- The contest README includes zkSync as a deployment chain.
For this reason I believe this issue (and the mentioned duplicates) to be a valid medium.
sherlock-admin3
Escalate
This escalation raises two points:
The first point is that #353 and #440 are duplicates of this issue.
The second point is that this issue has been excluded without reasoning (nor do I see any signs of someone reviewing this issue), even though evidence has been provided, and the impacts have been shown:
- The relevant part of the zkEVM docs has been linked within the report.
- The contract is bricked for this issue, which fits into the "rendering the contract useless" in the medium severity criteria.
- The contest README includes zkSync as a deployment chain.
For this reason I believe this issue (and the mentioned duplicates) to be a valid medium.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
cvetanovv
I disagree with the escalation. This issue is invalid.
You can see Sherlock documentation subclause 24. EVM opcodes type of issue is not valid.
midori-fuse
The clause states:
Using Solidity versions that support EVM opcodes that don't work on networks on which the protocol is deployed is not a valid issue because one can manage compilation flags to compile for past EVM versions on newer Solidity versions.
This is not an issue of "Using solidity versions", because all solidity versions support the CREATE opcode, and this issue will manifest no matter what Solidity version you use, or what EVM you compile it on. The clause clearly states that the rule only applies to using Solidity versions such that it is mitigatable by managing compilation flags, it does not apply to all "EVM opcodes type" in general.
Any issue also boils down to just "EVM opcode", because when you compile any Solidity source files, you always get EVM opcodes, the majority (if not, most of the time, all) of which you cannot manage compilation flags to the behavior you desire.
Kalogerone
I agree with @midori-fuse. Subclause 24 doesn't refer to these kind of issues. This issue is not about the solidity version used. Subclause 24 clearly covers the solution which cannot be applied here:
because one can manage compilation flags to compile for past EVM versions on newer Solidity versions.
cvetanovv
@midori-fuse and @Kalogerone, I agree with the comments and will consult with @WangSecurity about whether it is a valid issue.
Hash01011122
Agreed with @midori-fuse on
The clause clearly states that the rule only applies to using Solidity versions such that it is mitigatable by managing compilation flags, it does not apply to all "EVM opcodes type" in general.
But still this appears to be low. I will let head of judge decide severity of this issue.
Kalogerone
I would argue it is not a low because as I mentioned in my report, the function used to create a new contract is payable and the user has to pay a fee to do that. Zksync docs never mention that the function will fail/revert, meaning that the user’s funds are not safe and there is possible loss of funds.
The following code will not function correctly because the compiler is not aware of the bytecode beforehand
Unfortunately, it's impossible to differentiate between the above cases during compile-time. As a result, we strongly recommend including tests for any factory that deploys child contracts using type(T).creationCode.
WangSecurity
I agree with the escalation and that it should be a valid medium, rather than the high. Planning to accept the escalation and validate as medium with duplicates #353 and #440.
Evert0x
Result: Medium Has Duplicates
sherlock-admin4
Escalations have been resolved successfully!
Escalation status:
- midori-fuse: accepted
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the use of a clone helper that relies on the CREATE opcode with runtime-generated bytecode, which is unsupported on zkSync Era.
Impact
No editions can be created on zkSync Era, and because the function is payable, users could lose the creation fee.
What the attacker needed
Protocol deployed on zkSync Era; user calls createEdition with a fee
The fix
The issue should be fixed by implementing CREATE2 directly and using type(Edition).creationCode as recommended in the zkSync Era documentation.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
On Ethereum, a contract can create new contracts using a low-level instruction called CREATE. On zkSync Era, a different layer-2 network, that instruction only works if the compiler already knows the exact code of the new contract. Here, the code is built at runtime, so the creation fails, and any fee paid is lost.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.