Skip to content
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

Add information on the isSystem flag. #1036

Open
PatrickAlphaC opened this issue Apr 30, 2024 · 0 comments
Open

Add information on the isSystem flag. #1036

PatrickAlphaC opened this issue Apr 30, 2024 · 0 comments

Comments

@PatrickAlphaC
Copy link
Contributor

PatrickAlphaC commented Apr 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant