Skip to content
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

solidity_keccak not matching JS keccak256(abi.encodePacked( #3290

Closed
inev opened this issue Mar 15, 2024 · 1 comment
Closed

solidity_keccak not matching JS keccak256(abi.encodePacked( #3290

inev opened this issue Mar 15, 2024 · 1 comment

Comments

@inev
Copy link

inev commented Mar 15, 2024

  • Version: latest
  • Python 3.12.1
  • OS: mac
  • pip freeze output
aiohttp==3.9.3
aiosignal==1.3.1
asttokens==2.4.1
attrs==23.2.0
bitarray==2.9.2
black==24.2.0
blessed==1.20.0
cbor2==5.6.2
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
cytoolz==0.12.3
dataclassy==0.11.1
editor==1.6.6
eip712==0.2.4
eth-account==0.10.0
eth-brownie==1.20.2
eth-event==1.2.5
eth-hash==0.6.0
eth-keyfile==0.7.0
eth-keys==0.5.0
eth-rlp==1.0.1
eth-typing==3.5.2
eth-utils==2.3.1
eth_abi==5.0.0
execnet==2.0.2
frozenlist==1.4.1
h11==0.14.0
hexbytes==0.3.1
hypothesis==6.27.3
idna==3.6
importlib-metadata==7.0.1
iniconfig==2.0.0
inquirer==3.2.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
lazy-object-proxy==1.10.0
lru-dict==1.2.0
multidict==6.0.5
mypy-extensions==1.0.0
natsort==8.4.0
outcome==1.3.0.post0
packaging==23.2
parsimonious==0.9.0
pathspec==0.12.1
peewee==3.17.1
platformdirs==4.2.0
pluggy==1.4.0
prompt-toolkit==3.0.43
protobuf==4.25.3
psutil==5.9.8
py==1.11.0
py-solc-ast==1.2.10
py-solc-x==1.1.1
pyasn1==0.5.1
pycryptodome==3.20.0
Pygments==2.17.2
pygments-lexer-solidity==0.7.0
PySimpleGUI==5.0.2
PySocks==1.7.1
pytest==6.2.5
pytest-forked==1.6.0
pytest-xdist==1.34.0
python-dotenv==0.16.0
pyunormalize==15.1.0
PyYAML==6.0.1
random-username==1.0.2
readchar==4.0.5
referencing==0.33.0
regex==2023.12.25
requests==2.31.0
rlp==4.0.0
rpds-py==0.18.0
rsa==4.9
runs==1.2.2
selenium==4.18.1
semantic-version==2.10.0
setuptools==69.1.0
six==1.16.0
sniffio==1.3.0
sortedcontainers==2.4.0
toml==0.10.2
toolz==0.12.1
tqdm==4.66.2
trio==0.24.0
trio-websocket==0.11.1
typing_extensions==4.9.0
undetected-chromedriver==3.5.5
urllib3==2.2.1
vvm==0.1.0
vyper==0.3.10
wcwidth==0.2.13
web3==6.15.1
websockets==12.0
wheel==0.42.0
wrapt==1.16.0
wsproto==1.2.0
xmod==1.8.1
yarl==1.9.4
zipp==3.17.0

What was wrong?

I'm trying to reproduce a signature that a contract verifies but I'm unable to do it on web3py. To verify I'm producing a signature correctly I'm going to look at an already produced signature and verify that the address is correct. First here's my code:

hash = Web3.solidity_keccak(['address', 'uint256', 'uint256', 'uint256'], ["0xf7FA3C8C9Ba3FfCFA1d5f0ca5C9294Afd5970aE7", 1, 59144, 1])
message = defunct_hash_message(hash)
address = w3.eth.account._recover_hash(message, signature=HexBytes("0x599f3172abf3bf5029ee5ea53b5119fa2c9d5de3fa434fd81d46209fb0ab1d230a6c5a0946b59942f94e1b352d325db1bf938a608eb13cbc89ce7184e2d6112b1c"))
print(address)

The output is 0x784aD8676Ade4DEE288fd3f36e2F2EbDfdF70765 but should be 0xf7FA3C8C9Ba3FfCFA1d5f0ca5C9294Afd5970aE7

This is the contract and specifically, I'm looking at newTicket function. Specifically if you look at the code here, LotteryMaster.sol#126you can see this is being done in solidity:

keccak256(
                abi.encodePacked(to, txHashes.length, block.chainid, sessionIdx))
        );  // include session index so the signature only affect only for this session
        require(isValidSignature(toAddressHash, _signature), "Mismatch signature.");

If you look at this successful transaction here it has the full signature. Now I want to be able to recover the address like they do in the code. But for that I need to hash the message correctly. If you look at their code you can determine the message parameters by looking at the transaction itself, and so should be able to create the hash that would return the address using the signature. But I can't seem to do that. What am I doing wrong?

@fselmo
Copy link
Collaborator

fselmo commented Mar 26, 2024

We try to steer usage questions away from here so please re-raise the issue more specifically if you have debugged and believe there is an issue with the library. Best of luck.

@fselmo fselmo closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants