matter-labs / matter-labs/zksync-docs
Add information on the `isSystem` flag.
Nobody has claimed this yet.
- Dominant language
- Vue
- Stars
- 14
- Forks
- 93
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 3
Description
For reference, see this conversation here.
About
zkSync has a number of opcodes that are not supported in basic solidity or vyper syntax. The zkSync compiler is pretty good at knowing where to put specific zkSync opcodes depending on the solidity codebase.
However, there are times when it will be unsure. If isSystem is set to false, when it's unsure, it will not input the zkSync opcodes. When isSystem is set to true it will look for very specific call setups in the solidity opcodes and essentially hot swaps them out for the zkSync opcodes.
Example
For example, let's say zkSync supports an opcode called RESET which resets your wallet balance (idk why you'd want this, but ok). There is no Solidity syntax that would support such a call. If solidity supported this, the syntax might look like such:
assembly {
reset(my_address)
}
And would generate opcodes that might look like this:
PUSH0
RESET
PUSH1 0x01
However, the RESET opcodes doesn't exist in the EVM. So instead, what we do, is we setup a simulated call. This is when we abuse specific We instead say "Whenever we see a string of opcodes that looks like PUSH32 0xFFFE PUSH32 7 CALL swap that out for the RESET opcode.
PUSH0
- PUSH32 0xFFFE
- PUSH32 7
- CALL
+ RESET
PUSH1 0x01
In solidity, we use the syntax of System Contracts to make it easier to generate this set of assembly, so your solidity might look something like this:
SystemContractsCaller.systemCallWithPropagatedRevert(
uint32(gasleft()),
address(RESET_SYSTEM_CONTRACT_ADDRESS),
0,
abi.encodeCall(IResetContract.reset, ())
);
Using System Contracts
When we pass the isSystem=true flag to the compiler, it will "hot swap" out all the "simulated called" with their real zkSync opcodes. If isSystem=false is passed, then the contract will not chance the underlying opcodes, and try to make the regular calls as instructed.
Security concerns
There is a chance that the generated opcodes have a collision. For example, maybe you want to run PUSH32 0xFFFE PUSH32 7 CALL and not RESET, this is something developers MUST be aware of when working with system contracts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked System Contracts documentation, especially the NonceHolder section, and read the referenced Ethereum Stack Exchange conversation for context. Add an explanation of how isSystem=true and isSystem=false affect simulated system-contract calls, including the opcode-collision security concern, then verify the guidance is clear to Solidity developers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100