2

I'm using the ECVerify library and in the test examples in that contract, function ecverify(bytes32 hash, bytes sig, address signer) returns (bool) {} expects bytes sig in the format "\xFF\xFF\xFF...", and it does not seem to work with a bytes sig = "0xFFFFFF..." format.

How do I convert bytes32 sig = 0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200 to bytes sig = "\xac\xa7\xda...?

Update: re: Edmund Edgars comment, in ECVerfiy.sol there are test examples,

function test_v0() returns (bool) {
    bytes32 hash = 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad;
    bytes memory sig = "\xac\xa7\xda\x99\x7a\xd1\x77\xf0\x40\x24\x0c\xdc\xcf\x69\x05\xb7\x1a\xb1\x6b\x74\x43\x43\x88\xc3\xa7\x2f\x34\xfd\x25\xd6\x43\x93\x46\xb2\xba\xc2\x74\xff\x29\xb4\x8b\x3e\xa6\xe2\xd0\x4c\x13\x36\xea\xce\xaf\xda\x3c\x53\xab\x48\x3f\xc3\xff\x12\xfa\xc3\xeb\xf2\x00";
    return ECVerify.ecverify(hash, sig, 0x0e5cb767cce09a7f3ca594df118aa519be5e2b5a);
}

If I replace bytes sig with "0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200" then it fails. It seems to only work with the bytes sig = "\xac\xa7\xda..." format.

I'm using ECVerify for a dApp and will be passing a lot of signatures to it, and it seemed like those need to be in that format, so are there any libraries or something for converting to "\xac\xa7\xda" or how would I send signatures to ECVerify?

  • A bytes32 in Solidity is 32 bytes - if you've got a formatting problem it's probably where you're passing the data to the contract. Can you post your failing code? – Edmund Edgar Jan 30 '17 at 13:03
  • posted the code – cryptorenaisance Jan 30 '17 at 18:46
1

When you type

bytes memory sig = "0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200"

Solidity interprets this as the literal characters "0", "x", etc. in ASCII.

if you instead use (note the missing 0x)

bytes memory sig =  hex"aca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200"

it will interpret it as the bytes in hexadecimal format.

When you are actually passing data to the contract, this won't be an issue, the contract will just accept a sting of bytes, so any formatting needs to be done on the client side.

0

Since your signature is 64 Bytes long you can't store it in a Bytes32 variable. This will NOT work.

bytes32 sig = 0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200

However you can store the signature in an arbitrary long bytes array as you mentioned:

bytes sig = "\xAA\xBB ... \x00"

This will be handled as an array in is the same as:

bytes1[] memory = new bytes1[](64);
bytes1[0] = 0xAA;
bytes1[1] = 0xBB;
//...
bytes1[63] = 0x00;

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.