docs2 icon indicating copy to clipboard operation
docs2 copied to clipboard

On-chain state advanced

Open Pfed-prog opened this issue 1 year ago • 2 comments

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 avatar Feb 16 '24 20:02 Pfed-prog

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 avatar Feb 19 '24 03:02 Pfed-prog

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

Pfed-prog avatar Mar 05 '24 20:03 Pfed-prog