From e2556da2738ee6b40330a76ff1c0ad6fccca16f2 Mon Sep 17 00:00:00 2001 From: Michael Montour Date: Mon, 11 Nov 2024 21:18:08 -0800 Subject: [PATCH] fix: some pylint cleanup. Changes to be committed: modified: aa_utils/__init__.py modified: offchain/offchain_utils.py --- hybrid-compute/aa_utils/__init__.py | 38 +++++++++++------------ hybrid-compute/offchain/offchain_utils.py | 21 +++++++------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/hybrid-compute/aa_utils/__init__.py b/hybrid-compute/aa_utils/__init__.py index a243bd8..31fc3ff 100644 --- a/hybrid-compute/aa_utils/__init__.py +++ b/hybrid-compute/aa_utils/__init__.py @@ -44,16 +44,16 @@ def sign_v7_op(self, user_op, signer_key): # The deploy-local script supplies the packed values prior to signature, as it bypasses the bundler. # For normal UserOperations the fields are derived here if 'accountGasLimits' not in op: - accountGasLimits = ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['verificationGasLimit'])])[16:32] \ + account_gas_limits = ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['verificationGasLimit'])])[16:32] \ + ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['callGasLimit'])])[16:32] else: - accountGasLimits = Web3.to_bytes(hexstr=op['accountGasLimits']) + account_gas_limits = Web3.to_bytes(hexstr=op['accountGasLimits']) if 'gasFees' not in op: - gasFees = ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['maxPriorityFeePerGas'])])[16:32] \ + gas_fees = ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['maxPriorityFeePerGas'])])[16:32] \ + ethabi.encode(['uint128'],[Web3.to_int(hexstr=op['maxFeePerGas'])])[16:32] else: - gasFees = Web3.to_bytes(hexstr=op['gasFees']) + gas_fees = Web3.to_bytes(hexstr=op['gasFees']) if 'paymasterAndData' not in op: op['paymasterAndData'] = "0x" @@ -63,9 +63,9 @@ def sign_v7_op(self, user_op, signer_key): Web3.to_int(hexstr=op['nonce']), Web3.keccak(hexstr="0x"), # initcode Web3.keccak(hexstr=op['callData']), - accountGasLimits, + account_gas_limits, Web3.to_int(hexstr=op['preVerificationGas']), - gasFees, + gas_fees, Web3.keccak(hexstr=op['paymasterAndData']), ]) pack2 = ethabi.encode(['bytes32','address','uint256'], [Web3.keccak(pack1), self.EP_addr, self.chain_id]) @@ -142,15 +142,15 @@ def estimate_op_gas(self, op, extra_pvg=0, extra_vg=0, extra_cg=0): print("*** eth_estimateUserOperationGas failed") time.sleep(2) return False, op - else: - est_result = response.json()['result'] - - op['preVerificationGas'] = Web3.to_hex(Web3.to_int( - hexstr=est_result['preVerificationGas']) + extra_pvg) - op['verificationGasLimit'] = Web3.to_hex(Web3.to_int( - hexstr=est_result['verificationGasLimit']) + extra_vg) - op['callGasLimit'] = Web3.to_hex(Web3.to_int( - hexstr=est_result['callGasLimit']) + extra_cg) + + est_result = response.json()['result'] + + op['preVerificationGas'] = Web3.to_hex(Web3.to_int( + hexstr=est_result['preVerificationGas']) + extra_pvg) + op['verificationGasLimit'] = Web3.to_hex(Web3.to_int( + hexstr=est_result['verificationGasLimit']) + extra_vg) + op['callGasLimit'] = Web3.to_hex(Web3.to_int( + hexstr=est_result['callGasLimit']) + extra_cg) return True, op def sign_submit_op(self, op, owner_key): @@ -159,8 +159,8 @@ def sign_submit_op(self, op, owner_key): is_v7 = False if self.EP_addr == "0x0000000071727De22E5E9d8BAf0edAc6f37da032": is_v7 = True - elif self.EP_addr != "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789": - assert "unknown EntryPoint address" + else: + assert self.EP_addr == "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789" if is_v7: op = self.sign_v7_op(op, owner_key) @@ -236,13 +236,13 @@ def sign_and_submit(self, tx, key): def approve_token(self, token, spender, deploy_addr, deploy_key): """Perform an unlimited ERC20 token approval""" - approveCD = selector("approve(address,uint256)") + ethabi.encode( + approve_calldata = selector("approve(address,uint256)") + ethabi.encode( ['address','uint256'], [spender, Web3.to_int(hexstr="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")]) tx = { 'from': deploy_addr, - 'data': approveCD, + 'data': approve_calldata, 'to': token, } print("ERC20 approval of", token, "for", spender) diff --git a/hybrid-compute/offchain/offchain_utils.py b/hybrid-compute/offchain/offchain_utils.py index b694d83..c1b5283 100644 --- a/hybrid-compute/offchain/offchain_utils.py +++ b/hybrid-compute/offchain/offchain_utils.py @@ -81,7 +81,7 @@ def gen_response(req, err_code, resp_payload): e_msg = eth_account.messages.encode_defunct(oo_hash) sig = signer_acct.sign_message(e_msg) - success = (err_code == 0) + success = err_code == 0 print("Method returning success={} response={} signature={}".format( success, Web3.to_hex(resp_payload), Web3.to_hex(sig.signature))) return ({ @@ -112,9 +112,13 @@ def gen_response_v7(req, err_code, resp_payload): print("call_gas calculation", len(resp_payload), 4+len(p_enc2), call_gas) - accountGasLimits = Web3.to_bytes(hexstr="0x00000000000000000000000000010000") + ethabi.encode(['uint128'],[call_gas])[16:32] - print("AGL", Web3.to_hex(accountGasLimits)) - gasFees = Web3.to_bytes(hexstr="0x0000000000000000000000000000000000000000000000000000000000000000") + account_gas_limits = \ + ethabi.encode(['uint128'],[Web3.to_int(hexstr=limits['verificationGasLimit'])])[16:32] + \ + ethabi.encode(['uint128'],[call_gas])[16:32] + + gas_fees = Web3.to_bytes( + hexstr="0x0000000000000000000000000000000000000000000000000000000000000000" + ) packed = ethabi.encode([ 'address', @@ -130,11 +134,10 @@ def gen_response_v7(req, err_code, resp_payload): req['opNonce'], Web3.keccak(Web3.to_bytes(hexstr='0x')), # initCode Web3.keccak(p_enc2), - accountGasLimits, + account_gas_limits, Web3.to_int(hexstr=limits['preVerificationGas']), - gasFees, - Web3.to_bytes(hexstr='0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), -# Web3.keccak(Web3.to_bytes(hexstr='0x')), # paymasterAndData + gas_fees, + Web3.keccak(Web3.to_bytes(hexstr='0x')), # paymasterAndData ]) oo_hash = Web3.keccak(ethabi.encode(['bytes32', 'address', 'uint256'], [ Web3.keccak(packed), EntryPointAddr, HC_CHAIN])) @@ -143,7 +146,7 @@ def gen_response_v7(req, err_code, resp_payload): e_msg = eth_account.messages.encode_defunct(oo_hash) sig = signer_acct.sign_message(e_msg) - success = (err_code == 0) + success = err_code == 0 print("Method returning success={} response={} signature={}".format( success, Web3.to_hex(resp_payload), Web3.to_hex(sig.signature))) return ({