Download the PHP package amashukov/rlp-php without Composer
On this page you can find all versions of the php package amashukov/rlp-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amashukov/rlp-php
More information about amashukov/rlp-php
Files in amashukov/rlp-php
Package rlp-php
Short Description RLP (Recursive Length Prefix) encoder and decoder in pure PHP — Ethereum's canonical serialization for transactions, blocks, and state trie.
License MIT
Informations about the package rlp-php
amashukov/rlp-php
Pure-PHP RLP (Recursive Length Prefix) encoder and decoder — Ethereum's canonical serialization for transactions, blocks and the state trie.
amashukov/rlp-php is a pure-PHP implementation of RLP (Recursive Length Prefix), the canonical serialization format used throughout Ethereum and the EVM for transactions, blocks and the Merkle-Patricia state trie. It encodes and decodes nested byte-string structures and minimal big-endian integers, and enforces strict RLP canonicality on decode to defend against malleable encodings.
The package is a leaf primitive — zero composer dependencies, just ext-gmp for big-integer encoding helpers.
Features
- Encode & decode arbitrarily nested lists of byte-strings.
- Integer encoding in Ethereum's minimal big-endian convention, including big integers via decimal strings.
- Strict canonical decode — rejects non-canonical length prefixes, leading-zero lengths, trailing bytes and truncated input.
- Stream decoding for parsing concatenated RLP items (e.g. a sequence of transactions).
- Zero composer dependencies —
ext-gmponly. - PHPStan level 9 clean,
@PER-CSformatted, CI-tested.
Installation
Usage
Encode
Encode integers (Ethereum convention: minimal big-endian)
Decode
Leaves are always returned as raw byte strings; integers are the caller's interpretation step.
Stream decoding
For parsing concatenated RLP items (e.g. a stream of transactions), use decodeStream:
Canonical decoding
decode() enforces RLP canonicality. The following inputs are rejected with InvalidArgumentException:
- A single byte < 0x80 wrapped in a long-form prefix (
0x81 0x00). - A short string encoded as a long string (length < 56 with
0xb8…prefix). - A short list encoded as a long list (payload length < 56 with
0xf8…prefix). - A long-form length with a leading zero byte (
0xb9 0x00 0x38 …). - Trailing bytes after the root item.
- Truncated input where the declared length exceeds the available bytes.
These checks defend downstream consumers against malleable transaction encodings and trie tampering.
Requirements
- PHP 8.3+
ext-gmp
No composer dependencies.
Related packages
Part of a modular pure-PHP blockchain toolkit:
| Package | Purpose |
|---|---|
| amashukov/keccak-php | Keccak-256 / SHA-3 / SHAKE hashing |
| amashukov/secp256k1-php | secp256k1 ECDSA sign / verify / recover |
| amashukov/rlp-php | Ethereum RLP encode / decode |
| amashukov/ton-cell-php | TON TLB Cell / Builder / Slice / BOC |
| amashukov/eip1559-tx-signer-php | EIP-1559 transaction signer |
| amashukov/abi-encoder-php | Ethereum ABI encoder |
| amashukov/eth-rpc-client-php | Ethereum JSON-RPC client |
| amashukov/eth-php | EVM umbrella package |
Quality
- PHPStan level 9.
- php-cs-fixer with the
@PER-CSruleset. - GitHub Actions CI on every push.
- Test vectors validated against the Ethereum RLP / Yellow Paper reference outputs.
Reference
- Ethereum RLP specification: https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/
- Yellow Paper §B (Recursive Length Prefix): https://ethereum.github.io/yellowpaper/paper.pdf
License
MIT License.
All versions of rlp-php with dependencies
ext-gmp Version *