import { CanonicalSurface } from '../components/CanonicalSurface'

# Getting Started

This guide sets up Verity for two workflows:

1. **Existing Solidity (fastest start):** import a selected Solidity function into Lean and prove a property about it — see [Import a Solidity function](/solidity-import).
2. **Author in Verity:** write a contract directly in `verity_contract`, prove its specification and compile to EVM artifacts — see [Your First Contract](/first-contract#minimal-skeleton).

<CanonicalSurface>
Have existing Solidity? You only need Git, Python 3, `elan` and the pinned importer `solc` — start with [Import a Solidity function](/solidity-import). Continue below for the full native-authoring and Foundry test setup.
</CanonicalSurface>

## Prerequisites

| Tool | Purpose | Required for |
|------|---------|-------------|
| [elan](https://github.com/leanprover/elan) | Lean toolchain manager | All Lean proofs and Solidity imports |
| Python 3.8+ | Setup and repo scripts | Installing pinned importer `solc`, scaffold generator, CI scripts |
| [Foundry](https://book.getfoundry.sh/getting-started/installation) | Solidity/EVM test runner | Differential and Foundry property tests |
| [`solc`](https://docs.soliditylang.org/en/latest/installing-solidity.html) 0.8.33+ | System Solidity compiler | Native compiler differential tests (separate from `solidity_import`) |

> **Pinned `solc` for `solidity_import` vs system `solc`:** The automatic Solidity importer uses its own checksum-verified binaries under `.lake/solidity-import/` (installed via `python3 scripts/setup_solc_import.py --version 0.8.34`, or `--all` to also fetch `0.8.38`, `0.8.35`, `0.8.28`, `0.8.26`, `0.8.10` and `0.7.6` on Linux/macOS x86-64). For Foundry differential tests on native Verity contracts, install a system `solc` 0.8.33+ separately (for example via [`solc-select`](https://github.com/crytic/solc-select) or `brew install solidity`).

## 1. Install Lean 4

[elan](https://github.com/leanprover/elan) manages Lean toolchains (like `rustup` for Rust). The project pins its toolchain in `lean-toolchain`.

```bash
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
```

Follow the prompts, then **reload your shell**:

```bash
source ~/.elan/env    # or open a new terminal
lean --version        # should print leanprover/lean4:v4.31.0 (or whatever lean-toolchain pins)
```

> **Tip**: If `source ~/.elan/env` does not work, check `~/.profile` or `~/.bashrc` for the elan path entry.

## 2. Install Foundry

[Foundry](https://book.getfoundry.sh/) provides `forge` for compiling and testing Solidity contracts. The project uses it for property-based differential tests.

```bash
curl -L https://foundry.paradigm.xyz | bash
foundryup
forge --version
```

## 3. Clone and build

First clone the repository:

```bash
git clone https://github.com/lfglabs-dev/verity.git
cd verity
```

If you only want to import and prove properties of an existing Solidity function, install the pinned importer `solc` and build just the importer target:

```bash
python3 scripts/setup_solc_import.py --version 0.8.34
lake build Compiler.SolidityImport.Import
```

Then follow [Import a Solidity function](/solidity-import).

To build every example contract, compiler pass and proof in the repository (for native `verity_contract` authoring and Foundry tests):

```bash
lake build                # Downloads dependencies and verifies the current proof set
```

The first full `lake build` downloads Mathlib and compiles everything; expect **20–45 minutes** on first run (Mathlib is large). Subsequent builds are incremental and much faster (seconds to minutes).

## Explore a proof

Once the build completes, the core loop is **write a contract in Lean → prove it correct → compile it to EVM bytecode**:

```bash
lake build Contracts.SimpleStorage.Proofs.Basic    # verifies theorems in seconds
lake exe verity-compiler                            # writes artifacts/yul/SimpleStorage.yul
```

Three directories to keep in mind:

1. `Contracts/<Name>/<Name>.lean`, EDSL implementation, executable Lean code.
2. `Contracts/<Name>/Spec.lean`, `Invariants.lean`, `Proofs/`, logical specs (`Prop`) and proofs.
3. `Contracts/Specs.lean`, `CompilationModel` values that generate IR/Yul.

## 4. Run the test suite

```bash
# All tests (property tests deploy Yul via vm.ffi, so FFI is required)
FOUNDRY_PROFILE=difftest forge test

# Unit tests only (no FFI needed)
forge test --no-match-path "test/Property*" --no-match-path "test/Differential*" --no-match-path "test/CallValue*" --no-match-path "test/CalldataSize*" --no-match-path "test/yul/*"
```

The `difftest` profile enables `vm.ffi()` calls needed by property tests (to invoke `solc` for Yul compilation), differential tests (to invoke the Lean-based interpreter), and Yul end-to-end tests. This requires `lake build` to have completed successfully.

## 5. Generate your first contract

```bash
python3 scripts/generate_contract.py TipJar \
  --fields "tips:mapping" \
  --functions "tip(uint256),getBalance(address)"
```

This writes EDSL implementation, specs, invariants, proofs, and a Foundry property test under `Contracts/TipJar/` and `test/`. Follow the printed instructions to register the contract in `Contracts/Specs.lean`, then see the [First Contract tutorial](/first-contract) for the full walkthrough.

## 6. Compile to Yul/EVM

```bash
lake build verity-compiler
lake exe verity-compiler          # Output in artifacts/yul/
```

For contracts that use external libraries (e.g., Poseidon hash):

```bash
lake exe verity-compiler --link examples/external-libs/PoseidonT3.yul -o artifacts/yul
```

See the [Linking Libraries guide](/guides/linking-libraries) for details.

## What to read next

1. **[Import a Solidity function](/solidity-import)**, Automatic Solidity importer quickstart: select a function, inspect its report and prove a property
2. **[First Contract tutorial](/first-contract)**, Author a native Verity contract from scratch; starts with the [minimal skeleton](/first-contract#minimal-skeleton)
3. **[Manual Port from Solidity](/guides/solidity-to-verity)**, Hand-porting patterns into the `verity_contract` surface when automatic import does not fit
4. **[Example Contracts](/examples)**, Progressive examples from single-slot storage to token transfers
5. **[Core Architecture](/core)**, The Contract monad, state model, and design decisions
6. **[Capabilities & Limits](/capabilities)**, What the verified fragment expresses today, and what is partial or unsupported
7. **[Compiler reference](/compiler)**, Full CompilationModel DSL documentation