Replace per-candidate Anvil+forge-script pipeline with in-process EVM
execution using Foundry's native revm backend, achieving 10-100× speedup
for evolutionary search at scale.
New files:
- onchain/test/FitnessEvaluator.t.sol — Forge test that forks Base once,
deploys the full KRAIKEN stack, then for each candidate uses vm.etch to
inject the compiled optimizer bytecode, UUPS-upgrades the proxy, runs all
attack sequences with in-memory vm.snapshot/revertTo (no RPC overhead),
and emits one {"candidate_id","fitness"} JSON line per candidate.
Skips gracefully when BASE_RPC_URL is unset (CI-safe).
- tools/push3-evolution/revm-evaluator/batch-eval.sh — Wrapper that
transpiles+compiles each candidate sequentially, writes a two-file
manifest (ids.txt + bytecodes.txt), then invokes FitnessEvaluator.t.sol
in a single forge test run and parses the score JSON from stdout.
Modified:
- tools/push3-evolution/evolve.sh — Adds EVAL_MODE env var (anvil|revm).
When EVAL_MODE=revm, batch-scores every candidate in a generation with
one batch-eval.sh call instead of N sequential fitness.sh processes;
scores are looked up from the JSONL output in the per-candidate loop.
Default remains EVAL_MODE=anvil for backward compatibility.
Key design decisions:
- Per-candidate Solidity compilation is unavoidable (each Push3 candidate
produces different Solidity); the speedup is in the evaluation phase.
- vm.snapshot/revertTo in forge test are O(1) memory operations (true
revm), not RPC calls — this is the core speedup vs Anvil.
- recenterAccess is set in bootstrap so TWAP stability checks are bypassed
during attack sequences (mirrors the existing fitness.sh bootstrap).
- Test skips cleanly when BASE_RPC_URL is absent, keeping CI green.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| .claude | ||
| .github/workflows | ||
| .husky | ||
| analysis | ||
| lib | ||
| script | ||
| src | ||
| test | ||
| .claude-code-supervisor.yml | ||
| .gas-snapshot | ||
| .gitignore | ||
| .lintstagedrc.json | ||
| .secret.local | ||
| .solhint.json | ||
| .solhintignore | ||
| AGENTS.md | ||
| deployments-local.json | ||
| foundry.toml | ||
| hAIrberger.md | ||
| lcov.info | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| remappings.txt | ||
| UNISWAP_V3_MATH.md | ||
KRAIKEN Onchain
Solidity contracts for the KRAIKEN protocol. Built with Foundry.
Contracts
| Contract | Description |
|---|---|
Kraiken.sol |
ERC20 token with mint/burn controlled by LiquidityManager. VERSION=2. |
LiquidityManager.sol |
Three-position Uniswap V3 strategy (Anchor, Discovery, Floor). |
Stake.sol |
Harberger-tax staking with snatching auctions and discrete tax brackets. |
OptimizerV3.sol |
UUPS upgradeable. Binary bear/bull parameter selection from staking sentiment. |
VWAPTracker.sol |
Volume-weighted average price with directional recording and compression. |
Setup
git submodule update --init --recursive
cd lib/uni-v3-lib && npm install && cd ../..
forge build
forge test
Deploy
source .env
forge script script/BaseSepoliaDeploy.sol:BaseSepoliaDeploy --slow --broadcast --verify --rpc-url ${BASE_SEPOLIA_RPC_URL}
See docs/DEPLOYMENT_RUNBOOK.md for production deployment.
Deployments
Base Mainnet
| Contract | Address |
|---|---|
| Kraiken | 0x45caa5929f6ee038039984205bdecf968b954820 |
| Stake | 0xed70707fab05d973ad41eae8d17e2bcd36192cfc |
| LiquidityManager | 0x7fd4e645ce258dd3942eddbeb2f99137da8ba13b |
Base Sepolia
| Contract | Address |
|---|---|
| Kraiken | 0x22c264Ecf8D4E49D1E3CabD8DD39b7C4Ab51C1B8 |
| Stake | 0xe28020BCdEeAf2779dd47c670A8eFC2973316EE2 |
| LiquidityManager | 0x3d6a8797693a0bC598210782B6a889E11A2340Cd |
Research & Analysis
The analysis/ directory contains fuzzing scripts, parameter sweep tools, and security analysis:
- SECURITY_REVIEW.md — Security analysis and vulnerability assessment
- KRAIKEN_RESEARCH_REPORT.md — Comprehensive research report
- README.md — Analysis tool usage guide
Key findings: critical sqrt price bug fixed, 1050-combo 4D parameter sweep completed, floor ratchet vulnerability identified. See the research report for details.
ABI Architecture
Contract ABIs flow through the stack via kraiken-lib/src/abis.ts, which imports directly from out/ (forge build artifacts). Run forge build to update ABIs across all consumers (ponder, web-app).
References
- AGENTS.md — Agent guide for onchain development
- UNISWAP_V3_MATH.md — Uniswap V3 math reference
- hAIrberger.md — Dynamic LP strategy design document