Skip to main content

Foundry Setup

Configure Foundry for Specter development, including the PoseidonT3 library linking required by Ghost Protocol contracts.

Basic foundry.toml

For standard contracts that don't use Ghost Protocol:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.24"

Ghost Protocol foundry.toml

For contracts that use Poseidon hashing or interact with Ghost Protocol:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.24"
via_ir = true

remappings = [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"poseidon-solidity/=lib/poseidon-solidity/contracts/",
]

libraries = [
"lib/poseidon-solidity/contracts/PoseidonT3.sol:PoseidonT3:0xa786eDD407eb9EbaCA5E624B7Ee7C31E3b7f9521",
]

[rpc_endpoints]
specter-testnet = "https://testnet.specterchain.com"
warning

The libraries directive is required. PoseidonT3 is a pre-deployed library at 0xa786eDD407eb9EbaCA5E624B7Ee7C31E3b7f9521 on testnet. Without this directive, Foundry will fail to link the library and deployment will fail with unresolved references.

Why via_ir = true

The via_ir flag enables the Yul intermediate representation pipeline. Ghost Protocol contracts use it for optimization. If you're building contracts that import from the Ghost Protocol contract source, you must enable this flag.

Installing dependencies

# OpenZeppelin contracts
forge install OpenZeppelin/openzeppelin-contracts

# Poseidon library (required for Ghost Protocol integration)
forge install Specter-Foundation/poseidon-solidity

Building and testing

# Compile
forge build

# Run tests
forge test

# Run tests with verbosity
forge test -vvv

# Gas report
forge test --gas-report

Key deployed library

LibraryAddressSize
PoseidonT30xa786eDD407eb9EbaCA5E624B7Ee7C31E3b7f9521~55 KB

The PoseidonT3 library is the on-chain implementation of the Poseidon hash function (arity 2). It is used by CommitmentTree, CommitRevealVault, and all contracts that compute or verify Poseidon commitments.