Skip to content

Commit

Permalink
fix: some pylint cleanup.
Browse files Browse the repository at this point in the history
 Changes to be committed:
	modified:   aa_utils/__init__.py
	modified:   offchain/offchain_utils.py
  • Loading branch information
mmontour1306 committed Nov 12, 2024
1 parent 256ee28 commit e2556da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
38 changes: 19 additions & 19 deletions hybrid-compute/aa_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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])
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions hybrid-compute/offchain/offchain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand Down Expand Up @@ -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',
Expand All @@ -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]))
Expand All @@ -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 ({
Expand Down

0 comments on commit e2556da

Please sign in to comment.