aptos-move/framework/aptos-experimental/doc/helpers.md
<a id="0x7_helpers"></a>
0x7::helperscut_vectorget_veiled_balance_zero_ciphertextpublic_amount_to_veiled_balance<a id="@Constants_0"></a>
<a id="0x7_helpers_EVECTOR_CUT_TOO_LARGE"></a>
Tried cutting out more elements than are in the vector via <code>cut_vector</code>.
<pre><code><b>const</b> <a href="helpers.md#0x7_helpers_EVECTOR_CUT_TOO_LARGE">EVECTOR_CUT_TOO_LARGE</a>: u64 = 1; </code></pre><a id="0x7_helpers_cut_vector"></a>
cut_vectorGiven a vector <code>vec</code>, removes the last <code>cut_len</code> elements of <code>vec</code> and returns them in order. (This function exists because we did not like the interface of <code>std::vector::trim</code>.)
<pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_cut_vector">cut_vector</a><T>(vec: &<b>mut</b> <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><T>, cut_len: u64): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><T> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_cut_vector">cut_vector</a><T>(vec: &<b>mut</b> <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><T>, cut_len: u64): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><T> { <b>let</b> len = vec.length(); <b>let</b> res = <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(); <b>assert</b>!(len >= cut_len, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="helpers.md#0x7_helpers_EVECTOR_CUT_TOO_LARGE">EVECTOR_CUT_TOO_LARGE</a>)); <b>while</b> (cut_len > 0) { res.push_back(vec.pop_back()); cut_len -= 1; }; res.reverse(); res } </code></pre> </details><a id="0x7_helpers_get_veiled_balance_zero_ciphertext"></a>
get_veiled_balance_zero_ciphertextReturns an encryption of zero, without any randomness (i.e., $r=0$), under any ElGamal PK.
<pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_get_veiled_balance_zero_ciphertext">get_veiled_balance_zero_ciphertext</a>(): <a href="../../aptos-framework/../aptos-stdlib/doc/ristretto255_elgamal.md#0x1_ristretto255_elgamal_CompressedCiphertext">ristretto255_elgamal::CompressedCiphertext</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_get_veiled_balance_zero_ciphertext">get_veiled_balance_zero_ciphertext</a>(): elgamal::CompressedCiphertext { elgamal::ciphertext_from_compressed_points( <a href="../../aptos-framework/../aptos-stdlib/doc/ristretto255.md#0x1_ristretto255_point_identity_compressed">ristretto255::point_identity_compressed</a>(), <a href="../../aptos-framework/../aptos-stdlib/doc/ristretto255.md#0x1_ristretto255_point_identity_compressed">ristretto255::point_identity_compressed</a>() ) } </code></pre> </details><a id="0x7_helpers_public_amount_to_veiled_balance"></a>
public_amount_to_veiled_balanceReturns an encryption of <code>amount</code>, without any randomness (i.e., $r=0$), under any ElGamal PK. WARNING: This is not a proper ciphertext: the value <code>amount</code> can be easily bruteforced.
<pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_public_amount_to_veiled_balance">public_amount_to_veiled_balance</a>(amount: u32): <a href="../../aptos-framework/../aptos-stdlib/doc/ristretto255_elgamal.md#0x1_ristretto255_elgamal_Ciphertext">ristretto255_elgamal::Ciphertext</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="helpers.md#0x7_helpers_public_amount_to_veiled_balance">public_amount_to_veiled_balance</a>(amount: u32): elgamal::Ciphertext { <b>let</b> scalar = <a href="../../aptos-framework/../aptos-stdlib/doc/ristretto255.md#0x1_ristretto255_new_scalar_from_u32">ristretto255::new_scalar_from_u32</a>(amount); elgamal::new_ciphertext_no_randomness(&scalar) } </code></pre> </details>