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

Revert web3 upgrade v7 to v6 #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exclude =
# `pip install eth-prototype[PDF]` like:
# PDF = ReportLab; RXP
web3 =
web3==7.*
web3==6.*

defender =
boto3
Expand All @@ -77,7 +77,7 @@ testing =
pytest
gmpy2
pytest-cov
web3[tester]==7.*
web3[tester]==6.*
boto3

[options.entry_points]
Expand Down
20 changes: 8 additions & 12 deletions src/ethproto/aa_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@


def pack_two(a, b):
a = HexBytes(a).hex()
b = HexBytes(b).hex()
a = HexBytes(a).hex()[2:]
b = HexBytes(b).hex()[2:]
return "0x" + a.zfill(32) + b.zfill(32)


Expand Down Expand Up @@ -110,23 +110,23 @@ def hash_packed_user_operation_only(packed_user_op):
hash_paymaster_and_data,
],
).hex()
)
).hex()


def hash_packed_user_operation(packed_user_op, chain_id, entry_point):
return Web3.keccak(
hexstr=encode(
["bytes32", "address", "uint256"],
[hash_packed_user_operation_only(packed_user_op), entry_point, chain_id],
[HexBytes(hash_packed_user_operation_only(packed_user_op)), entry_point, chain_id],
).hex()
)
).hex()


def sign_user_operation(private_key, user_operation, chain_id, entry_point):
packed_user_op = pack_user_operation(user_operation)
hash = hash_packed_user_operation(packed_user_op, chain_id, entry_point)
signature = Account.sign_message(encode_defunct(hexstr=hash.hex()), private_key)
return signature.signature
signature = Account.sign_message(encode_defunct(hexstr=hash), private_key)
return signature.signature.hex()


def make_nonce(nonce_key, nonce):
Expand Down Expand Up @@ -272,11 +272,7 @@ def build_user_operation(w3, tx, retry_nonce=None):

def send_transaction(w3, tx, retry_nonce=None):
user_operation = build_user_operation(w3, tx, retry_nonce)
user_operation["signature"] = add_0x_prefix(
sign_user_operation(
AA_BUNDLER_EXECUTOR_PK, user_operation, tx["chainId"], AA_BUNDLER_ENTRYPOINT
).hex()
)
user_operation["signature"] = sign_user_operation(AA_BUNDLER_EXECUTOR_PK, user_operation, tx["chainId"], AA_BUNDLER_ENTRYPOINT)
resp = w3.provider.make_request("eth_sendUserOperation", [user_operation, AA_BUNDLER_ENTRYPOINT])
if "error" in resp:
next_nonce = check_nonce_error(resp, retry_nonce)
Expand Down
6 changes: 3 additions & 3 deletions src/ethproto/w3wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hexbytes import HexBytes
from web3.contract import Contract
from web3.exceptions import ContractLogicError, ExtraDataLengthError
from web3.middleware import ExtraDataToPOAMiddleware
from web3.middleware import geth_poa_middleware

from .build_artifacts import ArtifactLibrary
from .contracts import RevertError
Expand Down Expand Up @@ -75,9 +75,9 @@ def register_w3_provider(provider_key="w3", w3=None, tester=None, provider_kwarg
try:
w3.eth.get_block("latest")
except ExtraDataLengthError:
w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
elif W3_POA == "yes":
w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

# If address_book not provided and there are envs with W3_ADDRESS_BOOK_PREFIX,
# use W3EnvAddressBook
Expand Down
10 changes: 4 additions & 6 deletions tests/test_aa_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,22 @@ def test_pack_user_operation():
def test_hash_packed_user_operation():
packed = aa_bundler.pack_user_operation(user_operation)
hash = aa_bundler.hash_packed_user_operation_only(packed)
assert hash == HexBytes("0xa2c19765d18b0d690c05b20061bd23d066201aff1833a51bd28af115fbd4bcd9")
assert hash == "0xa2c19765d18b0d690c05b20061bd23d066201aff1833a51bd28af115fbd4bcd9"
hash = aa_bundler.hash_packed_user_operation(packed, CHAIN_ID, ENTRYPOINT)
assert hash == HexBytes("0xb365ad4d366e9081718e926912da7a78a2faae592286fda0cc11923bd141b7cf")
assert hash == "0xb365ad4d366e9081718e926912da7a78a2faae592286fda0cc11923bd141b7cf"


def test_sign_user_operation():
signature = aa_bundler.sign_user_operation(TEST_PRIVATE_KEY, user_operation, CHAIN_ID, ENTRYPOINT)
assert signature == HexBytes(
"0xb9b872bfe4e90f4628e8ec24879a5b01045f91da8457f3ce2b417d2e5774b508261ec1147a820e75a141cb61b884a78d7e88996ceddafb9a7016cfe7a48a1f4f1b" # noqa
assert (signature == "0xb9b872bfe4e90f4628e8ec24879a5b01045f91da8457f3ce2b417d2e5774b508261ec1147a820e75a141cb61b884a78d7e88996ceddafb9a7016cfe7a48a1f4f1b" # noqa
)


def test_sign_user_operation_gas_diff():
user_operation_2 = dict(user_operation)
user_operation_2["maxPriorityFeePerGas"] -= 1
signature = aa_bundler.sign_user_operation(TEST_PRIVATE_KEY, user_operation_2, CHAIN_ID, ENTRYPOINT)
assert signature == HexBytes(
"0x8162479d2dbd18d7fe93a2f51e283021d6e4eae4f57d20cdd553042723a0b0ea690ab3903d45126b0047da08ab53dfdf86656e4f258ac4936ba96a759ccb77f61b" # noqa
assert (signature == "0x8162479d2dbd18d7fe93a2f51e283021d6e4eae4f57d20cdd553042723a0b0ea690ab3903d45126b0047da08ab53dfdf86656e4f258ac4936ba96a759ccb77f61b" # noqa
)


Expand Down
Loading