Skip to main content

Nethereum.AppChain.Contracts

NuGet: Nethereum.AppChain.Contracts | Source: src/Nethereum.AppChain.Contracts/

Nethereum.AppChain.Contracts

Solidity smart contracts for the Nethereum AppChain anchoring and messaging system. Built with Foundry.

Contracts​

Core​

ContractPurpose
AppChainAnchor.solAnchor registry — stores block anchors per AppChain with pluggable proof verification. AggregatedAnchor struct with 3 proof systems (NoProof, StarkHashOffChain, SnarkOnChain) and extensible registry.
AppChainHub.solPublic AppChain registry and messaging hub. Chain ID reservation (prevents squatting via registration fee), cross-chain messaging with authorized senders, anchor storage, message acknowledgment with Merkle root checkpoints. Optional — AppChains deploy their own AppChainAnchor independently; the Hub provides discovery, coordination, and a standardised messaging layer.
AppChainPolicy.solMembership and policy governance — Merkle-root membership management (writers/admins/blacklist), configurable policy parameters (calldata limits, log limits, gas limits, sequencer), and epoch-based tree rebuilding.
AppChainProofManager.solProof registry — records per-block proof submissions from authorized provers (direct or bond-requested), each checked against the anchor's minimum proof system.

Authority & Access Control​

ContractPurpose
SimpleAuthority.solAuthority contract with operator + per-chain authorized provers. Implements IAuthority. Supports operator validation, prover authorization/revocation, and ownership transfer.
IAuthority.solInterface for pluggable authority contracts.

Verification​

ContractPurpose
IVerifier.solStandard verifier interface: verify(bytes proof, uint256[] publicInputs) → bool. All verifiers implement this.
CalldataFormatVerifier.solValidates compressed block header calldata format (version byte + Brotli/Zlib envelope).
StarkBlobCommitmentVerifier.solValidates STARK proof hash with EIP-4844 blob commitment reference.
CalldataStarkVerifier.solCombined calldata + STARK hash verification.
PipelinePayloadVerifier.solValidates multi-section encoded pipeline payloads (headers + proofs + DA reference).
MockProofVerifier.solTest verifier that validates proof format without cryptography — returns false on malformed input (requires a 256-byte proof, at least 6 public inputs, non-zero commitment, non-zero chain identity, and correct batch block ordering). Does not verify the elliptic-curve pairing.
ZiskVerifierAdapter.solAdapter wrapping the ZisK zkVM SNARK verifier (IZiskVerifier) to the IVerifier interface. It accepts a proof only when the first eight Zisk public values (32-bit words, each held in a 64-bit public) hold keccak256(abi.encodePacked(publicInputs)); a proof of the guest's generic outputs does not carry that commitment and is rejected by the adapter (it still verifies through ZiskVerifier.verifySnarkProof).
IZiskVerifier.solZisK-specific SNARK verifier interface (verifySnarkProof(bytes32 programVK, bytes32 rootCVadcopFinal, bytes publicValues, bytes proofBytes)), the zkVM's native verifier bridged to IVerifier by ZiskVerifierAdapter.
ZiskVerifier.solZisk 1.3.1-alpha PLONK verifier (copied from Zisk's zisk-contracts): implements IZiskVerifier over PlonkVerifier. getRootCVadcopFinal() returns the root a leaf proof is wrapped under; verifySnarkProof reverts with InvalidProof on a bad proof. The generated C# service is Nethereum.AppChain.Anchoring.ZiskVerifier.ZiskVerifierService.
PlonkVerifier.solThe snarkJS-generated PLONK verifier for the Zisk final circuit that ZiskVerifier inherits.

Proof System Registry​

The AppChainAnchor contract maps proof system IDs to verifier contracts via registerProofSystem(uint8 id, address verifier, bool requiresProof):

IDEnum NameVerifierrequiresProofVerification
0NoProofaddress(0)falseTrust operator
1StarkHashOffChainoptionalfalseOff-chain STARK verification
2SnarkOnChainrequiredtrueFull on-chain SNARK verification via IVerifier.verify() (pluggable verifier; shipped: ZiskVerifierAdapter)

The registry is extensible — additional proof systems can be registered by the registry owner (registerProofSystem is onlyOwner). 7 C# submission strategies (DA × Proof mode combinations) map to these 3 on-chain proof system IDs.

See STRATEGY_VERIFIERS.md for the full strategy-to-verifier mapping.

Build​

forge build

Test​

forge test -vvv

C# Code Generation​

Generated Nethereum contract services live in:

  • src/Nethereum.AppChain.Anchoring/AppChainAnchor/ — AnchorService, definitions, extensions
  • src/Nethereum.AppChain.Anchoring/SimpleAuthority/
  • src/Nethereum.AppChain.Anchoring/AppChainProofManager/
  • src/Nethereum.AppChain.Anchoring/MockProofVerifier/
  • src/Nethereum.AppChain.Anchoring/ZiskVerifierAdapter/
  • src/Nethereum.AppChain.Anchoring/Hub/Contracts/AppChainHub/
  • src/Nethereum.AppChain.Policy/Contracts/AppChainPolicy/

Regenerate with:

Nethereum.Generator.Console generate from-config -cfg .nethereum-gen.multisettings

Security Model​

PREVIEW — Contracts are audited internally. External audit recommended before mainnet deployment.

AppChainAnchor:

  • Authority-gated anchor submission — each chain registers its own IAuthority contract (e.g. SimpleAuthority)
  • Proof system registry with requiresProof validation — verifier address required when proof is mandatory
  • One-way raiseMinimumProofSystem prevents downgrade attacks
  • MockProofVerifier provided for testing only — must not be registered on production chains

AppChainHub:

  • ReentrancyGuard on all ETH-transferring functions (registration, messaging, withdrawals)
  • EIP-2 compliant ECDSA signature verification (s-value check prevents malleability)
  • Pull-payment pattern using call{value} for all withdrawals and refunds
  • CEI (Checks-Effects-Interactions) ordering enforced — state updates before external calls
  • Per-chain authorized sender allowlist for message submission
  • Pluggable IProofVerifier per chain for anchor proof verification

AppChainPolicy:

  • Merkle-root based membership (writers, admins, blacklist)
  • Blacklist verification via proof in invite() — prevents re-adding banned addresses
  • Epoch-based tree rebuilding for membership rotation
  • Admin-gated policy parameter changes