Skip to content

Latest commit

 

History

History
291 lines (140 loc) · 8.66 KB

evm.md

File metadata and controls

291 lines (140 loc) · 8.66 KB

Module 0x2::evm

use 0x1::hash;
use 0x2::hash;

Constants

const ErrorBlake2fFailed: u64 = 9;

const ErrorEcAddFailed: u64 = 6;

const ErrorEcMulFailed: u64 = 7;

const ErrorEcPairingFailed: u64 = 8;

const ErrorEcRecoverFailed: u64 = 1;

const ErrorInvalidInputSize: u64 = 11;

const ErrorModexpFailed: u64 = 5;

const ErrorPointEvaluationFailed: u64 = 10;

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.

public fun ec_recover(hash: vector<u8>, v: vector<u8>, r: vector<u8>, s: vector<u8>): vector<u8>

Function sha2_256

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

@return hash: The result hash.

Hash function.

public fun sha2_256(data: vector<u8>): vector<u8>

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.

public fun ripemd_160(data: vector<u8>): vector<u8>

Function identity

@param data: Data to return.

@return data: Data from input.

Returns the input.

public fun identity(data: vector<u8>): vector<u8>

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.

public fun modexp(b_size: vector<u8>, e_size: vector<u8>, m_size: vector<u8>, b: vector<u8>, e: vector<u8>, m: vector<u8>): vector<u8>

Function ec_add

@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 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'.

public fun ec_add(x1: vector<u8>, y1: vector<u8>, x2: vector<u8>, y2: vector<u8>): (vector<u8>, vector<u8>)

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'.

public fun ec_mul(x1: vector<u8>, y1: vector<u8>, s: vector<u8>): (vector<u8>, vector<u8>)

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'.

public fun ec_pairing(data: vector<u8>): vector<u8>

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.

public fun blake2f(rounds: vector<u8>, h: vector<u8>, m: vector<u8>, t: vector<u8>, f: vector<u8>): vector<u8>

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.

public fun point_evaluation(versioned_hash: vector<u8>, x: vector<u8>, y: vector<u8>, commitment: vector<u8>, proof: vector<u8>): (vector<u8>, vector<u8>)