-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web3.eth.sign have different signatures generated in web3js and web3py #259
Comments
@sivachaitanya What version of web3.js are you using? 0.x.x or 1.x.x? EDIT: nevermind. confirmed bug |
@sivachaitanya Looks like web3.py is expecting a string not in hex and encoding it as hex no matter what. So your sha3 is something of the form The following in web3.py:
Is the same as this is web3.js
I'll need to discuss with @carver and @pipermerriam on how we want this to behave, given the web3.js implementation. Ours should definitely be able to handle the output of |
Thanks for the quick reply Danny, From your suggestion sending the generated web3js signature from hex of password to Ecrecover function of solidity gives me totally different address. The code that is working at web3js end which gives me correct address when I sign the sign the message is - web3js code -
Ecrectest.sol -
So this combination of web3js and doing Ecrecover of web3js generated signature gives me correct address which signed it. However, on the flip side, in the web3py side when I' signing using the following function-
when inputting the signature generated from web3py inside the util.fromRPCSig(), I'm getting V,R,S values. However the address that is computed from the same verify function Ecrecover on the smart contract gives me incorrect address. Here basically here python and Javascript will be a clients sending the signature to nodejs api which calls the verify function on deployed contract and checks if the signature matches. There are no issues from web3js end but having mismatch with signature of web3py. I confirm that both the clients have different testrpc instances running locally and to verify the signature generatedby python client, I'm hardcoding sig variable in javascript to signature generated from python which should give me account address that generated that signature in python. NOTE - SHA3 for both the clients are matching. |
sha3() takes an encoding parameter, which defaults to hex. If you want to pass it bytes instead, you can use:
If the value is all ascii characters, this is equivalent to:
The sha3 implementation could use some love, though:
|
@carver Thank you for your response, But here the problem is the signature generated by web3py when inputted inside the Ecrecover of solidity with v,r,s variables extracted from web3js gives me incorrect address with or without the prefix. SHA3 in both the web3js and web3py seems to matching but the eth.sign seems to produce different results. I have correct address generated from web3js end but can you please help me how can I get signature validation done correctly for the signatures from web3py ? |
@sivachaitanya The following will work until
Because
@carver I think this warrants a change to |
@sivachaitanya Note: do not run
|
@djrtwo Danny, seems like the signature generated using web3.eth.sign in web3 py is not matching with web3.eth.sign in web3js, Above is the output from web3.js in the browser console for below code -
Above is the output from web3py for the below code, [Note- I have decoded the hex as per your suggestion before signing it and Both clients are signing with same account at the moment]
Clearly from the screenshots the sha3 and signature of sha3 are also not matching. Javascript side I am able to extract address by calling ecrecover on the solidity contract. I'm using web3.js v 0.18.2 and web3.py 3.13.3 which I got this from line in init.py
|
@sivachaitanya Your sha3 hashes are definitely not matching so any message signing following that will not match. It appears to me that |
@pipermerriam Thoughts on this?
The following is a current hack to make sure it signs correctly
We could either
|
I didn't have time to fully catch up on this issue, but I wanted to toss this into the mix now so you guys can discuss. I think it is ok for us to introduce a breaking change to |
Please take a look at #301 If that gets merged, the new way to use
^ Those are all equivalent. BTW, if you are using 'password' from the earlier example for anything else (like, say, a password), please don't use Instead, the server can send a random challenge phrase for a user to sign. |
Please reopen if you are still experiencing issues. |
I have an issue with this. having a message = 'mymessage' I use w3.eth,account.sign(message_text=message, public_key=publickKey) and the messageHash obtained in this signature differs from doing w3.sha3(text=message) Any comment will be appreciated |
@jfdelgad that's because messages have a prefix prepended to them as part of the signing process to prevent usage of this API for transaction signing. |
What was wrong?
web3.eth.sign(account,web3.sha3(plaintextdata)) is generating different signatures in web3js and web3py
Please include any of the following that are applicable:
So the above code is generating different signatures in web3js and web3py. I doing ecrecover in Solidity and the appending the '\x19Ethereum Signed Message\n'+lenght(message)+message in the contract itself and was able to recover the address for a web3js to Solidity call. However the signed message from Python is giving a totally different signature for same steps and same message and the ecrecover is giving incorrect account address. I observed that SHA3 for the both web3js and web3py are matching but the signature is different ?
I have testrpc client running and signing the hash with its account
How can it be fixed?
No idea
Fill this section in if you know how this could or should be fixed.
The text was updated successfully, but these errors were encountered: