You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+53-1Lines changed: 53 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
12
12
-**Safety First**:
13
13
-**Checks-Effects-Interactions (CEI)** pattern must be strictly followed.
14
-
-Use `Ownable2Step` over `Ownable` for privileged access.
14
+
-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.
15
15
- Prefer `ReentrancyGuard` for external calls where appropriate.
16
16
-**Gas & Efficiency**:
17
17
- Use **Custom Errors** (`error MyError();`) instead of `require` strings.
forge test --match-path test/SwarmRegistryL1.t.sol
50
50
```
51
+
52
+
## ZkSync Source Code Verification
53
+
54
+
**IMPORTANT**: Do NOT use `forge script --verify` or `forge verify-contract` directly for ZkSync contracts. Both fail to achieve full verification due to path handling issues with the ZkSync block explorer verifier.
2.`forge verify-contract` (standard JSON) sends OpenZeppelin sources containing `../` relative imports → verifier rejects "import with absolute or traversal path".
60
+
3.`forge verify-contract --flatten` or manual flattening eliminates imports but changes the source file path in the metadata hash → **"partially verified"** (metadata mismatch).
61
+
62
+
### The Solution
63
+
64
+
Use `ops/verify_zksync_contracts.py` which:
65
+
66
+
1. Generates standard JSON via `forge verify-contract --show-standard-json-input`
67
+
2. Rewrites all `../` relative imports in OpenZeppelin source content to resolved project-absolute paths (e.g., `../../utils/Foo.sol` → `lib/openzeppelin-contracts/contracts/utils/Foo.sol`)
68
+
3. Submits directly to the ZkSync verification API via HTTP
69
+
70
+
### Full vs Partial Verification
71
+
72
+
-**`bytecode_hash = "none"`** is set in `foundry.toml` (both `[profile.default]` and `[profile.zksync]`). This omits the CBOR metadata hash from bytecode. Contracts deployed with this setting achieve **full verification**.
73
+
- Contracts deployed **before** this setting was added (pre 2026-04-10) will always show "partially verified" — this is cosmetic only. The source code is correct and auditable.
74
+
75
+
### Usage
76
+
77
+
```bash
78
+
# After deployment — verify all contracts from broadcast:
When deploying a new contract type, add its mapping to `CONTRACT_SOURCE_MAP` in `ops/verify_zksync_contracts.py` so `--broadcast` mode can auto-detect it.
99
+
100
+
### Automated (via deploy script)
101
+
102
+
`ops/deploy_swarm_contracts_zksync.sh` calls `verify_zksync_contracts.py` automatically after deployment. No manual steps needed for the standard swarm contracts.
0 commit comments