diff --git a/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/hash-functions.adoc b/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/hash-functions.adoc index d24233814d..a1a6dfa15c 100644 --- a/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/hash-functions.adoc +++ b/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/hash-functions.adoc @@ -5,13 +5,13 @@ [id="domain_and_range"] == Domain and range -All hashes outputs are eventually mapped to elements in stem:[$\mathbb{F}_p$] with stem:[$p=2^{251}+17\cdot 2^{192}+1$]. +All hashes outputs are eventually mapped to elements in stem:[$\mathbb{F}_P$], where stem:[$P=2^{251}+17\cdot 2^{192}+1$]. There are three hash functions used throughout Starknet's specifications: -* stem:[$sn\_keccak: \{0,1\}^* \rightarrow \mathbb{F}_p$] -* stem:[$pedersen: \mathbb{F}_p^2\rightarrow\mathbb{F}_p$] -* stem:[$poseidon: \mathbb{F}_p^*\rightarrow \mathbb{F}_p$] +* stem:[$sn\_keccak: \{0,1\}^* \rightarrow \mathbb{F}_P$] +* stem:[$pedersen: \mathbb{F}_P^2\rightarrow\mathbb{F}_P$] +* stem:[$poseidon: \mathbb{F}_P^*\rightarrow \mathbb{F}_P$] [id="starknet_keccak"] == Starknet Keccak @@ -22,7 +22,7 @@ in order to fit into a field element. [id="pedersen_hash"] == Pedersen hash -Pedersen hash makes use of the following STARK friendly elliptic curve over stem:[$\mathbb{F}_p$]: +Pedersen hash makes use of the following STARK friendly elliptic curve over stem:[$\mathbb{F}_P$]: [stem] ++++ @@ -37,7 +37,7 @@ where [id="definition"] === Definition -Given an input stem:[$(a,b)\in\mathbb{F}_p^2$], we begin by breaking it into stem:[$a_{low}, a_{high}, b_{low}, b_{high}$], +Given an input stem:[$(a,b)\in\mathbb{F}_P^2$], we begin by breaking it into stem:[$a_{low}, a_{high}, b_{low}, b_{high}$], where the low part consists of the low 248 bits of the element and the high part consists of the high 4 bits of the element. Our Pedersen hash is then defined by: [stem] @@ -72,6 +72,7 @@ poseidon_2(x,y) := \left[\text{hades_permutation}(x,y,2)\right]_0 Where latexmath:[[\cdot\]_j] denotes taking the j'th coordinate of a tuple .Additional resources + * xref:#poseidon_array_hash[Poseidon hash with an arbitrary number of inputs] * link:https://github.com/starkware-industries/poseidon/blob/main/poseidon3.txt[Parameters for defining the Poseidon permutation used in Starknet] * link:https://github.com/CryptoExperts/poseidon[Reference implementation in C and assembly of the above by CryptoExperts] @@ -94,7 +95,7 @@ h(...h(h(0, a_1),a_2),...,a_n),n) [id="poseidon_array_hash"] === Poseidon -Let stem:[$\text{hades}:\mathbb{F}_p^3\rightarrow\mathbb{F}_p^3$] denote the Hades permutation (with Starknet's parameters), then given an array stem:[$a_1,...,a_n$] of stem:[$n$] field elements +Let stem:[$\text{hades}:\mathbb{F}_P^3\rightarrow\mathbb{F}_P^3$] denote the Hades permutation, with Starknet's parameters, then given an array stem:[$a_1,...,a_n$] of stem:[$n$] field elements we define stem:[$poseidon(a_1,...,a_n)$] to be the first coordinate of stem:[$H(a_1,...,a_n;0,0,0)$], where: [stem] @@ -106,5 +107,5 @@ H\big(a_3,...,a_n;\text{hades}(s_1+a_1, s_2+a_2, s_3)\big), & \text{if } n\ge 2 \end{cases} ++++ -You can find an implementation of the above in Python link:https://github.com/starkware-libs/cairo-lang/blob/12ca9e91bbdc8a423c63280949c7e34382792067/src/starkware/cairo/common/poseidon_hash.py#L46[here], -and an equivalent Cairo implementation link:https://github.com/starkware-libs/cairo-lang/blob/12ca9e91bbdc8a423c63280949c7e34382792067/src/starkware/cairo/common/builtin_poseidon/poseidon.cairo#L28[here]. +For an implementation of the above in Python, see link:https://github.com/starkware-libs/cairo-lang/blob/12ca9e91bbdc8a423c63280949c7e34382792067/src/starkware/cairo/common/poseidon_hash.py#L46[poseidon_hash.py], +and for an equivalent Cairo implementation, see link:https://github.com/starkware-libs/cairo-lang/blob/12ca9e91bbdc8a423c63280949c7e34382792067/src/starkware/cairo/common/builtin_poseidon/poseidon.cairo#L28[poseidon.cairo] in the cairo-lang Github repository. diff --git a/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/p-value.adoc b/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/p-value.adoc index 85422f6c9c..487a4cd66e 100644 --- a/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/p-value.adoc +++ b/components/Starknet/modules/architecture_and_concepts/pages/Cryptography/p-value.adoc @@ -2,7 +2,7 @@ // The field element type in Starknet is based on the STARK field in the underlying Cairo VM. In other words, a value stem:[$$x$$] of a field element type is an integer in the range of stem:[$$0≤x