@carver
msg = Web3.soliditySha3( [ 'address' , 'uint256' ] ,
[ Web3.toChecksumAddress("0x516510e3B61F3D425Fe5F52D7492E8950C8647D7") , 500])
message = encode_defunct(text=msg.hex())
message_hash = Web3.keccak(
b"\x19Ethereum Signed Message:\n" +
bytes(f"{len(message.body)}", encoding='utf-8') + message.body
)
message_hash
HexBytes('0xbf8efb471491d386f2121dda534d499aa84043532aad52af5ee0deb6e74a7c86')
I found this message_hash == signature.messagehash..
So, I tried using the same params in the solidity like :
keccak256(abi.encodePacked( "\x19Ethereum Signed Message:\n" , "66" , hash ))
But then I checked the values :
b"\x19Ethereum Signed Message:\n" +bytes(f"{len(message.body)}", encoding='utf-8') + message.body == b'\x19Ethereum Signed Message:\n660xbccf9f6664ef1f771e15d448d5cccf44e50b6c71a510dc2cb13935e316685e22'
but
abi.encodePacked( "\x19Ethereum Signed Message:\n" , "66" , hash ) == 0x19457468657265756d205369676e6564204d6573736167653a0a3636bccf9f6664ef1f771e15d448d5cccf44e50b6c71a510dc2cb13935e316685e22
Okay, so now we're starting to run into the reason that this warning is in the docs:
Consider the w3.eth.sign() approach be deprecated.
Hey @carver
As you had suggessted I tried
from eth_account.messages import encode_defunct, encode_intended_validator
msg = Web3.soliditySha3( [ 'address' , 'uint256' ] ,
[ Web3.toChecksumAddress("0x516510e3B61F3D425Fe5F52D7492E8950C8647D7") , 500])
message = encode_intended_validator(Web3.toChecksumAddress("0x09c1814a3c53c025f354a9d7b88e28a084d0f162"),
hexstr=msg.hex())
print("message" , message)
signed_message = w3.eth.account.sign_message(message, private_key=private_key)
But this time the signed_message.messagehash and what i got from solidity are diffrent :(
@carver I also used this https://eips.ethereum.org/EIPS/eip-191
and so made a little code change :
keccak256(abi.encodePacked(byte(0x19),byte(0),address(this),destination, value, data, nonce));
Still didn't match
did you go through the tests?
I forgot .. i ll check tyhe tests now ..
ValidationError
when a POA network returns >32 bytes of extraData and the geth_poa_middleware
isn't active. I want to handle this automatically in Brownie.. when connecting to a new network, query an endpoint and if this error is raised, add the middleware. I can do so by examining at the string of the ValidationError
but that feels brittle. Wondering if you'd be open to instead raising a new exception, POAValidationError
or ExtraDataError
? This exception can subclass ValidationError
so the change won't break anything, and this way there is a much stronger approach for catching the specific error.
Hi, guys
var hash = "0x" + abi.soliditySHA3(
["address", "uint256"],
["0x516510e3B61F3D425Fe5F52D7492E8950C8647D7", 500]
).toString("hex");
var signature = web3.eth.accounts.sign( hash , privateKey );
I was able to solve my issue by using nodejs .. using this code the signature.messagehash == solidity message hash.. But I wanted to write the Api in python only.. Why can't i solve it with python??
======
web3.py v5.11.0 released :rocket: https://web3py.readthedocs.io/en/latest/releases.html#v5-11-0-2020-06-03
Thanks to contributors @palango @iamdefinitelyahuman @cygnusv @cryptoscopia :muscle:
admin()
, which triggers a validation error in web3.py. I can't think of a good reason for there to be such duplicates in the ABI intentionally, it just looks broken. Maybe you could publish one that doesn't have duplicates? https://compound.finance/docs/abi/mainnet/Comptroller
LATEST_BLOCK = 10226095
STEP_SIZE = 100_000
for i in range(0, int(1_000_000 / STEP_SIZE)):
filter_builder = cDAI.events.LiquidateBorrow.build_filter()
filter_builder.fromBlock = LATEST_BLOCK - ((i + 1) * STEP_SIZE)
filter_builder.toBlock = LATEST_BLOCK - (i * STEP_SIZE)
filter_instance = filter_builder.deploy(w3)
entries = filter_instance.get_all_entries()
if len(entries) > 0:
print(i, entries)