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

Fix rlp encode unsigned for legacy tx #1462

Merged
merged 3 commits into from
Oct 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion kakarot_scripts/deploy_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 3 additions & 36 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Dict, List, Optional, Tuple, Union, cast

import rlp
import uvloop
from async_lru import alru_cache
from eth_abi import decode
from eth_abi.exceptions import InsufficientDataBytes
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
{
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/src/kakarot/accounts/test_account_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 27 additions & 8 deletions tests/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading