# TBM Attribute Generation

## To our newly minted pawrents/pawrents-to-be,

Thank you for all your love and support thus far! Our team is absolutely thrilled as we enter our final hours of preparation to ensure all 9,800 bears are lookin' and smellin' good for public adoption! (200 bears are reserved for the team and drops)

We wanted to take this opportunity to also assure you that our minting process is designed to be fair and equal. In adhering to the values of fairness, the reveal of the bears will only be done when all the bears are sold out. Thus upon minting of a bear, you will see a placeholder image.

The section below outlines how we ensure fairness and complete randomisation. So don't worry about us saving the good stuff for ourselves, or swapping out your rare mint with a common one! It's not like us to do that (: Of course, you don't have to simply trust our word. Trust our work instead 🐻❤️

### **Here's how we do it:**

Before the sale, we randomly generate the trait combinations of all 10,000 NFTs, and organise them into a CSV-formatted trait table. The SHA-256 hash of this CSV file is used to initialise [The Bear Market Token contract](https://viewblock.io/zilliqa/address/zil167flx79fykulp57ykmh9gnf3curcnyux6dcj5e). This hash on the contract cannot be changed by anyone, not even the contract owner, EVER. More technical details in the later sections.

Upon selling out, the minted bears will then be revealed. Right after the reveal, we’ll publish the CSV file on IPFS. Anyone can then download the file and verify that the revealed CSV file matches with the hash previously published on the contract.

As the hash was already locked in prior, that would mean any changes to the file would result in a different hash. Yes, we're good but changing traits without changing the hash is humanly impossible. We know you're smart enough to catch any irregularities so go ahead and give it a check. 🙂

### **tl;dr**

Everyone has an equal chance at minting any type of bear!

## Methodology

### Random Generation

The attributes and image generation outline:

1. Generate Attributes and Render Images
2. Compute Provenance Hash
3. Create NFT Contract
4. Commit to RN Retriever Address on Ethereum\
   \---- Sale Completes ---
5. Retrieve Verifiable Random Number via Chainlink
6. Assign Token ID to Bear ID

#### Generate Attributes and Render Images

10,000 NFT attribute sets are generated randomly. An algorithm is used to randomly pick trait values within constraints that make sense, layering images in the right order. Examples of constraints include making sure Polar Bears are not grouped with Zombie Eyes, as that would make a very strange-looking Polar Bear 👾

Based on the traits generated in the previous step, the image for each Bear is rendered.

#### Compute Provenance Hash

A [SHA256](https://en.wikipedia.org/wiki/SHA-2) hash of the rendered image file is then added to an *Attributes CSV* with the attributes. Each row of the *Attributes CSV* represents a single Bear token.&#x20;

This *Attributes CSV* file is then hashed with the same algorithm, the resulting file hash is called the ***Provenance Hash**.*

{% hint style="info" %}
The *Attributes CSV* file will be publicly available after the sale has concluded.
{% endhint %}

#### Create NFT Contract

The Bear Market Token NFT contract is deployed with a ***Provenance Hash*** as an initialisation parameter along with other information. There is no transition available in the contract to modify this field and is therefore immutable.&#x20;

The NFT contract has been deployed to address: [zil167flx79fykulp57ykmh9gnf3curcnyux6dcj5e](https://viewblock.io/zilliqa/address/zil167flx79fykulp57ykmh9gnf3curcnyux6dcj5e?network=mainnet)

![Screenshot from ViewBlock showing TBM contract.](/files/-MjDvNarozsJIJMTuLcD)

{% hint style="info" %}
Since there is no transition on the contract to modify this field, the `provenance_hash` on the contract **can never be changed, by anyone, ever**.
{% endhint %}

#### Commit to RN Retriever Address on Ethereum

The address used for retrieving a verifiable random number (next step) is determined before the sale. This ensures that the team cannot create multiple random numbers and cherry-pick a favourable one.

The address is recorded as a[ transaction](https://viewblock.io/zilliqa/tx/645818a6077d418964721c231bce07e75dc3fd61e0e811cd92763165184ed5bb) sent to the NFT contract from a Zilswap deployer address. It is marked as failed because it calls a non-existent function. The purpose of this transaction is simply to record the address as part of the transaction inputs, and therefore the failure or success of the transaction itself does not actually matter.

`RN Retriever Address Commitment Transaction Hash (Zilliqa):`\
`645818a6077d418964721c231bce07e75dc3fd61e0e811cd92763165184ed5bb`

`RN Retrieve Address (Ethereum):`\
`0xff86325df809d1b09aec381a3c3b9c3fb25305f0`

#### Retrieve Verifiably Random Number via Chainlink

After the sale is concluded, a verifiably random number is retrieved from a blockchain. Since this is not yet possible on the Zilliqa blockchain, [ChainLink VRF](https://docs.chain.link/docs/chainlink-vrf/) on Ethereum will be used to retrieve the random number.

The first number picked from the RN Retriever Address committed above will be used, so retrieving multiple numbers and cherry-picking is not possible. The transaction hash will be posted here once this step is executed.

#### Assign Token ID to Bear ID

The random number will then be used to offset the Token ID, which is then assigned to the Bear ID (see above CSV) (overflow will be rotated back to the front). The reserved supply used for marketing and giveaway purposes will not be shifted.\
\
Example: If you have a Token ID 1337, and random number 5123432 is picked, the NFT you receive will have Bear ID 9169.\
&#x20;`Math:`\
`1337 + (5123432 % 9800) = 9169`&#x20;

### Fair Distribution

#### Verifiably Random

By using a verifiably random number — retrieved after the sale — to offset Token ID to Bear ID assignment, it is impossible for anyone, even members of the team, to unfairly obtain a more rare NFT from the collection.&#x20;

#### Verifiably Tamper Proof

The NFT attributes are set in stone, and cannot be modified. Since any change to the generated attributes will result in a change in the *Attributes CSV*, which translates to a file hash that is different from the ***Provenance Hash***.&#x20;

You can verify the *Attributes CSV* has not been altered by running the following command:

```
$ openssl dgst -sha256 attributes.csv
SHA256(dist/legacy-attributes.csv)= 411755d1c5dad0e6dd0d6f2a23687b3ddff21054f3e82cce7631dda9273452bd
```

You will see the output `411755d1c5dad0e6dd0d6f2a23687b3ddff21054f3e82cce7631dda9273452bd`, which is the ***Provenance Hash**.* The current ***Provenance Hash*** is publicised as a contract parameter of [The Bear Market Token contract](https://viewblock.io/zilliqa/address/zil167flx79fykulp57ykmh9gnf3curcnyux6dcj5e).&#x20;

### UPDATE: Shirts Off!

#### Image Update (Bears with Body: None)

![Original bear rendering with Body: None.](/files/-MjZkSiQDQhfLCZIDeFY)

Our Bear Crafters found that bears with a plain shirt actually look way better without a shirt! So we decided to let the bears remove their shirts and roam shirt-free. See how carefree they are for yourself:

![Updated bear rendering with Body: None.](/files/-MjZkY0J3aXOjECTa-U1)

You guessed it! This means some bear pawtraits now have different hashes, and the CSV File would ultimately have a hash different from the ***Provenance Hash*****.** Comparing the legacy CSV File and the updated CSV File, you will notice that all attributes are left unchanged. the only difference lies in the hash of the image file.&#x20;

```
# Example from legacy CSV
6175,Brown,None,Normal,Smile,None,Yellow,0lWpyNHp4lINxRzhBotvMXMMahzf3RUDoDqVU3/ltBw=

# Example from updated CSV
6175,Brown,None,Normal,Smile,None,Yellow,i0vW7R06WHf5w6UilWDiQtuhPvBiO4ZY6oCvxbB/udU=
```

This actually proves that the bear attributes are tamper-proof, as changing some image renderings will result in a different file hash. 🐻❤️

{% hint style="info" %}
Both CSV Files will be made available when the sale has concluded.
{% endhint %}

## UPDATE: The Reveal

### Retrieving Random Number

Sale has concluded and it is time for the grand reveal! The random number retrieval contract has been deployed and a verifiable random number was retrieved using this contract.

`RN Retriever Contract (Ethereum):`\
`0xffaa4cc8d630bfb483405e5ee550b25d1af604b7`

`RN Retrieval Transaction Hash (Ethereum):`\
`0x4ba7512817f4c08ec9c029190086037485d659e3fd3ea53c5ddad36de0b7db94`

`Retrieved Random Number:`\
`64147276475990748506760899694973421659372718799117962166213933420448497348718`

![Screenshot from etherscan.io showing random number.](/files/-Mk64gV6PtuzbZd6ZkvO)

`Random Offset (RN modulo 9800):`\
`64147276475990748506760899694973421659372718799117962166213933420448497348718 % 9800`\
`= 1718`

This means that if your Token ID is 1337, you will be getting Bear ID 3055.

`Math:`\
`1337 + 1718 = 3055`

The full list of Token ID to Bear ID assignment is available in the *Assignment CSV* file below.

### CSV Files

Click on the file names below to download the CSV file from IPFS.

| File                                                                                                                          | Hash                                                               |
| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [Attributes](https://ipfs.io/ipfs/bafybeigw6rau64ozkq2k2jowk7l45yc5edlzvb62mmta5akvhn3sphoq4m/attributes.csv)                 | `e635290790ec431900b7bce251c6eb5ee53805e67aa4b1c39018ace0a12c2a9e` |
| [Assignment](https://ipfs.io/ipfs/bafybeigw6rau64ozkq2k2jowk7l45yc5edlzvb62mmta5akvhn3sphoq4m/assignment.csv)                 | `0712c56cfa78b23f50e276d81075f88f6fb812a6c4d0717bb6502d74055bdc37` |
| [Attributes (Legacy)](https://ipfs.io/ipfs/bafybeigw6rau64ozkq2k2jowk7l45yc5edlzvb62mmta5akvhn3sphoq4m/legacy-attributes.csv) | `411755d1c5dad0e6dd0d6f2a23687b3ddff21054f3e82cce7631dda9273452bd` |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zilswap.io/tbm/the-bear-market-archives/attribute-generation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
