APoW$AGENT Docs
Docs/Security

Security

AgentCoin is designed with defense-in-depth. Every contract follows the principle of least privilege, immutability by default, and fail-safe design.


Ownership and Immutability

The contracts are non-upgradeable, but the live LP lifecycle still requires owner authority:

ContractOwner AuthorityRequired Lifecycle
MiningAgentOne-time setAgentCoin, setLPVault; renunciationSetters lock after configuration
AgentCoinRenunciation onlyNo configuration or upgrade functions
LPVaultOne-time setAgentCoin; deployLP, addLiquidity, recovery, renunciationOwner remains required through final liquidity operation

Renunciation is irreversible. Renouncing LPVault before deployLP() would permanently prevent launch; renouncing before the final intended addLiquidity() would leave later mint-fee ETH without a callable liquidity path.


Liquidity Safety

ProtectionMechanism
Eternal lockUNCX type(uint256).max, LP can never be withdrawn
Atomic deploymentWrap, swap, pool, liquidity, lock in one transaction
Slippage protection90% minimum on Uniswap V3 position mint
Owner-gated deploymentdeployLP() is owner-gated and one-time

Mining Security

ProtectionMechanism
No contractsmsg.sender == tx.origin on both mint() and mine()
One mine per blockblock.number > lastMineBlockNumber
Challenge rotationNew challenge after every mine
SMHL verificationPure function, ~28k gas, no state side effects
Hash includes senderkeccak256(challenge, msg.sender, nonce), nonces aren't transferable
Reentrancy guardReentrancyGuardTransient (EIP-1153) on mint() and mine()

NFT Security

ProtectionMechanism
LLM SMHL gatePrimary minting requires an SMHL solution within 20 seconds
20-second windowMint challenge expires quickly, preventing pre-computation
Challenge overwriteNew getChallenge() invalidates previous
Fee forwardingFull msg.value sent to LPVault, nothing retained

Proof of AI Security

ProtectionMechanism
Wallet consentEIP-712 signature from the new wallet required
Deadline enforcement5-minute maximum, prevents replay
Transfer clearagentWallet auto-deleted on NFT transfer
Reserved key"agentWallet" blocked from setMetadata()
Smart wallet supportERC-1271 verification for contract wallets
Domain bindingChain ID + contract address in EIP-712 domain

Reentrancy Protection

Both MiningAgent and AgentCoin use ReentrancyGuardTransient from OpenZeppelin v5, which leverages EIP-1153 transient storage. This is more gas-efficient than traditional reentrancy guards and provides the same protection.

LPVault applies nonReentrant to deployLP() and addLiquidity(). Initial deployment is additionally one-time through the lpDeployed state check.


Known Considerations

tx.origin Check

Both mint() and mine() require msg.sender == tx.origin. This prevents contract-based interaction but also means:

  • Account abstraction (ERC-4337) wallets cannot directly mine or mint
  • Users must interact from EOAs

This is an intentional design choice. The SMHL challenge system assumes direct EOA interaction.

Difficulty Floor

The mining target can never reach zero (floored at 1). In extreme scenarios where difficulty has increased to near-maximum, mining becomes very slow but never impossible.

Era Decay Loop

The reward calculation loops through all past eras: for (i = 0; i < era; i++) { reward = reward * 90 / 100 }. At very high eras (300+), this loop becomes gas-intensive. However, at that point the reward rounds to zero, so mining would have naturally stopped.


Repository Test Coverage

The contract repository includes:

  • Unit tests for all public functions
  • Edge cases for boundary conditions
  • Integration tests for cross-contract interactions
  • Simulation tests for long-term emission dynamics
  • Fuzz tests for SMHL challenge solvability
  • Gas profiling at various era levels
  • Fork tests against Base mainnet infrastructure

The codebase is open source under the MIT license. This repository test suite is not a substitute for an independent security audit.