-
Notifications
You must be signed in to change notification settings - Fork 66
[Advanced]: Support Pectra EVM Type 4 Transaction Encoding (EIP-7702) #1052
Description
🧠 Advanced
This issue is well-suited for contributors who are very familiar with the Hiero C++ SDK and enjoy working with its core abstractions and design patterns.
Advanced Issues often involve:
- Exploring and shaping SDK architecture
- Reasoning about trade-offs and long-term impact
- Working across multiple modules or systems
- Updating tests, examples, and documentation alongside code
The goal is to support thoughtful, high-impact contributions in a clear and collaborative way.
🐞 Problem Description
As part of the upcoming Pectra upgrade to Hiero networks, EIP-7702: Set Code for EOAs introduces Type 4 transactions (also known as SET_CODE_TX_TYPE). This new transaction type allows Externally Owned Accounts (EOAs) to delegate code execution to smart contracts, enabling features like:
- Transaction batching
- Sponsored/gasless transactions
- Session keys and permissioned sub-keys
- Smart wallet capabilities while preserving EOA identity
The Hiero C++ SDK currently does not support encoding or decoding Type 4 transactions. To prepare for the Pectra upgrade, the SDK must be able to construct and send these transactions to consensus nodes.
Technical Background
Type 4 transactions introduce a new RLP-encoded structure with an authorization list:
rlp([
chain_id,
nonce,
max_priority_fee_per_gas,
max_fee_per_gas,
gas_limit,
destination,
value,
data,
access_list,
authorization_list, // NEW: list of authorization tuples
signature_y_parity,
signature_r,
signature_s
])
Each entry in authorization_list is a tuple:
[ chain_id, address, nonce, y_parity, r, s ]
Where the authority (EOA) signs over keccak(MAGIC || rlp([chain_id, address, nonce])) with MAGIC = 0x05.
Key Parameters
| Parameter | Value |
|---|---|
SET_CODE_TX_TYPE |
0x04 |
MAGIC |
0x05 |
PER_AUTH_BASE_COST |
12,500 gas |
PER_EMPTY_ACCOUNT_COST |
25,000 gas |
💡 Proposed / Expected Outcome
Implement full SDK support for EIP-7702 Type 4 transactions, including:
- New data structures for authorization tuples and authorization lists
- RLP encoding/decoding for Type 4 transaction format
- Signature handling for authorization tuple signing (MAGIC prefix, proper hashing)
- Integration with existing
EthereumTransactioninfrastructure - Validation of chain IDs, nonces, and signature parameters
- Public API that allows users to construct and sign Type 4 transactions
The implementation should:
- Follow patterns established in other Hiero SDKs for consistency
- Preserve backwards compatibility with existing transaction types
- Provide clear, actionable error messages for invalid inputs
- Be well-documented with usage examples
🧠 Implementation & Design Notes
Suggested Approach
-
Review the design document:
HIP-1340 sdk-collaboration-hub#118 -
Study EIP-7702 specification:
https://eips.ethereum.org/EIPS/eip-7702 -
Identify affected areas in the C++ SDK:
src/sdk/main/src/- Transaction classes and encodingsrc/sdk/main/include/- Public API headers- Existing
EthereumTransactionimplementation for patterns
-
Design new classes/structures:
AuthorizationTupleor similar for individual authorizations- Extension to
EthereumTransactionor new transaction class for Type 4
-
Implement RLP encoding:
- Handle the new authorization_list field
- Ensure proper serialization order and types
-
Implement signature logic:
- MAGIC prefix (
0x05) for authorization signing - Proper keccak hashing of authorization data
- Signature validation (s <= secp256k1n/2 per EIP-2)
- MAGIC prefix (
-
Add comprehensive tests:
- Unit tests for encoding/decoding
- Integration tests for transaction submission
- Edge cases (empty authorization list, multiple authorizations, etc.)
-
Provide usage example(s):
- Demonstrate constructing a Type 4 transaction
- Show how to create and sign authorization tuples
Key Considerations
- Chain ID validation: Authorization tuples can have chain_id = 0 (valid on all chains) or must match the current chain
- Nonce handling: Each authorization increments the authority's nonce
- Delegation indicator: The code set on delegation is
0xef0100 || address - Gas calculations: Include
PER_EMPTY_ACCOUNT_COST * authorization_list.lengthin intrinsic gas
✅ Acceptance Criteria
A pull request for this issue should:
- Implement Type 4 transaction encoding per EIP-7702 specification
- Implement authorization tuple/list data structures
- Implement proper signature handling for authorizations (MAGIC prefix)
- Integrate with existing
EthereumTransactioninfrastructure - Maintain backwards compatibility with existing transaction types
- Follow existing architectural and C++ conventions in the SDK
- Include comprehensive unit and integration tests
- Provide at least one usage example
- Update relevant documentation
- Pass all CI checks
📚 Additional Context, Links, or Prior Art
Design Document
- SDK Collaboration Hub PR # 118: HIP-1340 sdk-collaboration-hub#118
Specifications
- EIP-7702 (Set Code for EOAs): https://eips.ethereum.org/EIPS/eip-7702
- EIP-2718 (Typed Transaction Envelope): https://eips.ethereum.org/EIPS/eip-2718
Related Resources
- Pectra Upgrade Info: https://pectra.org/
- EIP-7702 Security Considerations: Authorization signatures can be phished; the SDK should provide clear warnings/documentation about risks
Cross-SDK Alignment
This implementation should align with patterns used in other Hiero SDKs. Check the design document for cross-SDK consistency requirements.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status