I have a fair understanding of how ecrecover
works, but I don't know how to enforce a parameter set that will deterministically return the 0x0
address. I need this in my contract tests.
Is this even possible?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI stumbled upon this thread, then I discovered this document and I now understand that setting v
as any (positive?) number other than 27 or 28 will deterministically return 0x0
as the origin signer address.
Test it for yourself in solidity:
function getSignerZero(bytes32 msgHash, bytes32 r, bytes32 s) public returns (address _signer) {
uint8 wrongV = 17; // should normally be 27 or 28
return ecrecover(msgHash, wrongV, r, s);
}
Also, a caveat if you're using assembly and staticcall
: it's actually incorrect to say that the value returned is 0x0. What happens there is that the precompile never gets back with a new value, so your program will just point to the same value it pointed before the call.