Skip to content

genlayer-foundation/genlayer-living-organism

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Living Organism

A self-evolving intelligent contract on GenLayer. Each generation is a new contract deployed with LLM-mutated source code — not data-driven evolution, actual code evolution.

How it works

The contract stores its own source code as a string. When evolve() is called:

  1. The source code is passed to an LLM with instructions to mutate it
  2. Validators verify the mutation preserves the core structure (class name, evolve method, storage fields)
  3. The mutated code is deployed as a new child contract via gl.deploy_contract()
  4. The child is a new generation — same pattern, new behavior

Each generation keeps a registry of its children. Each child knows its parent and generation number. If a child is broken, the parent still works. Anyone can call evolve() on any generation to spawn the next one.

Generation 0  ──evolve()──►  Generation 1  ──evolve()──►  Generation 2
     │                            │
     └──evolve()──►  Generation 1b (branching is possible)

Contract methods

Method Type Description
evolve(suggestion="") write Spawn a mutated child contract. Optional suggestion guides the mutation direction.
get_code() view Read the contract's current source code
get_lineage() view JSON with generation number, parent address, children addresses, and own address
get_generation() view Current generation number
get_children() view List of child contract addresses

Deployed on GenLayer Studio

Generation 0: 0x1AD7273103F49098Be7475c54622ad787a5cC006

Deploy your own

Prerequisites

Steps

# Install dependencies
npm install

# Select the network (studionet, localnet, or a testnet)
genlayer network set studionet

# Deploy generation 0
npm run deploy

The deploy script automatically passes the contract's own source code as a constructor argument, creating generation 0 with no parent.

Project structure

contracts/living_organism.py   # The living organism contract
deploy/deployScript.ts         # Deployment script (reads contract, deploys gen 0)

Design decisions

  • Factory pattern, not self-upgrade — each generation is a separate contract. No storage layout constraints. Broken children don't affect parents.
  • Code as state — the contract stores its own source as a str field, readable via get_code(). This same string gets passed to the LLM for mutation and to gl.deploy_contract() for spawning.
  • Consensus — leader asks the LLM to mutate the code, validator checks structural compatibility (both must preserve evolve(), class structure, storage fields).
  • Open evolution — anyone can trigger evolve() and pay gas. No owner restriction.

Built with

License

MIT

About

A self-evolving intelligent contract on GenLayer. Each generation deploys a new contract with LLM-mutated source code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors