Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

alexandria_evm

Fully qualified path: alexandria_evm

Modules

Modules

Modules

constants

Fully qualified path: alexandria_evm::constants

Constants

Constants

Constants

FELT252_MAX

Fully qualified path: alexandria_evm::constants::FELT252_MAX

pub const FELT252_MAX: felt252 =
    3618502788666131213697322783095070105623107215331596699973092056135872020480;

decoder

Fully qualified path: alexandria_evm::decoder

Traits

Impls

Traits

Traits

AbiDecodeTrait

Fully qualified path: alexandria_evm::decoder::AbiDecodeTrait

pub trait AbiDecodeTrait

Trait functions

decode

Decodes EVM calldata for the specified types into a Span of felt252 values.

This function is the primary entry point for decoding EVM calldata in Starknet Cairo. It accepts a list of EVM-compatible types and decodes values from calldata accordingly. The resulting span of felt252 values can be directly used in Starknet’s call_syscall.

This function is typically implemented as a dispatcher that calls appropriate decoding routines (e.g., decode_uint, decode_tuple, decode_array, etc.) based on the types passed in.

Arguments

  • self - Reference to EVMCalldata context which maintains the calldata byte array, current offset, and relative offset for dynamic type resolution.
  • types - A list (Span) of EVMTypes to decode from the current calldata position.

Returns

  • Span<felt252> - A Cairo Span containing the decoded values as felt252

Fully qualified path: alexandria_evm::decoder::AbiDecodeTrait::decode

fn decode(ref self: EVMCalldata, types: Span<EVMTypes>) -> Span<felt252>

Impls

Impls

EVMTypesImpl

Fully qualified path: alexandria_evm::decoder::EVMTypesImpl

pub impl EVMTypesImpl of AbiDecodeTrait;

Impl functions

decode

Fully qualified path: alexandria_evm::decoder::EVMTypesImpl::decode

fn decode(ref self: EVMCalldata, types: Span<EVMTypes>) -> Span<felt252>

encoder

Fully qualified path: alexandria_evm::encoder

Structs

Traits

Impls

Structs

Structs

EVMCalldata

Fully qualified path: alexandria_evm::encoder::EVMCalldata

[derive(Clone, Drop, Serde)]
pub struct EVMCalldata {
    pub calldata: ByteArray,
    pub offset: u32,
    pub dynamic_data: ByteArray,
    pub dynamic_offset: u32,
}

Members

calldata

Fully qualified path: alexandria_evm::encoder::EVMCalldata::calldata

pub calldata: ByteArray

offset

Fully qualified path: alexandria_evm::encoder::EVMCalldata::offset

pub offset: u32

dynamic_data

Fully qualified path: alexandria_evm::encoder::EVMCalldata::dynamic_data

pub dynamic_data: ByteArray

dynamic_offset

Fully qualified path: alexandria_evm::encoder::EVMCalldata::dynamic_offset

pub dynamic_offset: u32

Traits

Traits

AbiEncodeTrait

Fully qualified path: alexandria_evm::encoder::AbiEncodeTrait

pub trait AbiEncodeTrait

Trait functions

encode

Encodes felt252 values into EVM calldata for the specified types.

This function is the primary entry point for encoding values into EVM-compatible calldata in Starknet Cairo. It accepts a list of EVM-compatible types and a corresponding list of felt252 values, then encodes them according to EVM ABI encoding standards.

This function is typically implemented as a dispatcher that calls appropriate encoding routines (e.g., encode_uint, encode_tuple, encode_array, etc.) based on the types passed in.

Arguments

  • self - Reference to EVMCalldata context which maintains the calldata byte array, current offset, dynamic data section and dynamic offset.
  • types - A list (Span) of EVMTypes to encode.
  • values - A list (Span) of felt252 values to encode according to the types.

Returns

  • ByteArray - The encoded EVM calldata as a byte array.

Usage

This function is typically called when preparing calldata for EVM contract calls from within Cairo smart contracts.

Fully qualified path: alexandria_evm::encoder::AbiEncodeTrait::encode

fn encode(ref self: EVMCalldata, types: Span<EVMTypes>, values: Span<felt252>) -> ByteArray

Impls

Impls

EVMTypesImpl

Fully qualified path: alexandria_evm::encoder::EVMTypesImpl

pub impl EVMTypesImpl of AbiEncodeTrait;

Impl functions

encode

Fully qualified path: alexandria_evm::encoder::EVMTypesImpl::encode

fn encode(ref self: EVMCalldata, types: Span<EVMTypes>, values: Span<felt252>) -> ByteArray

evm_enum

Fully qualified path: alexandria_evm::evm_enum

Enums

Enums

Enums

EVMTypes

Fully qualified path: alexandria_evm::evm_enum::EVMTypes

pub enum EVMTypes {
    Tuple: Span<EVMTypes>,
    Array: Span<EVMTypes>,
    FunctionSignature,
    Address,
    Bool,
    Uint8,
    Uint16,
    Uint24,
    Uint32,
    Uint40,
    Uint48,
    Uint56,
    Uint64,
    Uint72,
    Uint80,
    Uint88,
    Uint96,
    Uint104,
    Uint112,
    Uint120,
    Uint128,
    Uint136,
    Uint144,
    Uint152,
    Uint160,
    Uint168,
    Uint176,
    Uint184,
    Uint192,
    Uint200,
    Uint208,
    Uint216,
    Uint224,
    Uint232,
    Uint240,
    Uint248,
    Uint256,
    Int8,
    Int16,
    Int24,
    Int32,
    Int40,
    Int48,
    Int56,
    Int64,
    Int72,
    Int80,
    Int88,
    Int96,
    Int104,
    Int112,
    Int120,
    Int128,
    Int136,
    Int144,
    Int152,
    Int160,
    Int168,
    Int176,
    Int184,
    Int192,
    Int200,
    Int208,
    Int216,
    Int224,
    Int232,
    Int240,
    Int248,
    Int256,
    Bytes1,
    Bytes2,
    Bytes3,
    Bytes4,
    Bytes5,
    Bytes6,
    Bytes7,
    Bytes8,
    Bytes9,
    Bytes10,
    Bytes11,
    Bytes12,
    Bytes13,
    Bytes14,
    Bytes15,
    Bytes16,
    Bytes17,
    Bytes18,
    Bytes19,
    Bytes20,
    Bytes21,
    Bytes22,
    Bytes23,
    Bytes24,
    Bytes25,
    Bytes26,
    Bytes27,
    Bytes28,
    Bytes29,
    Bytes30,
    Bytes31,
    Bytes32,
    Bytes,
    String,
    Felt252,
}

Variants

Tuple

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Tuple

Tuple: Span<EVMTypes>

Array

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Array

Array: Span<EVMTypes>

FunctionSignature

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::FunctionSignature

FunctionSignature

Address

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Address

Address

Bool

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bool

Bool

Uint8

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint8

Uint8

Uint16

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint16

Uint16

Uint24

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint24

Uint24

Uint32

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint32

Uint32

Uint40

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint40

Uint40

Uint48

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint48

Uint48

Uint56

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint56

Uint56

Uint64

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint64

Uint64

Uint72

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint72

Uint72

Uint80

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint80

Uint80

Uint88

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint88

Uint88

Uint96

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint96

Uint96

Uint104

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint104

Uint104

Uint112

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint112

Uint112

Uint120

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint120

Uint120

Uint128

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint128

Uint128

Uint136

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint136

Uint136

Uint144

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint144

Uint144

Uint152

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint152

Uint152

Uint160

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint160

Uint160

Uint168

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint168

Uint168

Uint176

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint176

Uint176

Uint184

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint184

Uint184

Uint192

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint192

Uint192

Uint200

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint200

Uint200

Uint208

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint208

Uint208

Uint216

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint216

Uint216

Uint224

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint224

Uint224

Uint232

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint232

Uint232

Uint240

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint240

Uint240

Uint248

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint248

Uint248

Uint256

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Uint256

Uint256

Int8

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int8

Int8

Int16

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int16

Int16

Int24

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int24

Int24

Int32

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int32

Int32

Int40

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int40

Int40

Int48

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int48

Int48

Int56

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int56

Int56

Int64

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int64

Int64

Int72

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int72

Int72

Int80

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int80

Int80

Int88

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int88

Int88

Int96

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int96

Int96

Int104

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int104

Int104

Int112

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int112

Int112

Int120

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int120

Int120

Int128

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int128

Int128

Int136

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int136

Int136

Int144

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int144

Int144

Int152

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int152

Int152

Int160

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int160

Int160

Int168

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int168

Int168

Int176

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int176

Int176

Int184

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int184

Int184

Int192

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int192

Int192

Int200

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int200

Int200

Int208

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int208

Int208

Int216

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int216

Int216

Int224

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int224

Int224

Int232

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int232

Int232

Int240

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int240

Int240

Int248

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int248

Int248

Int256

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Int256

Int256

Bytes1

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes1

Bytes1

Bytes2

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes2

Bytes2

Bytes3

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes3

Bytes3

Bytes4

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes4

Bytes4

Bytes5

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes5

Bytes5

Bytes6

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes6

Bytes6

Bytes7

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes7

Bytes7

Bytes8

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes8

Bytes8

Bytes9

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes9

Bytes9

Bytes10

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes10

Bytes10

Bytes11

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes11

Bytes11

Bytes12

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes12

Bytes12

Bytes13

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes13

Bytes13

Bytes14

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes14

Bytes14

Bytes15

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes15

Bytes15

Bytes16

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes16

Bytes16

Bytes17

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes17

Bytes17

Bytes18

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes18

Bytes18

Bytes19

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes19

Bytes19

Bytes20

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes20

Bytes20

Bytes21

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes21

Bytes21

Bytes22

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes22

Bytes22

Bytes23

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes23

Bytes23

Bytes24

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes24

Bytes24

Bytes25

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes25

Bytes25

Bytes26

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes26

Bytes26

Bytes27

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes27

Bytes27

Bytes28

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes28

Bytes28

Bytes29

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes29

Bytes29

Bytes30

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes30

Bytes30

Bytes31

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes31

Bytes31

Bytes32

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes32

Bytes32

Bytes

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Bytes

Bytes

String

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::String

String

Felt252

Fully qualified path: alexandria_evm::evm_enum::EVMTypes::Felt252

Felt252

evm_struct

Fully qualified path: alexandria_evm::evm_struct

Structs

Structs

Structs

EVMCalldata

Fully qualified path: alexandria_evm::evm_struct::EVMCalldata

[derive(Clone, Drop, Serde)]
pub struct EVMCalldata {
    pub calldata: ByteArray,
    pub offset: u32,
    pub relative_offset: u32,
}

Members

calldata

Fully qualified path: alexandria_evm::evm_struct::EVMCalldata::calldata

pub calldata: ByteArray

offset

Fully qualified path: alexandria_evm::evm_struct::EVMCalldata::offset

pub offset: u32

relative_offset

Fully qualified path: alexandria_evm::evm_struct::EVMCalldata::relative_offset

pub relative_offset: u32

selector

Fully qualified path: alexandria_evm::selector

Traits

Impls

Traits

Traits

SelectorTrait

Fully qualified path: alexandria_evm::selector::SelectorTrait

pub trait SelectorTrait

Trait functions

compute_selector

Computes the EVM function selector (first 4 bytes of the Keccak-256 hash of a function signature).

Arguments

  • self - A ByteArray containing the UTF-8 string of the function signature, e.g., "transfer(address,uint256)".

Returns

  • felt252 - The 4-byte (32-bit) selector represented as a felt252 value.

Fully qualified path: alexandria_evm::selector::SelectorTrait::compute_selector

fn compute_selector(self: ByteArray) -> felt252

Impls

Impls

SelectorImpl

Fully qualified path: alexandria_evm::selector::SelectorImpl

pub impl SelectorImpl of SelectorTrait;

Impl functions

compute_selector

Computes the EVM function selector (first 4 bytes of the Keccak-256 hash of a function signature).

Arguments

  • self - A ByteArray containing the UTF-8 string of the function signature, e.g., "transfer(address,uint256)".

Returns

  • felt252 - The 4-byte (32-bit) selector represented as a felt252 value.

Fully qualified path: alexandria_evm::selector::SelectorImpl::compute_selector

fn compute_selector(self: ByteArray) -> felt252

signature

Fully qualified path: alexandria_evm::signature

Traits

Impls

Traits

Traits

SignatureTrait

Fully qualified path: alexandria_evm::signature::SignatureTrait

pub trait SignatureTrait

Trait functions

verify_signature

Verifies an Ethereum signature against a message hash and an Ethereum address.

This function expects a 65-byte signature (r, s, v) in the standard Ethereum format. It extracts the components, builds a Signature struct, and calls the verification routine.

Arguments

  • msg_hash - The hash of the signed message (typically a Keccak256 hash of a message prefix + payload).
  • signature - The 65-byte signature as a ByteArray: r (32 bytes) | s (32 bytes) | v (1 byte).
  • eth_address - The Ethereum address expected to have signed the message.

Fully qualified path: alexandria_evm::signature::SignatureTrait::verify_signature

fn verify_signature(msg_hash: u256, signature: ByteArray, eth_address: EthAddress)

Impls

Impls

SignatureImpl

Fully qualified path: alexandria_evm::signature::SignatureImpl

pub impl SignatureImpl of SignatureTrait;

Impl functions

verify_signature

Verifies an Ethereum signature against a message hash and an Ethereum address.

This function expects a 65-byte signature (r, s, v) in the standard Ethereum format. It extracts the components, builds a Signature struct, and calls the verification routine.

Arguments

  • msg_hash - The hash of the signed message (typically a Keccak256 hash of a message prefix + payload).
  • signature - The 65-byte signature as a ByteArray: r (32 bytes) | s (32 bytes) | v (1 byte).
  • eth_address - The Ethereum address expected to have signed the message.

Fully qualified path: alexandria_evm::signature::SignatureImpl::verify_signature

fn verify_signature(msg_hash: u256, signature: ByteArray, eth_address: EthAddress)

utils

Fully qualified path: alexandria_evm::utils

Free functions

has_dynamicChecks if any of the provided EVM types are dynamic. Dynamic types in Solidity/EVM include arrays, strings, and bytes. These types are not encoded inline and instead use an offset pointing to…
is_dynamic_typeChecks if a single EVM type is dynamic….

Free functions

Free functions

has_dynamicChecks if any of the provided EVM types are dynamic. Dynamic types in Solidity/EVM include arrays, strings, and bytes. These types are not encoded inline and instead use an offset pointing to…
is_dynamic_typeChecks if a single EVM type is dynamic….

has_dynamic

Checks if any of the provided EVM types are dynamic.

Dynamic types in Solidity/EVM include arrays, strings, and bytes. These types are not encoded inline and instead use an offset pointing to their actual data location elsewhere in calldata. This helper is used to determine if special encoding/decoding logic is needed.

Arguments

  • types - A span of EVMTypes representing the types to check.

Returns

  • true if any type is dynamic; otherwise, false.

Examples

let static_types = array![EVMTypes::Uint256, EVMTypes::Address].span();
assert!(!has_dynamic(static_types));

let dynamic_types = array![EVMTypes::Uint256, EVMTypes::Bytes].span();
assert!(has_dynamic(dynamic_types));

Fully qualified path: alexandria_evm::utils::has_dynamic

pub fn has_dynamic(types: Span<EVMTypes>) -> bool

is_dynamic_type

Checks if a single EVM type is dynamic.

Arguments

  • evm_type - The EVM type to check.

Returns

  • true if the type is dynamic; otherwise, false.

Fully qualified path: alexandria_evm::utils::is_dynamic_type

pub fn is_dynamic_type(evm_type: @EVMTypes) -> bool