0

I want to call function with four parameters. I know how to create two of them, but the last two is the r and s components of ECDSA signature of (param_1, param_2). I tried this (and a lot of combinations), but the result is wrong:

msg = '%d%d' % (param_1, param_2)
message_hash = defunct_hash_message(text=msg)
signed_message = w3.eth.account.signHash(message_hash, private_key=wallet_private_key)
w3.toHex(signed_message['r'])[2:])
w3.toHex(signed_message['s'])[2:])

Next

From code of contract:

r, s - components of ECDSA signature of (commitLastBlock, commit). v is guaranteed to always equal 27.

Made convertaion this way:

signatureHash = w3.soliditySha3(['uint40', 'uint256'], [commitLastBlock, commit])

I checked it and it's valid. But when I sign the result, the r and s values are wrong anyway. I do it whis way:

signed_message = w3.eth.account.signHash(signatureHash, private_key)
  • Without documentation of how you should combine the values or a reference implementation that does it, you're just guessing. There's no "right" way to convert to numbers into a byte sequence before signing. – smarx Apr 19 at 20:33
  • Can you show the function that you are trying to run?, what is the type of the parameters. – Jaime Apr 20 at 12:54
  • @Jaime function placeBet(uint betMask, uint modulo, uint commitLastBlock, uint commit, bytes32 r, bytes32 s) – Taras Rodionov Apr 22 at 8:45
  • @Jaime and the r and s should be created like that bytes32 signatureHash = keccak256(abi.encodePacked(uint40(commitLastBlock), commit)); – Taras Rodionov Apr 22 at 8:46

Your Answer

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

Browse other questions tagged or ask your own question.