Knowledge Base
  • 👨‍🎨For creators
    • 👋Intro to creating with Highlight
    • 📜Project quick start guides
      • Launch an open edition
      • Launch a delayed reveal collection
      • Launch a 1-of-1 auction
      • Launch a generative artwork
      • Launch an open edition generative artwork
      • Launch a PFP project
      • Launch a generative, image-based PFP project
      • Launch a ranked auction
      • Launch an onchain project
      • Launch a collector's choice project
      • Ongoing drops with the same contract
    • 🎇Learn the creation flows
      • ERC-721 vs. ERC-1155 Token Standards
      • Edition flow
      • Generative flow
      • Series flow
      • The importance of testing your collections
    • 👩‍💻Use embeds to build custom mint sites
      • Case Study: How Superchain Chiblings launched a fully custom website on Highlight x Base
      • Running a collector's choice mint via embeds
    • 💸Selling your NFTs
      • Available sale methods
        • Ranked auction
        • Dutch auction
        • English auction
      • Setting up gates (allowlists)
      • Combining sale methods
      • Configuring payment currencies
        • Accepting ERC20 payments
        • Accepting credit card payments
      • Payouts, royalties & splits
      • Livestream on the mint page
    • 🛠️Managing your collections
      • Hiding a collection
      • Mint creator reserves
      • Airdropping tokens
      • Updating collection metadata
      • Getting verified
      • Sponsored mints
      • Reducing collection size
    • 🔮Generative & onchain art tools
      • Highlight Studio
      • Onchain file system
      • Storing SVGs onchain
      • Downloading token metadata
      • How onchain is Highlight?
    • 🌐Integrations & ecosystem
      • Farcaster
      • Paragraph.xyz
      • Foundation Worlds
        • Importing a collection to Worlds
        • Foundation × Highlight FAQs
      • Export generative art from Cables.gl
      • Highlight on mobile
    • 🤓Advanced
      • Reusing contracts
      • Randomization algorithm
      • Upload asset specifications
      • Fulfilling auctions for non-transferable tokens
    • ✨About Highlight
      • Artwork policies
      • Highlight fees
  • For Collectors
    • 💳Buying
      • Buying on secondary
      • Exchange currency across chains
  • 💲Selling
    • Selling on secondary
    • Instantly sell & relist NFTs
  • 🔔Notifications
  • For developers
    • Intro to the Highlight Protocol
    • NFT contracts
      • Official addresses
      • ERC721GeneralSequence
      • ERC721General
      • ERC721EditionsDFS
      • ERC721SingleEditionDFS
      • ERC721GenerativeOnchain
      • Deprecated contracts
    • Custom metadata renderers
      • Example custom renderers
    • Minting protocol
      • Mint Managers
      • Mint Mechanics
        • Dutch auction mechanic
        • Ranked auction mechanic
        • Verisart mechanic
        • Seed-based mechanic
        • Auction Manager *
      • Referral Manager
    • Management modules
      • TokenManager
      • RoyaltyManager
    • Observability
    • Onchain File Storage
    • Mint fee oracle
    • Protocol rewards
      • Creator rewards
      • Mint referral rewards
    • Crosschain burn / redeem
  • Official links
    • ✨Highlight website
    • 🟣Highlight Farcaster
    • 🐦Highlight Twitter
    • 👋About us
Powered by GitBook
On this page
  • Randomization algorithm overview
  • Generative randomization process
  • Series randomization process
  1. For creators
  2. Advanced

Randomization algorithm

PreviousReusing contractsNextUpload asset specifications

Last updated 11 months ago

Randomization algorithm overview

Highlight ensures that mints for generative and series collections with random distribution mechanics are fair, provably random, and decentralized.

We use an independently verifiable, deterministic algorithm to populate token metadata on random mints. This means that:

  • Collectors can independently verify the provable randomness of each and every token’s metadata.

  • Neither the creator nor Highlight knows which mints will get which metadata, meaning no party can help any collector.

While metadata is centralized during a mint, we upload revealed metadata to Arweave in parallel so that collectors can always verify the centralized metadata against its decentralized copy. Once the mint ends, the creator can update their collection to use the decentralized metadata on-chain.

Generative randomization process

The hl-gen.js script provides a number of methods intended to help you generate deterministic randomness in your artwork. These methods are seeded by a combination of the transaction hash (or a predetermined hash if you choose) and the token ID.

It is important to use these methods to generate randomness in place of Math.random or p5’s random function to ensure that, after a token is minted, it renders identically on all subsequent renders.

Series randomization process

Pre-mint: creator upload

When the creator of a Series uploads the initial folder of the Series’ metadata, our tooling indexes the metadata in the order it was uploaded. These are called metadata ids.

During mint

Token ids are minted sequentially, in ascending order.

On each mint, we run an algorithm that generates the metadata id deterministically using a Pseudo-Random Number Generator (PRNG) called Mulberry32. This PRNG function outputs a metadataId from the following inputs:

  • Transaction hash

  • Block hash

  • Token id

  • Unclaimed metadataIds

Once a valid metadataId is generated, we populate the minted token’s metadata with the metadata corresponding to the metadataId.

We also upload the metadata to the Arweave folder, updating the base uri of the decentralized copy that remains inspectable by collectors.

Verification of fairness

Any third party can independently verify the randomness of any mint

The following pseudo-code is the verification algorithm that one can run to determine the expected metadataId to be generated for all minted tokens until a certain one. To run the verification algorithm, you’ll need the transaction hashes of each minted token, in-order.

const generateMetadataId = (txHashes: string[], size: number): number[] => {
  // size is the size of the series 
  const unclaimedMetadataIds = Array.from({length: 10), (_, i) => i + 1);
  const generatedMetadataIds: number[] = []
  for (let i = 0; i < mintedTokenId; i++) {
    const txHash = txHashes[i];
    const blockHashes = await getBlockHashesFromTxHash(txHash);
    const id = prng(txHash, blockHashes, i + 1, unclaimedMetadataIds)
    unclaimedMetadataIds = unclaimedMetadataIds.filter(item => item != id)
    generatedMetadataIds.push(id)
  }
  return generatedMetadataIds;
}

// to verify the expected metadata id for token n, you will need the 
transaction hashes of mints 1 - n. This verification algorithm will return 
the expected metadata ids for tokens 1 - n

Post-mint: mint ends

Creator executes a transaction that swaps the centralized folder on-chain for a decentralized Arweave copy.

👨‍🎨
🤓