Docs/Examples/Breeding Engine

BreedingMutationEngine (Verifiable Trait Inheritance)

Processes breeding pairs with on-chain VRF — the trigger holder cannot preview offspring traits and withhold until a favorable combination appears.


Overview

BreedingMutationEngine manages a queue of breeding pairs and resolves them one at a time using VRF. For each pair, five trait slots are resolved independently: each slot has a 5% chance of random mutation, otherwise it inherits from one parent at random. The offspring is minted to the requesting player. No one sees the traits before the transaction lands.

PropertyValue
Base contractAutoLoopVRFCompatible
VRF usagePer-trait inheritance and mutation resolution
Gas per tick~100k–250k
Sourceautoloop/src/agents/BreedingMutationEngine.sol
Tests29 passing (unit + fuzz)

Why AutoLoop Is Structurally Required

Trait combinations have unequal value — the trigger holder can cherry-pick. Without VRF:

  1. Worker computes the trait outcome off-chain before submitting
  2. Worker sees offspring would have Strength=2, Speed=98 (valuable meta combo)
  3. Worker submits the transaction immediately
  4. Worker sees offspring would have Strength=12, Speed=14 (worthless)
  5. Worker withholds until the next block produces a better outcome

This attack is routine in any breeding game that uses block.timestamp or blockhash as randomness and lets the caller submit at will. The VRF proof binds the randomness before the worker sees the result. The queue-and-process model means pairs are processed in order — no selective execution.

The pattern appears in Axie Infinity, CryptoKitties, and any on-chain NFT breeding system that uses predictable entropy.

Mechanics

  • mint() payable: genesis mint — assigns five traits from keccak256(blockhash, tokenId, sender). Genesis entropy is not VRF-protected (acceptable: no economic front-run opportunity at genesis time).
  • queueBreeding(parent1, parent2) payable: caller must own both parents. Pays breedingFee. Pair is added to the queue.
  • shouldProgressLoop(): breedingQueue.length > 0 && block.timestamp - lastBreed >= breedingCooldown
  • progressLoop(progressWithData): VRF → processes the first pair in queue. For each of 5 traits: if rand % 10000 < 500 (5%) → random mutation [1–100]; else → inherit from parent1 or parent2 based on LSB. Offspring minted to pair owner. Pair removed via swap-and-pop. Emits BreedingComplete(parent1, parent2, offspringId, traits).
  • withdrawProtocolFees(address): admin withdraws accumulated 2% protocol fees.

Revenue Model

  • 2% protocol fee on each queueBreeding() call (taken from breedingFee)
  • AutoLoop gas fee on each tick

Deploy

forge create src/agents/BreedingMutationEngine.sol:BreedingMutationEngine \
  --constructor-args 3600 1000000000000000 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Args:

  • breedingCooldown (seconds between breed ticks) — 3600 = 1 hour
  • breedingFee (wei per breed request) — 1000000000000000 = 0.001 ETH

After deploy, register with AutoLoop and ensure VRF keys are registered for all worker controllers.

Dashboard

View BreedingMutationEngine on the AutoLoop Dashboard.