EIP-155
The EIP-155 “Simple Replay Attack Protection” standard specifies a replay-attack-protected transaction encoding, which includes a chain identifier inside the transaction data, prior to signing.
- This ensures that transactions created for one blockchain are invalid on another blockchain. Therefore, transactions broadcast on one network cannot be replayed on another.
| Chain | Chain ID |
|---|---|
| Ethereum mainnet | 1 |
| Ropsten | 3 |
| Rinkeby | 4 |
EIP-155 took effect after the Spurious Dragon hard fork (FORK_BLKNUM 2,675,000, CHAIN_ID 1).
- If
block.number>=FORK_BLKNUMandCHAIN_IDis available, then when computing the hash of a transaction for the purposes of signing, instead of hashing only six rlp encoded elements(nonce, gasprice, startgas, to, value, data), you SHOULD hash nine rlp encoded elements(nonce, gasprice, startgas, to, value, data, chainid, 0, 0). If you do, then thevof the signature MUST be set to $$\{0,1\} + CHAIN\_ID * 2 + 35$$ where $$\{0,1\}$$ is the parity of the $$y$$ value of the curve point for whichris the $$x$$-value in thesecp256k1signing process.- If you choose to only hash 6 values, then
vcontinues to be set to $$\{0,1\} + 27$$ as previously.
- If you choose to only hash 6 values, then
- If
block.number >= FORK_BLKNUMand $$v = CHAIN\_ID * 2 + 35$$ or $$v = CHAIN\_ID * 2 + 36$$, then when computing the hash of a transaction for purposes of recovering, instead of hashing six rlp encoded elements(nonce, gasprice, startgas, to, value, data), hash nine rlp encoded elements(nonce, gasprice, startgas, to, value, data, chainid, 0, 0).- The currently existing signature scheme using $$v = 27$$ and $$v = 28$$ remains valid and continues to operate under the same rules as it did previously.
Public Key Recovery
Given an ECDSA signature $$(r, s)$$ and EC domain parameters, it is generally possible to determine the public key $$Q$$, at least to within a small number of choices.
- This is useful for generating self-signed signatures; also useful in bandwidth constrained environments when transmission of public keys cannot be afforded.
Potentially, several candidate public keys can be recovered from a signature. At a small cost, the signer can generate the ECDSA signature in such a way that only one of the candidate public keys is viable, and such that the verifier has a very small additional cost of determining which is the correct public key.
- 公钥是椭圆曲线上的点,椭圆曲线坐标 $$x, y \in [0, p-1]$$,而签名 $$r, s \in [1, n-1]$$,$$p > n$$,所以会存在多个点对应同一个 $$r$$ 的情况。
v of the signature makes the recovery process more efficient,.
ecrecover implementation:
| |
Value of recid:
- 0 -
yis even,xis finite - 1 -
yis odd,xis finite - 2 -
yis even,xis too large - 3 -
yis odd,xis too large
References