#Are smart contract fields private?
18 messages · Page 1 of 1 (latest)
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
Thanks!
Does this mean the value can be manipulated at verification time irregardless of a proof?
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.
Verification time (when a node verifies the proof) as opposed to proving time (when the contract client generates the proof)
Thank you!
The verifier will not have access to the property x in your example. x is a property that only exists on the typescript class which lives, for example, in the user’s browser as they create a proof. It’s not reflected in the proof itself that gets sent to the network for verification.
Okay, nice! Thanks for that
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
Best way to learn an answer to something is write something incorrect on the internet 🙂
That's exactly what I was expecting!
Is there a better way to provide initial parameters to a contract in order for these values to be effectively baked into the @method call? (instead of requiring clients to be in possession of the source code)
Users will always need to have the source code in order to execute the contract and produce a valid proof
Solves that mystery. Thank you!
@spice granite is there a good example of where a property like that would be useful?
ye, like hard coding a constant in e.g. a DEX or more generally specifying a privileged public key that is only allowed to access some functionality
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.