Expand description
Host functions overrides for Ethereum address recovery.
The host functions overriding is required because of impersonation feature.
Impersonation is used for sending/executing transactions with a signer
where its private key is unknown. Sent transactions require a signature
that is obtained with sender’s private key and the pallet-revive
runtime logic can recover the signer’s ethereum address from the signature
and the rest of the transaction bytes. The runtime recovers the signer’s
address by running secp256k1_ecdsa_recover to recover the signer’s public
key, and keccak_256 to hash the public key to a 20 byes Ethereum address.
These functions are exposed by sp-io and used as host functions by the runtime.
This module implements tweaked versions of the host functions from sp-io, which
can recognize fake signatures used for impersonated transactions, and can recover
the signer address from them, while expecting those fake signatures to be built in
a certain way ([0; 12] + sender’s Ethereum address + [IMPERSONATION_MARKER; 32] + recovery_id).
The tweaked host functions are especially useful in the context of overriding the
same sp-io host functions in the wasm executor type.
Modules§
Constants§
- IMPERSONATION_
MARKER - Magic marker used to identify impersonated transactions. Using 0xDE for “DEfake” - a distinctive pattern that won’t collide with legitimate EVM data. Previously we used [0; 33] but this collided with Solidity mapping key computations for slot 0 (which also have 32 trailing zero bytes).
Functions§
- is_
impersonated - recover_
maybe_ impersonated_ address - Recover sender address from signed transaction, handling impersonated transactions. For impersonated transactions (fake signatures), extracts the address embedded in the signature. For normal transactions, performs standard ECDSA recovery.
Type Aliases§
- Public
KeyTo Hash Override - Provides host function that override hashing functions in the scope of impersonation.
- Sender
Address Recovery Override - Provides host function that overrides ETH address recovery from signature in the scope of impersonation.