1

Who can explain what the second line exactly do ?
this function verify ecdsa signature. the msg is already hashaed and it seems like with sha3(prefix,msgHash) will be hashed twice.

function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r,  bytes32 s) public constant returns (bool) {

         bytes memory prefix = "\x19Ethereum Signed Message:\n32";
         bytes32 prefixedHash = sha3(prefix, msgHash);
         return ecrecover(prefixedHash, v, r, s) == _addr;
    }
1

This function verifies a signature. When the signature is generated, the standard practice, as defined in this EIP, is to add this (standard) prefix"\x19Ethereum Signed Message:\n" + len(message) (notice in this case, the length is 32).

As a result, to verify the signature, the same prefix needs to be appended to the original message (msgHash), in order to correctly validate the signature.

The main purpose of adding the prefix is security. If the signature is calculated directly from whatever input, it provides a method for a malicious player to present the byte array of a payment transaction (or contract method call) as a message, which is then presented to the victim to sign (thus approving). Adding a prefix makes such attack much less likely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.