From c8996f2fdbe216802fd18a83cb9ae431cb52746e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Walter?= Date: Wed, 2 Oct 2024 17:13:02 +0300 Subject: [PATCH] Fix rlp encode unsigned for legacy tx --- kakarot_scripts/deploy_kakarot.py | 2 +- kakarot_scripts/utils/kakarot.py | 39 ++----------------- pyproject.toml | 1 - .../kakarot/accounts/test_account_contract.py | 2 +- tests/utils/helpers.py | 35 +++++++++++++---- uv.lock | 2 - 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index 9238567f3..e47718e31 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -56,7 +56,6 @@ async def main(): # %% Starknet Deployments class_hash = get_declarations() starknet_deployments = get_starknet_deployments() - evm_deployments = get_evm_deployments() if NETWORK["type"] is not NetworkType.PROD: starknet_deployments["EVM"] = await deploy_starknet( @@ -125,6 +124,7 @@ async def main(): dump_deployments(starknet_deployments) # %% Pre-EIP155 deployments + evm_deployments = get_evm_deployments() evm_deployments["Multicall3"] = await deploy_with_presigned_tx( MULTICALL3_DEPLOYER, MULTICALL3_SIGNED_TX, diff --git a/kakarot_scripts/utils/kakarot.py b/kakarot_scripts/utils/kakarot.py index fbbb27448..15ab6c701 100644 --- a/kakarot_scripts/utils/kakarot.py +++ b/kakarot_scripts/utils/kakarot.py @@ -5,6 +5,7 @@ from types import MethodType from typing import Any, Dict, List, Optional, Tuple, Union, cast +import uvloop import rlp from async_lru import alru_cache from eth_abi import decode @@ -178,32 +179,8 @@ async def get_contract( return contract -def get_contract_sync( - contract_app: str, - contract_name: str, - address=None, - caller_eoa: Optional[Account] = None, -) -> Web3Contract: - - artifacts = get_solidity_artifacts(contract_app, contract_name) - - contract = cast( - Web3Contract, - WEB3.eth.contract( - address=to_checksum_address(address) if address is not None else address, - abi=artifacts["abi"], - bytecode=artifacts["bytecode"]["object"], - ), - ) - contract.bytecode_runtime = HexBytes(artifacts["bytecode_runtime"]["object"]) - - try: - for fun in contract.functions: - setattr(contract, fun, MethodType(_wrap_kakarot(fun, caller_eoa), contract)) - except NoABIFunctionsFound: - pass - contract.events.parse_events = MethodType(_parse_events, contract.events) - return contract +def get_contract_sync(*args, **kwargs) -> Web3Contract: + return uvloop.run(get_contract(*args, **kwargs)) @alru_cache() @@ -303,16 +280,6 @@ async def deploy( return contract -async def deploy_details( - contract_app: str, contract_name: str, *args, **kwargs -) -> Web3Contract: - contract = await deploy(contract_app, contract_name, *args, **kwargs) - return { - "address": int(contract.address, 16), - "starknet_address": contract.starknet_address, - } - - def dump_deployments(deployments): json.dump( { diff --git a/pyproject.toml b/pyproject.toml index 7a036c639..f5adb40b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,6 @@ dev-dependencies = [ "openzeppelin-cairo-contracts>=0.6.1", "pandas>=1.5.1", "py-ecc>=7.0.0", - "pycryptodome>=3.16.0", "pyperclip>=1.8.2", "pysha3>=1.0.2", "pytest-asyncio==0.21.1", diff --git a/tests/src/kakarot/accounts/test_account_contract.py b/tests/src/kakarot/accounts/test_account_contract.py index a79b8e0da..ac3e65cf2 100644 --- a/tests/src/kakarot/accounts/test_account_contract.py +++ b/tests/src/kakarot/accounts/test_account_contract.py @@ -136,7 +136,7 @@ def test_should_raise_when_read_bytecode_zellic_issue_1279( ), ): with cairo_error(message="Value is not empty"): - output_len, output = cairo_run("test__bytecode") + cairo_run("test__bytecode") class TestNonce: @SyscallHandler.patch("Ownable_owner", 0xDEAD) diff --git a/tests/utils/helpers.py b/tests/utils/helpers.py index 89e3ef5c9..c6a44e16e 100644 --- a/tests/utils/helpers.py +++ b/tests/utils/helpers.py @@ -20,7 +20,26 @@ ) -def rlp_encode_signed_data(tx: dict) -> bytes: +def to_int(v: Union[str, int]) -> int: + if isinstance(v, str): + if v.startswith("0x"): + return int(v, 16) + return int(v) + return v + + +def to_bytes(v: Union[str, bytes, list[int]]) -> bytes: + if isinstance(v, bytes): + return v + elif isinstance(v, str): + if v.startswith("0x"): + return bytes.fromhex(v[2:]) + return v.encode() + else: + return bytes(v) + + +def rlp_encode_signed_data(tx: dict): if "type" in tx: typed_transaction = TypedTransaction.from_dict(tx) @@ -38,13 +57,13 @@ def rlp_encode_signed_data(tx: dict) -> bytes: ] else: legacy_tx = [ - tx["nonce"], - tx["gasPrice"], - tx["gas"] if "gas" in tx else tx["gasLimit"], - bytes.fromhex(f"{int(tx['to'], 16):040x}"), - tx["value"], - tx["data"], - ] + ([tx["chainId"], 0, 0] if "chainId" in tx else []) + to_int(tx["nonce"]), + to_int(tx["gasPrice"]), + to_int(tx["gas"] if "gas" in tx else tx["gasLimit"]), + bytes.fromhex(f"{to_int(tx['to']):040x}") if tx["to"] else b"", + to_int(tx["value"]), + to_bytes(tx["data"]), + ] + ([to_int(tx["chainId"]), 0, 0] if "chainId" in tx else []) return rlp.encode(legacy_tx) diff --git a/uv.lock b/uv.lock index 5fda35487..006189381 100644 --- a/uv.lock +++ b/uv.lock @@ -1323,7 +1323,6 @@ dev = [ { name = "openzeppelin-cairo-contracts" }, { name = "pandas" }, { name = "py-ecc" }, - { name = "pycryptodome" }, { name = "pyperclip" }, { name = "pysha3" }, { name = "pytest" }, @@ -1371,7 +1370,6 @@ dev = [ { name = "openzeppelin-cairo-contracts", specifier = ">=0.6.1" }, { name = "pandas", specifier = ">=1.5.1" }, { name = "py-ecc", specifier = ">=7.0.0" }, - { name = "pycryptodome", specifier = ">=3.16.0" }, { name = "pyperclip", specifier = ">=1.8.2" }, { name = "pysha3", specifier = ">=1.0.2" }, { name = "pytest", specifier = "==8.1.1" },