Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .agent/rules/solidity_zksync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Solidity & ZkSync Development Standards

## Toolchain & Environment
- **Primary Tool**: `forge` (ZkSync fork). Use for compilation, testing, and generic scripting.
- **Secondary Tool**: `hardhat`. Use only when `forge` encounters compatibility issues (e.g., complex deployments, specific plugin needs).
- **Network Target**: ZkSync Era (Layer 2).
- **Solidity Version**: `^0.8.20` (or `0.8.24` if strictly supported by the zk-compiler).

## Modern Solidity Best Practices
- **Safety First**:
- **Checks-Effects-Interactions (CEI)** pattern must be strictly followed.
- When a contract requires an owner (e.g., admin-configurable parameters), prefer `Ownable2Step` over `Ownable`. Do **not** add ownership to contracts that don't need it — many contracts are fully permissionless by design.
- Prefer `ReentrancyGuard` for external calls where appropriate.
- **Gas & Efficiency**:
- Use **Custom Errors** (`error MyError();`) instead of `require` strings.
- Use `mapping` over arrays for membership checks where possible.
- Minimize on-chain storage; use events for off-chain indexing.

## Testing Standards
- **Framework**: Foundry (Forge).
- **Methodology**:
- **Unit Tests**: Comprehensive coverage for all functions.
- **Fuzz Testing**: Required for arithmetic and purely functional logic.
- **Invariant Testing**: Define invariants for stateful system properties.
- **Naming Convention**:
- `test_Description`
- `testFuzz_Description`
- `test_RevertIf_Condition`

## ZkSync Specifics
- **System Contracts**: Be aware of ZkSync system contracts (e.g., `ContractDeployer`, `L2EthToken`) when interacting with low-level features.
- **Gas Model**: Account for ZkSync's different gas metering if performing low-level optimization.
- **Compiler Differences**: Be mindful of differences between `solc` and `zksolc` (e.g., `create2` address derivation).
11 changes: 10 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
"Frontends",
"testuser",
"testhandle",
"douglasacost"
"douglasacost",
"IBEACON",
"AABBCCDD",
"SSTORE",
"Permissionless",
"Reentrancy",
"SFID",
"EXTCODECOPY",
"solady",
"SLOAD"
]
}
33 changes: 33 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Solidity & ZkSync Development Standards

## Toolchain & Environment
- **Primary Tool**: `forge` (ZkSync fork). Use for compilation, testing, and generic scripting.
- **Secondary Tool**: `hardhat`. Use only when `forge` encounters compatibility issues (e.g., complex deployments, specific plugin needs).
- **Network Target**: ZkSync Era (Layer 2).
- **Solidity Version**: `^0.8.20` (or `0.8.24` if strictly supported by the zk-compiler).

## Modern Solidity Best Practices
- **Safety First**:
- **Checks-Effects-Interactions (CEI)** pattern must be strictly followed.
- Use `Ownable2Step` over `Ownable` for privileged access.
- Prefer `ReentrancyGuard` for external calls where appropriate.
- **Gas & Efficiency**:
- Use **Custom Errors** (`error MyError();`) instead of `require` strings.
- Use `mapping` over arrays for membership checks where possible.
- Minimize on-chain storage; use events for off-chain indexing.

## Testing Standards
- **Framework**: Foundry (Forge).
- **Methodology**:
- **Unit Tests**: Comprehensive coverage for all functions.
- **Fuzz Testing**: Required for arithmetic and purely functional logic.
- **Invariant Testing**: Define invariants for stateful system properties.
- **Naming Convention**:
- `test_Description`
- `testFuzz_Description`
- `test_RevertIf_Condition`

## ZkSync Specifics
- **System Contracts**: Be aware of ZkSync system contracts (e.g., `ContractDeployer`, `L2EthToken`) when interacting with low-level features.
- **Gas Model**: Account for ZkSync's different gas metering if performing low-level optimization.
- **Compiler Differences**: Be mindful of differences between `solc` and `zksolc` (e.g., `create2` address derivation).
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "lib/era-contracts"]
path = lib/era-contracts
url = https://github.com/matter-labs/era-contracts
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"editor.formatOnSave": true,
"[solidity]": {
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"chat.tools.terminal.autoApprove": {
"forge": true
}
}
20 changes: 20 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"lib/zksync-storage-proofs": {
"rev": "4b20401ce44c1ec966a29d893694f65db885304b"
},
"lib/openzeppelin-contracts": {
"rev": "e4f70216d759d8e6a64144a9e1f7bbeed78e7079"
},
"lib/solady": {
"tag": {
"name": "v0.1.26",
"rev": "acd959aa4bd04720d640bf4e6a5c71037510cc4b"
}
},
"lib/forge-std": {
"rev": "1eea5bae12ae557d589f9f0f0edae2faa47cb262"
},
"lib/era-contracts": {
"rev": "84d5e3716f645909e8144c7d50af9dd6dd9ded62"
}
}
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at acd959
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@openzeppelin=lib/openzeppelin-contracts/
@openzeppelin=lib/openzeppelin-contracts/
solady/=lib/solady/src/
Loading
Loading