How renegade-fi/renegade-solidity-contracts works
Project Type and Purpose
• Project Type: A blockchain‐protocol repository (“darkpool” settlement contracts) combining on‐chain Solidity code, off‐chain code generation (Rust), deployment scripts (bash/Cargo), and integration tests (Rust + Anvil).
• Purpose: Encapsulate Merklized exchange state, on‐chain PlonK verifier, settlement logic; provide tooling to generate ABIs, verification keys, Poseidon constants; enable local testing and deployment.
File Structure for Architectural Components
Top‐Level Directories:
• abi/ → Rust code generating contract ABIs and JSON artifacts
• codegen/ → Rust binaries generating zero‐values, Poseidon constants, verification keys
• src/ → Solidity contracts, libraries (darkpool, merkle, poseidon2, verifier), proxies
• lib/ → Git‐submodules of standard libs (OpenZeppelin, forge‐std, huff, solmate)
• script/ → Shell scripts for deployment, ABI updates, integration tests
• integration/ → Rust integration test suite that spins up an Anvil node, deploys contracts, and invokes them
• tools/ → Additional Rust CLI tools for deploying dummy tokens or orchestrating multi‐chain deployment
• test/ → Unit tests: Solidity (Forge), Huff tests, Rust reference implementations
README for Additional Insights
• Builds on Foundry (forge & anvil) and Rust/Cargo toolchains.
• Unit tests run via “forge test --ffi” (Solidity + FFI calls into Rust reference impls).
• Integration tests run via a shell script that starts an Anvil node, deploys contracts, and executes Rust tests.
• Deployment scripts prompt for configuration and use forge to deploy to any EVM chain.
Main System Components and Their Interactions
a. Developer Workstation
– Installs Foundry (forge & anvil) and Rust/Cargo.
– Runs codegen binaries (abi/, codegen/) to produce JSON ABIs, Poseidon parameters, PlonK vkeys.
b. Build & Deployment Pipeline
– Foundry compiles Solidity contracts in src/, linking libraries from lib/.
– script/bin/deploy.sh uses forge to push compiled bytecode to a live EVM via RPC.
– script/bin/deploy-token.sh and tools/* deploy ERC20 mocks.
c. On‐Chain Component (EVM Node)
– Hosts deployed smart contracts:
• Darkpool Settlement contract (state + matching logic)
• Merkle tree contract (state root updates)
• PlonK Verifier contract (proof validation on-chain)
– Interacts via JSON RPC with off‐chain clients and scripts.
d. Off‐Chain Test Harness & Clients
– Integration tests (Rust) spawn Anvil (local EVM), deploy contracts, then call into them via ethers‐rs.
– Rust reference implementations under test/rust‐reference‐impls mirror on‐chain logic for unit testing via FFI (forge unit tests).
e. Code Generation & Artifacts
– abi/ and codegen/ produce:
• Combined JSON ABIs (ICombined.json)
• Poseidon constants & zero‐hashes
• PlonK vkeys for on‐chain verifier
– Artifacts consumed both by Solidity (embedded via include_bytes! or loaded dynamically) and by off‐chain clients/tests.
Architectural Patterns & Design Principles
• Modular Libraries: reuse OpenZeppelin, solmate, huffers, solidity‐bn254 for critical cryptographic primitives.
• On‐chain/off‐chain separation: heavy crypto pre‐computation off‐chain (codegen) vs. minimal verification on‐chain.
• Test‐driven: unit tests in Solidity + Rust FFI, integration tests in Rust + local Anvil.
• Script orchestration: bash wrappers for reproducible builds, tests, and deployments.
Elements
– Clear labels: “ABI Generator”, “Poseidon Constants Generator”, “Solidity Compiler (Foundry)”, “Anvil/EVM Node”, “Integration Test Suite”, “Deployment Script”
• From codegen to build artifacts (ABIs, vkeys)
• From build to on‐chain deployment
• From tests to EVM node via JSON RPC
• Off‐chain Rust tools (blue rectangles)
• Shell scripts/commands (rounded yellow)