Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[moveos_std] Complete evm precompiled functions #1757

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ bitcoincore-rpc-json = "0.18.0"
toml = "0.8.12"
csv = "1.2.1"
revm-precompile = "7.0.0"
revm-primitives = "4.0.0"

# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
Expand Down
1 change: 1 addition & 0 deletions frameworks/moveos-stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ primitive-types = { workspace = true }
bech32 = { workspace = true }
bs58 = { workspace = true, features = ["check"] }
revm-precompile = { workspace = true }
revm-primitives = { workspace = true }

move-binary-format = { workspace = true }
move-bytecode-utils = { workspace = true }
Expand Down
202 changes: 198 additions & 4 deletions frameworks/moveos-stdlib/doc/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@


- [Constants](#@Constants_0)
- [Function `ec_recover`](#0x2_evm_ec_recover)
- [Function `sha2_256`](#0x2_evm_sha2_256)
- [Function `ripemd_160`](#0x2_evm_ripemd_160)
- [Function `identity`](#0x2_evm_identity)
- [Function `modexp`](#0x2_evm_modexp)
- [Function `ec_add`](#0x2_evm_ec_add)
- [Function `ec_mul`](#0x2_evm_ec_mul)
- [Function `ec_pairing`](#0x2_evm_ec_pairing)
- [Function `blake2f`](#0x2_evm_blake2f)
- [Function `point_evaluation`](#0x2_evm_point_evaluation)


<pre><code><b>use</b> <a href="">0x1::hash</a>;
<b>use</b> <a href="hash.md#0x2_hash">0x2::hash</a>;
</code></pre>


Expand All @@ -21,6 +29,15 @@
## Constants


<a name="0x2_evm_ErrorBlake2fFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorBlake2fFailed">ErrorBlake2fFailed</a>: u64 = 9;
</code></pre>



<a name="0x2_evm_ErrorEcAddFailed"></a>


Expand All @@ -30,6 +47,15 @@



<a name="0x2_evm_ErrorEcMulFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorEcMulFailed">ErrorEcMulFailed</a>: u64 = 7;
</code></pre>



<a name="0x2_evm_ErrorEcPairingFailed"></a>


Expand All @@ -39,11 +65,57 @@



<a name="0x2_evm_ErrorInvalidCoordinate"></a>
<a name="0x2_evm_ErrorEcRecoverFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorInvalidCoordinate">ErrorInvalidCoordinate</a>: u64 = 11;
<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorEcRecoverFailed">ErrorEcRecoverFailed</a>: u64 = 1;
</code></pre>



<a name="0x2_evm_ErrorInvalidInputSize"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorInvalidInputSize">ErrorInvalidInputSize</a>: u64 = 11;
</code></pre>



<a name="0x2_evm_ErrorModexpFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorModexpFailed">ErrorModexpFailed</a>: u64 = 5;
</code></pre>



<a name="0x2_evm_ErrorPointEvaluationFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorPointEvaluationFailed">ErrorPointEvaluationFailed</a>: u64 = 10;
</code></pre>



<a name="0x2_evm_ec_recover"></a>

## Function `ec_recover`

@param hash: Keccack-256 hash of the transaction.
@param v: Recovery identifier, expected to be either 27 or 28.
@param r: x-value, expected to be in the range ]0; secp256k1n[.
@param s: Expected to be in the range ]0; secp256k1n[.

@return public_address: The recovered 20-byte address right aligned to 32 bytes.

Elliptic curve digital signature algorithm (ECDSA) public key recovery function.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_ec_recover">ec_recover</a>(<a href="">hash</a>: <a href="">vector</a>&lt;u8&gt;, v: <a href="">vector</a>&lt;u8&gt;, r: <a href="">vector</a>&lt;u8&gt;, s: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -52,7 +124,9 @@

## Function `sha2_256`

@param data: Arbitrary binary data to hash
@param data: Data to hash with SHA2-256.

@return hash: The result hash.

Hash function.

Expand All @@ -62,6 +136,59 @@ Hash function.



<a name="0x2_evm_ripemd_160"></a>

## Function `ripemd_160`

@param data: Data to hash with RIPEMD-160.

@return hash: The result 20-byte hash right aligned to 32 bytes.

Hash function.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_ripemd_160">ripemd_160</a>(data: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x2_evm_identity"></a>

## Function `identity`

@param data: Data to return.

@return data: Data from input.

Returns the input.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_identity">identity</a>(data: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x2_evm_modexp"></a>

## Function `modexp`

@param b_size: Byte size of B.
@param e_size: Byte size of E.
@param m_size: Byte size of M.
@param b: Base as unsigned integer.
@param e: Exponent as unsigned integer, if zero, then B ** E will be one.
@param m: Modulo as unsigned integer, if zero, then returns zero.

@return value: Result of the computation, with the same number of bytes as M.

Arbitrary-precision exponentiation under modulo.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_modexp">modexp</a>(b_size: <a href="">vector</a>&lt;u8&gt;, e_size: <a href="">vector</a>&lt;u8&gt;, m_size: <a href="">vector</a>&lt;u8&gt;, b: <a href="">vector</a>&lt;u8&gt;, e: <a href="">vector</a>&lt;u8&gt;, m: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x2_evm_ec_add"></a>

## Function `ec_add`
Expand All @@ -71,27 +198,94 @@ Hash function.
@param x2: X coordinate of the second point on the elliptic curve 'alt_bn128'.
@param y2: Y coordinate of the second point on the elliptic curve 'alt_bn128'.

@return x: X coordinate of the result point on the elliptic curve 'alt_bn128'.
@return y: Y coordinate of the result point on the elliptic curve 'alt_bn128'.

Notes: The point at infinity is encoded with both field x and y at 0.

Point addition (ADD) on the elliptic curve 'alt_bn128'
Point addition (ADD) on the elliptic curve 'alt_bn128'.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_ec_add">ec_add</a>(x1: <a href="">vector</a>&lt;u8&gt;, y1: <a href="">vector</a>&lt;u8&gt;, x2: <a href="">vector</a>&lt;u8&gt;, y2: <a href="">vector</a>&lt;u8&gt;): (<a href="">vector</a>&lt;u8&gt;, <a href="">vector</a>&lt;u8&gt;)
</code></pre>



<a name="0x2_evm_ec_mul"></a>

## Function `ec_mul`

@param x1: X coordinate of the first point on the elliptic curve 'alt_bn128'.
@param y1: Y coordinate of the first point on the elliptic curve 'alt_bn128'.
@param s: Scalar to use for the multiplication.

@return x: X coordinate of the result point on the elliptic curve 'alt_bn128'.
@return y: Y coordinate of the result point on the elliptic curve 'alt_bn128'.

Notes: The point at infinity is encoded with both field x and y at 0.

Scalar multiplication (MUL) on the elliptic curve 'alt_bn128'.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_ec_mul">ec_mul</a>(x1: <a href="">vector</a>&lt;u8&gt;, y1: <a href="">vector</a>&lt;u8&gt;, s: <a href="">vector</a>&lt;u8&gt;): (<a href="">vector</a>&lt;u8&gt;, <a href="">vector</a>&lt;u8&gt;)
</code></pre>



<a name="0x2_evm_ec_pairing"></a>

## Function `ec_pairing`

@param data: Coordinates of the points.
The input must always be a multiple of 6 32-byte values. 0 inputs is valid and returns 1.

@return success: 1 if the pairing was a success, 0 otherwise.

Notes: The point at infinity is encoded with both field x and y at 0.

Bilinear function on groups on the elliptic curve 'alt_bn128'.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_ec_pairing">ec_pairing</a>(data: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x2_evm_blake2f"></a>

## Function `blake2f`

@param rounds: Number of rounds (big-endian unsigned integer).
@param h: State vector (8 8-byte little-endian unsigned integer).
@param m: Message block vector (16 8-byte little-endian unsigned integer).
@param t: Offset counters (2 8-byte little-endian integer).
@param f: Final block indicator flag (0 or 1).

@return h: State vector (8 8-byte little-endian unsigned integer).

Compression function F used in the BLAKE2 cryptographic hashing algorithm.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_blake2f">blake2f</a>(rounds: <a href="">vector</a>&lt;u8&gt;, h: <a href="">vector</a>&lt;u8&gt;, m: <a href="">vector</a>&lt;u8&gt;, t: <a href="">vector</a>&lt;u8&gt;, f: <a href="">vector</a>&lt;u8&gt;): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x2_evm_point_evaluation"></a>

## Function `point_evaluation`

@param versioned_hash: Reference to a blob in the execution layer.
@param x: x-coordinate at which the blob is being evaluated.
@param y: y-coordinate at which the blob is being evaluated.
@param commitment: Commitment to the blob being evaluated.
@param proof: Proof associated with the commitment.

@return FIELD_ELEMENTS_PER_BLOB: The number of field elements in the blob.
@return : BLS_MODULUS: The modulus used in the BLS signature scheme.

Verify p(z) = y given commitment that corresponds to the polynomial p(x) and a KZG proof. Also verify that the provided commitment matches the provided versioned_hash.


<pre><code><b>public</b> <b>fun</b> <a href="evm.md#0x2_evm_point_evaluation">point_evaluation</a>(versioned_hash: <a href="">vector</a>&lt;u8&gt;, x: <a href="">vector</a>&lt;u8&gt;, y: <a href="">vector</a>&lt;u8&gt;, commitment: <a href="">vector</a>&lt;u8&gt;, proof: <a href="">vector</a>&lt;u8&gt;): (<a href="">vector</a>&lt;u8&gt;, <a href="">vector</a>&lt;u8&gt;)
</code></pre>
Loading
Loading