#Are smart contract fields private?

18 messages · Page 1 of 1 (latest)

stone sand
#

For example

// is the field x private?
class Ex extends SmartContract {
  ...
  x = new UInt32(42);
  ...
}
alpine dirge
#

x, in your example, is private. It's not on chain. But it's also not useful in a proof context.

ex = new Ex();
ex.x = UInt32.from(5);
ex.x = UInt32.from(10000);
#

There's no constraints on the value

stone sand
#

Thanks!

#

Does this mean the value can be manipulated at verification time irregardless of a proof?

alpine dirge
#

Not sure what you mean by at verification time. If you wanted to include it in a @method, you'd probably have to wrap the call in a Circuit.asProver context. I would call that an anti-pattern.

But I could imagine manipulating it, for example, after a transaction is sent, you could increment transactionCount on your smart contract instance. I can't think of too many examples where it's useful. Pretty much x in your example is a property on a typescript class just like any other property on a typescript class. But it's totally unrelated to any functionality of a smart contract.

stone sand
#

Verification time (when a node verifies the proof) as opposed to proving time (when the contract client generates the proof)

#

Thank you!

alpine dirge
stone sand
#

Okay, nice! Thanks for that

spice granite
#

Actually, x will not be stored in-chain, but it will be “hard coded” into the circuit, so it can’t be manipulated. And in order to execute the contract, users need the source code - so you’ll have to share the code and the value of x nonetheless

alpine dirge
#

Best way to learn an answer to something is write something incorrect on the internet 🙂

stone sand
spice granite
#

Users will always need to have the source code in order to execute the contract and produce a valid proof

stone sand
#

Solves that mystery. Thank you!

alpine dirge
#

@spice granite is there a good example of where a property like that would be useful?

spice granite
stone sand
#

I am thinking of a game with a fixed cost for making a move. I want the cost to be hardcoded in any given instance of the contract, a parameter amongst the instances, and not stored on chain.