|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
RLP encoder implementation for EIP-1559 (type 2) transactions. More...
Go to the source code of this file.
Macros | |
| #define | ITEMS_BUF_MAX 320U |
| #define | ITEMS_FIXED_MAX 160U |
| #define | CALLDATA_MAX (ITEMS_BUF_MAX - ITEMS_FIXED_MAX) |
Functions | |
| static uint8_t | be_minimal (uint64_t value, uint8_t out[8]) |
Write value as a minimal big-endian byte sequence. | |
| static size_t | rlp_bytes (const uint8_t *data, size_t data_len, uint8_t *out, size_t out_cap) |
| RLP-encode a byte string. | |
| static size_t | rlp_uint64 (uint64_t value, uint8_t *out, size_t out_cap) |
| RLP-encode a non-negative integer. | |
| static size_t | rlp_int256 (const uint8_t data[32], uint8_t *out, size_t out_cap) |
| RLP-encode a 32-byte big-endian integer (e.g. ECDSA r or s). | |
| static size_t | rlp_list_header (size_t content_len, uint8_t *out, size_t out_cap) |
Write the RLP list header for a list of content_len bytes. | |
| static size_t | encode_common_fields (const eth_tx_t *tx, uint8_t *items, size_t items_cap) |
| Encode the nine common EIP-1559 fields into the items buffer. | |
| size_t | eth_rlp_encode_unsigned (const eth_tx_t *tx, uint8_t *out, size_t out_max) |
| Encode an unsigned EIP-1559 transaction: 0x02 || RLP([chainId, nonce, ...]). | |
| size_t | eth_rlp_encode_signed (const eth_tx_t *tx, uint8_t v, const uint8_t r[32], const uint8_t s[32], uint8_t *out, size_t out_max) |
| Encode a signed EIP-1559 transaction: 0x02 || RLP([..., v, r, s]). | |
RLP encoder implementation for EIP-1559 (type 2) transactions.
Definition in file eth_rlp.cpp.
| #define CALLDATA_MAX (ITEMS_BUF_MAX - ITEMS_FIXED_MAX) |
Definition at line 33 of file eth_rlp.cpp.
Referenced by encode_common_fields().
| #define ITEMS_BUF_MAX 320U |
Definition at line 23 of file eth_rlp.cpp.
Referenced by eth_rlp_encode_signed(), and eth_rlp_encode_unsigned().
| #define ITEMS_FIXED_MAX 160U |
Definition at line 32 of file eth_rlp.cpp.
|
static |
Write value as a minimal big-endian byte sequence.
Value 0 produces one 0x00 byte; the caller is responsible for treating the empty-integer case (value==0 -> RLP 0x80) before calling this function.
| [in] | value | Integer to encode. |
| [out] | out | Output buffer (exactly 8 bytes; up to 8 used). |
Definition at line 55 of file eth_rlp.cpp.
Referenced by rlp_bytes(), rlp_list_header(), and rlp_uint64().
|
static |
Encode the nine common EIP-1559 fields into the items buffer.
The calldata length is bounds-checked up front against CALLDATA_MAX so the fixed-size items buffer can never overflow.
| [in] | tx | Transaction to encode. |
| [out] | items | Scratch buffer. |
| [in] | items_cap | Capacity of items (>= ITEMS_BUF_MAX). |
Definition at line 215 of file eth_rlp.cpp.
References eth_tx_t::calldata, eth_tx_t::calldata_len, CALLDATA_MAX, eth_tx_t::chain_id, eth_tx_t::eth_value, eth_tx_t::gas_limit, eth_tx_t::max_fee, eth_tx_t::max_priority_fee, eth_tx_t::nonce, rlp_bytes(), rlp_uint64(), and eth_tx_t::to.
Referenced by eth_rlp_encode_signed(), and eth_rlp_encode_unsigned().
| size_t eth_rlp_encode_signed | ( | const eth_tx_t * | tx, |
| uint8_t | v, | ||
| const uint8_t | r[32], | ||
| const uint8_t | s[32], | ||
| uint8_t * | out, | ||
| size_t | out_max ) |
Encode a signed EIP-1559 transaction: 0x02 || RLP([..., v, r, s]).
| [in] | tx | Transaction parameters. |
| [in] | v | Signature parity bit; must be 0 or 1. |
| [in] | r | 32-byte big-endian ECDSA r component. |
| [in] | s | 32-byte big-endian ECDSA s component. |
| [out] | out | Output buffer for the encoded bytes. |
| [in] | out_max | Capacity of out. |
out_max or tx->calldata_len exceeds the internal scratch bound. Definition at line 268 of file eth_rlp.cpp.
References encode_common_fields(), ITEMS_BUF_MAX, rlp_int256(), rlp_list_header(), and rlp_uint64().
Referenced by sign_and_broadcast().
| size_t eth_rlp_encode_unsigned | ( | const eth_tx_t * | tx, |
| uint8_t * | out, | ||
| size_t | out_max ) |
Encode an unsigned EIP-1559 transaction: 0x02 || RLP([chainId, nonce, ...]).
| [in] | tx | Transaction parameters. |
| [out] | out | Output buffer for the encoded bytes. |
| [in] | out_max | Capacity of out. |
out_max or tx->calldata_len exceeds the internal scratch bound. Definition at line 244 of file eth_rlp.cpp.
References encode_common_fields(), ITEMS_BUF_MAX, and rlp_list_header().
Referenced by sign_and_broadcast().
|
static |
RLP-encode a byte string.
| [in] | data | Input bytes. |
| [in] | data_len | Number of input bytes. |
| [out] | out | Output buffer. |
| [in] | out_cap | Capacity of out. |
out_cap is too small. Definition at line 89 of file eth_rlp.cpp.
References be_minimal().
Referenced by encode_common_fields(), rlp_int256(), and rlp_uint64().
|
static |
RLP-encode a 32-byte big-endian integer (e.g. ECDSA r or s).
Leading zero bytes are stripped so the encoding is minimal.
| [in] | data | 32-byte big-endian integer. |
| [out] | out | Output buffer. |
| [in] | out_cap | Capacity of out. |
out_cap is too small. Definition at line 159 of file eth_rlp.cpp.
References rlp_bytes().
Referenced by eth_rlp_encode_signed().
|
static |
Write the RLP list header for a list of content_len bytes.
| [in] | content_len | Length of the list content (not written here). |
| [out] | out | Output buffer. |
| [in] | out_cap | Capacity of out. |
out_cap is too small. Definition at line 182 of file eth_rlp.cpp.
References be_minimal().
Referenced by eth_rlp_encode_signed(), and eth_rlp_encode_unsigned().
|
static |
RLP-encode a non-negative integer.
0 is encoded as the empty byte string (0x80).
| [in] | value | Integer to encode. |
| [out] | out | Output buffer. |
| [in] | out_cap | Capacity of out. |
out_cap is too small. Definition at line 137 of file eth_rlp.cpp.
References be_minimal(), and rlp_bytes().
Referenced by encode_common_fields(), and eth_rlp_encode_signed().