About

While doing some research about on-chain NFT possibilities, I felt in love with trees and their digital modeling. And plan to go way further than trees.

Summary

  • Artwork is generative and stored fully on-chain.
  • Artwork evolves with blocks and transfers.
  • All MergeTrees will grow or decline depending of the game events.
  • The contract has 2 phases:
    1. Public mint for everyone until the initial total supply is reached = 100 + 3 artist's proofs.
    2. Stag hunt to play a worlwide cooperation game and earn rewards (NFT(s), rare traits...).

Markers

Change the marker of your tree from a curated selection of NFT collection that you own thanks to EIP-4883 Link to external website.
Pick a blossom flower 💮️ or an autumn leaf 🍁️ rather than the default 🟢 !

A guide will be published soon. In the meantime, you can propose your composable marker make a Pull Request Link to external website

On-chain artwork

MergeTrees are stored fully onchain on Ethereum and do not host the images files nor metadata on other network like IPFS or Arweave.

From the tree's traits, all the branches characteristics are computed and put together to draw the entire tree. Once it is ready, the resulting SVG is encoded in base64.

Rendering

Rendering trees on-chain wasn't easy, but it's real now. A first approach involved doing a lot of maths in Solidity to calculate each branch position. But there were a lot of limitations about the tree parameters.
So after some research, I decided to leverage the power of SVG Link to external website and its <use href > Link to external website , which allow to re-use parts of a document. For the tree, each branch is drawn by reusing the previous one and scaling/rotating it.
That's how it is stored on-chain and for old computers why you can experience some slowness (especially on animated one, but hey see it as an homage to PoW 😉️).

A detailed article will be published soon. For now, you can check the Modeling section.

What is a stag hunt ?

In game theory, a stag hunt Link to external website is a coordination game where two or more players can choose to cooperate and hunt a stag together for a large reward, or hunt a hare individually for a smaller and selfish reward.

The French philosopher Jean-Jacques Rousseau first introduced this game in "A Discourse on Inequality" in 1755. The game illustrates the conflict between social cooperation and indidivual benefit.

Formal definition (2 players)

Stag Hare
Stag 3, 3 0, 1
Hare 1, 0 1, 1

Stag 🦌

To capture the stag, you must call the huntStag function and more than 51% of the supply need to be "mature trees" i.e. they have the maximum segments level (acquired by transfers), including the caller tree.

Reward & consequences:

  • All "mature trees" are cut i.e. their segments are back to minimum and their 'stags' attribute is incremented.
  • They are all eligible to claim a new NFT.
  • Animated trees (from hare hunt) are not animated anymore
  • Growth is back (decline cancelled)
  • The stags trait is incremented.

Hare 🐰

To capture a hare, you must call the huntHare function and pay a fee greater or equal to:

Hare Hunt Min price formula

Reward & consequences:

  • Your tree gets animated trait until the next stag hunt
  • A new cloned NFT with lower value traits.
  • You trigger decline for everyone for 211810 blocks
  • Your tree is excluded from cooperation count for 211810 blocks
  • The hares trait is incremented.

Diagram

Mermaid flow chart diagram

Artwork Evolution

Transfers 🤝

At every NFT transfer, the tree will add or remove 1 segment / level depending on the growth phase. Allowing it to be a simple trunk or a beautiful tree with 6 segments.


Note: if you go to 0 segment, a special message will display.

Length growth 📈 or decline 📉?


For every block mined in the blockchain, the tree will grow in length if we are in a growing phase or decline otherwise. A growthDivider is also set to tweak it more precisely.


Colors 🎨

Since we all share the same planet but have a highly unequal impact on it, certain MergeTrees have the unique ability to alter 1 bit of the color across ALL trees.
If they manage to reach consensus, they might be able to turn the trees and their markers to red, blue or yellow (...).

MergeTree Traits

MergeTrees are generated pseudo-randomly based Ethereum block hashes and have the following traits:

  • Length: between 20 and 227
  • Diameter: between 5 and 40
  • D: Fractal dimension (Hausdorff), between 2 and 3 (stored as an index of precomputed values)
  • Δ: Leonardo da Vinci's exponent, between 1.93 and 2.3 (stored as an index of precomputed values)
  • Angle: (20°, 30°, 45°, 60°, 90°)
  • Branches: (2, 3, 4)
  • Animated: if the tree growth or decline is animated each 12 seconds (PoS block time)

You can preview your tree in the Playground.

Tree Digital Modeling

For modeling the tree, I used a fractal canopy as described by Benoît Mandelbrot in:

B. B. Mandelbrot, The Fractal Geometry of Nature (Freeman, San Francisco, 1983). ISBN 0716711869 Link to external website

But calculating angles and floating numbers in Solidity is hard (integers are not made for it), you can have a look at this great work solidity-trigonometry Link to external website by mds1 based on the original solidity work of Lefteris Karapetsas Link to external website who ported Dave Dribin's trigint C library Link to external website, which in turn is based on an article Link to external website by Scott Dattalo. It made me realize the complexity of tree modelling and computing costs on the EVM.

My solution was to leverage leverage the power of SVG Link to external website (using the client visualizer) and its <use href > Link to external website, which allow to re-use parts of a document.
Making it even more interactive and able to reach 7-8 segments rather than only 4 ! The file size was also reduced by 25x (74.9 kB to the actual 2.9 kB) and rendering from smartcontract went from 4sec to 0.2sec in test environment. The only downside is the rendering on the browser or client which is a bit slower. A lot of QA solved this by finding acceptable tradeoffs.

In the smartcontract, the trunk is drawn first, then the branches are drawn recursively.
The length and diameter are scaled at each level from the trunk.

For a length at level k, with N the number of daughters branchs and delta the Hausdorff dimension: Length trait

For a diameter at level k, with N the number of daughters branchs and Δ the Leonardo da Vinci's exponent:

Diameter trait

Each NFT has different values for Δ and D, stored in traits, making it unique.

Leonardo da Vinci's exponent and his rule of trees

500 years ago, Leonardo da Vinci, after hours of observation, defined an empiric rule to help people draw trees:

All the branches of a tree at every stage of its height when put together are equal in thickness to the trunk below them.

The exponent with a range of 1.93 to 2.3 help to embrace the diversity of tree species.

Hausdorff dimension

The Hausdorff dimension is a mathematical concept used to quantify the complexity of fractal shapes by extending traditional notions of dimensionality. Wikipedia Link to external website

A more detailled approach on tree modelling can be found in this research publication:

Eloy, C. (2011). Leonardo’s Rule, Self-Similarity, and Wind-Induced Stresses in Trees. Physical Review Letters, 107(25). https://doi.org/10.1103/physrevlett.107.258101 Link to external website

Seeder contract

The MergeTree Seeder contract is used to determine traits during the minting process. It is upgradeable to support future trait generation algorithm upgrades and can be locked by the team to prevent any further update.
Currently, traits are determined using pseudo-random number generation:

keccak256( abi.encodePacked( block.prevrandao, address(this), tokenId ) );

Please note that it is not truly random and could be predicted and/or biased by validators, but in a limited way.
See Security considerations of EIP-4399 Link to external website.

License

The artworks are licensed in CC BY Link to external website and the code in GPL-3.0 Link to external website.


Disclaimer: You are using this site and contracts at your own risk.