Note {
version: Felt,
key: AffinePointCompressed,
R: AffinePointCompressed,
commitment: AffinePointCompressed,
enc_amount: Felt,
message_id: Option<U256>
}
AffinePointCompressed {
x: Felt,
y_parity: bool,
}
In order to remain hidden to everyone that look at the note apart from the spender and the receiver, the amount on the note needs to be encrypted.
The amount is encrypted as follows:
The receiver will be able to compute the hash of the shared key, compute the inverse and then multiply the inverse with
the enc_value and get the actual note's value
A Note contains a Pedersen Commitment that force the spender of the note to not overspend more than the note's value.
The commitment C is computed as follows:
$C = bG + vH$
For:
-
$G$ - Generator of the STARK Curve -
$H$ - Is the hash-to-curve point for each token generated according to the 6.6.2. Simplified Shallue-van de Woestijne-Ulas Method algorithm. The relation betweenGandHshould be unknown. TheHpoint is chain-specific, testnet value will be different from mainnet to avoid any possibility of a replay-attack. -
$v$ - the value represented asFelt -
$b$ - blinding factor
The blinding factor b is computed by the spender of the note as follows:
The receiver now have the value of
Pedersen commitments are additively homomorphic, this means that we can add the input commitments and it should equal
output commitments, with small changes.
Let's say we have
This means that the input commitments equals to: $$ \sum_{i=0}^m C^{in}i = \sum{i=0}^m [b^{in}i*G] + \sum{i=0}^m [v^{in}_i*H] $$
And the output commitments equals to: $$ \sum_{i=0}^n C^{out}i = \sum{i=0}^n [b^{out}i*G] + \sum{i=0}^n [v^{out}_i*H] $$
We need to make sure that the input amounts equals output amounts such that subtracting one from the other equals 0: $$ \sum_{i=0}^m C^{in}i - \sum{i=0}^n C^{out}i $$ $$ = (\sum{i=0}^m [b^{in}i*G] - \sum{i=0}^n [b^{out}i*G]) + (\sum{i=0}^m [v^{in}i*H] - \sum{i=0}^n [v^{out}_i*H]) $$
If the spender is honest, the amount factors $(\sum_{i=0}^m [v^{in}i*H] - \sum{i=0}^n [v^{out}i*H])$ will cancel each other and we are left just with the sum of the blinding factors $\sum{i=0}^m [b^{in}i*G] - \sum{i=0}^n [b^{out}_i*G]$.
This sum will not cancel out because the blinding factors are not meant to cancel each other. But we can do
something about that. The spender know the blind factors and we can add a new value to cancel each
others. The spender should prove that he know the scalar value for the new point that we add, let's call this new
term
Let's recap and see that now everything should be fine. Our commitments now looks like this: