o1-labs / docs2

Docs website for the Mina Protocol.
https://docs.minaprotocol.com
89 stars 133 forks source link

On-chain state advanced #854

Open Pfed-prog opened 9 months ago

Pfed-prog commented 9 months ago

Diving into a smart contract details further.

In On-chain state Section of a smart contract https://docs.minaprotocol.com/zkapps/o1js/smart-contracts#on-chain-state

image

It says that the state can consist of at most 8 fields of 32 bytes each.

But there are no details further. For example, I have used a simple trial and error method to see how this works in practice. For me 9 states worked as well.

image

Also, when I switched PublicKey instead of a Field the test script failed. Hence, PublicKey seems to take more space than a Field.

image

Removing one additional Field worked just fine.

image

I have tested my finding further -- and found out that 2 Fields is equivalent to 1 PublicKey

Pfed-prog commented 9 months ago

It would be amazing to come back to some resource that contains more information on state optimization.

For example, @IamZKdevETH probably his github -> @iam-dev shared with me the following repository that aims to pack data

https://github.com/45930/o1js-pack

Pfed-prog commented 8 months ago

I am not sure if this is the right place to just post walls of texts, excuse me.

In ERC-20 some tokens implement states that contain strings, I think from projects implemented during hackathons this is the main thing that stands out to me.

I have posted some thoughts on how to use available URI for this purpose https://forums.minaprotocol.com/t/mina-smart-contract-uri/6232/2