Contract verification¶
No explorer verification service yet
The PQWERAI explorer does not accept or display verified source code. Until it does, verification means anyone can rebuild your published source and get the exact bytes deployed on chain.
Procedure¶
- Publish the source, the exact compiler version (
0.8.26+commit.8a97fa7a), and all settings (optimizer runs,evmVersion,bytecode_hash/metadata, remappings, library versions). - Rebuild and compare the runtime code with
eth_getCode, copying only the immutable ranges the compiler reports.
verify.sh
# Verification = the on-chain runtime code equals the locally compiled runtime, byte for byte, except the
# ranges the compiler reserves for immutables (here `creator`), whose values are written at deployment.
# (The PQWERAI explorer has no source-verification service yet; this is the same check the Wallet Studio runs.)
cast code "$COUNTER" --rpc-url "$RPC" > onchain.hex
python3 - out/Counter.sol/Counter.json onchain.hex <<'PY'
import json, sys
art = json.load(open(sys.argv[1]))["deployedBytecode"]
local = bytearray.fromhex(art["object"][2:])
chain = bytearray.fromhex(open(sys.argv[2]).read().strip()[2:])
masked = 0
for refs in art.get("immutableReferences", {}).values():
for r in refs: # copy the deployed immutable value into the local image before comparing
local[r["start"]:r["start"] + r["length"]] = chain[r["start"]:r["start"] + r["length"]]
masked += r["length"]
if local == chain:
print(f"VERIFIED: {len(chain)} runtime bytes match ({masked} immutable bytes taken from chain)")
else:
sys.exit("MISMATCH: on-chain code differs from the compiled artifact")
PY
Tips¶
bytecode_hash = "none"(or--metadata-hash none) removes the CBOR metadata hash, whose value changes with comments and file paths. Without it you must publish the exact metadata JSON as well.- Vyper appends immutables to the end of runtime code; Huff/Yul have no immutables unless you write them.
- For libraries, the linked address is part of the bytes; publish it.
- The Windows Wallet Studio runs the same byte-for-byte check after every deployment.
Sources at 72057fe3ec: developers/examples/first-contract/verify.sh
Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec