Skip to content

Commit

Permalink
fix: dependencies update (kkrt-labs#559)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->
Updates necessary dependencies to be able to interact with the current
version of Starknet deployed on the testnet (v0.11).

<!-- Give an estimate of the time you spent on this PR in terms of work
days. Did you spend 0.5 days on this PR or rather 2 days? -->

Time spent on this PR: 0.75 day

## Pull request type

<!-- Please try to limit your pull request to one type, submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [x] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?
The current dependencies are outdated and prevent the interaction with
Starknet 0.11 deployed on the testnet.

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Resolves kkrt-labs#558 

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Starknet-py updated to version 0.15 which fixes failing interactions
with the testnet.
- Cairo-lang updated to the latest version 0.11
- Replace py-evm by blake2b-py 

## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
  • Loading branch information
greged93 authored Mar 28, 2023
1 parent 4a00821 commit cd1f7c3
Show file tree
Hide file tree
Showing 8 changed files with 2,006 additions and 2,036 deletions.
3,971 changes: 1,970 additions & 2,001 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ packages = [{ include = "scripts" }]

[tool.poetry.dependencies]
python = ">=3.9,<3.10"
cairo-lang = "^0.10.1"
cairo-lang = "^0.11.0.1"
openzeppelin-cairo-contracts = "0.5.0"
amarna = "^0.1.5"
starknet-py = "^0.14.0a0"
starknet-py = "^0.15.0"

[tool.poetry.group.dev.dependencies]
black = "^22.10.0"
isort = "^5.10.1"
cairo-coverage = "^0.1.4"
cairo-coverage = { git = "https://github.com/starknet-edu/cairo-coverage.git", branch="master" }
pandas = "^1.5.1"
pytest-xdist = { version = "^3.0.2", extras = ["psutil"] }
setproctitle = "^1.3.2"
pysha3 = "^1.0.2"
web3 = "6.0.0b2"
web3 = "<6.0.0"
python-dotenv = "^0.21.0"
eth-account = "<0.8.0"
autoflake = "^2.0.0"
pycryptodome = "^3.16.0"
rlp = "<=3"
py-evm = "0.6.1a2"
eth-keys = "^0.4.0"
eth-abi = "^3.0.1"
eth-utils = "^2.1.0"
blake2b-py = { git = "https://github.com/ethereum/blake2b-py.git", tag="v0.2.0" }
eth-keys = "<0.4.0"
eth-abi = "<4.0.0"
eth-utils = "<2.0.0"
hypothesis = "^6.65.0"
case-converter = "^1.1.0"
starknet-devnet = "^0.4.6"
starknet-devnet = "0.5.0a0"
requests = "^2.28.2"
codespell = "^2.2.2"

Expand Down
18 changes: 8 additions & 10 deletions scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests
from caseconverter import snakecase
from starknet_py.contract import Contract
from starknet_py.net import AccountClient
from starknet_py.net.account.account import Account
from starknet_py.net.client import Client
from starknet_py.net.client_models import Call
from starknet_py.net.models import Address
Expand Down Expand Up @@ -93,7 +93,7 @@ async def create_account():
await GATEWAY_CLIENT.wait_for_tx(transaction_hash)


async def get_default_account() -> AccountClient:
async def get_default_account() -> Account:
accounts = json.load(
open(list(Path(DEFAULT_ACCOUNT_DIR).expanduser().glob("*.json"))[0])
)
Expand All @@ -103,10 +103,9 @@ async def get_default_account() -> AccountClient:

logger.info(f"ℹ️ Using account {account['address']:x}")

return AccountClient(
return Account(
address=account["address"],
client=GATEWAY_CLIENT,
supported_tx_version=1,
chain=CHAIN_ID,
key_pair=KeyPair(
private_key=int(account["private_key"], 16),
Expand All @@ -118,7 +117,7 @@ async def get_default_account() -> AccountClient:
async def get_account(
address=None,
private_key=None,
) -> AccountClient:
) -> Account:
address = int(address or ACCOUNT_ADDRESS, 16)
key_pair = KeyPair.from_private_key(int(private_key or PRIVATE_KEY, 16))
try:
Expand Down Expand Up @@ -148,10 +147,9 @@ async def get_account(
f"Public key of account 0x{address:064x} is not consistent with provided private key"
)

return AccountClient(
return Account(
address=address,
client=GATEWAY_CLIENT,
supported_tx_version=1,
chain=CHAIN_ID,
key_pair=key_pair,
)
Expand Down Expand Up @@ -323,9 +321,9 @@ async def declare(contract_name):
declare_transaction = await account.sign_declare_transaction(
compiled_contract=Path(artifact).read_text(), max_fee=int(1e16)
)
resp = await account.declare(transaction=declare_transaction)
resp = await account.client.declare(transaction=declare_transaction)
logger.info(f"⏳ Waiting for tx {get_tx_url(resp.transaction_hash)}")
await account.wait_for_tx(resp.transaction_hash, check_interval=15)
await account.client.wait_for_tx(resp.transaction_hash, check_interval=15)
logger.info(f"✅ {contract_name} class hash: {hex(resp.class_hash)}")
return resp.class_hash

Expand Down Expand Up @@ -365,7 +363,7 @@ async def invoke(contract_name, function_name, *inputs, address=None):
logger.info(f"⏳ Invoking {contract_name}.{function_name}({json.dumps(inputs)})")
response = await account.execute(call, max_fee=int(1e16))
logger.info(f"⏳ Waiting for tx {get_tx_url(response.transaction_hash)}")
await account.wait_for_tx(response.transaction_hash, check_interval=15)
await account.client.wait_for_tx(response.transaction_hash, check_interval=15)
logger.info(
f"✅ {contract_name}.{function_name} invoked at tx: %s",
hex(response.transaction_hash),
Expand Down
4 changes: 2 additions & 2 deletions src/kakarot/instructions/environmental_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.cairo_builtins import HashBuiltin, BitwiseBuiltin
from starkware.cairo.common.cairo_keccak.keccak import keccak_bigend, finalize_keccak
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak_bigend, finalize_keccak
from starkware.starknet.common.syscalls import get_caller_address, get_tx_info
from starkware.cairo.common.uint256 import Uint256

Expand Down Expand Up @@ -691,7 +691,7 @@ namespace EnvironmentalInformation {
local keccak_ptr_start: felt* = keccak_ptr;

with keccak_ptr {
let (result) = keccak_bigend(inputs=dest, n_bytes=bytecode_len);
let (result) = cairo_keccak_bigend(inputs=dest, n_bytes=bytecode_len);
finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions src/kakarot/instructions/sha3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from starkware.cairo.common.math_cmp import is_le
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.cairo_builtins import HashBuiltin, BitwiseBuiltin
from starkware.cairo.common.cairo_keccak.keccak import keccak_bigend, finalize_keccak
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak_bigend, finalize_keccak
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.pow import pow
from starkware.cairo.common.bool import FALSE
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace Sha3 {
local keccak_ptr_start: felt* = keccak_ptr;

with keccak_ptr {
let (result) = keccak_bigend(inputs=dest, n_bytes=length.low);
let (result) = cairo_keccak_bigend(inputs=dest, n_bytes=length.low);
finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr);
}
Expand Down
10 changes: 6 additions & 4 deletions src/kakarot/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.bool import TRUE, FALSE
from starkware.cairo.common.cairo_builtins import HashBuiltin, BitwiseBuiltin
from starkware.cairo.common.cairo_keccak.keccak import keccak_bigend, finalize_keccak
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak_bigend, finalize_keccak
from starkware.cairo.common.dict import (
DictAccess,
dict_new,
Expand Down Expand Up @@ -645,7 +645,7 @@ namespace CreateHelper {
);

with keccak_ptr {
let (create_hash) = keccak_bigend(inputs=packed_bytes8, n_bytes=rlp_list_len);
let (create_hash) = cairo_keccak_bigend(inputs=packed_bytes8, n_bytes=rlp_list_len);
finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr);
}
Expand Down Expand Up @@ -689,7 +689,7 @@ namespace CreateHelper {
);
with keccak_ptr {
// get keccak hash of bytecode
let (bytecode_hash_bigend) = keccak_bigend(
let (bytecode_hash_bigend) = cairo_keccak_bigend(
inputs=bytecode_bytes8, n_bytes=bytecode_len
);
// get keccak hash of
Expand Down Expand Up @@ -743,7 +743,9 @@ namespace CreateHelper {
dest_index=0,
);
let (create2_hash) = keccak_bigend(inputs=packed_bytes8, n_bytes=packed_bytes_len);
let (create2_hash) = cairo_keccak_bigend(
inputs=packed_bytes8, n_bytes=packed_bytes_len
);
finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr);
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/eth_transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from kakarot.constants import Constants
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.bool import TRUE, FALSE
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin, HashBuiltin
from starkware.cairo.common.cairo_keccak.keccak import keccak, finalize_keccak, keccak_bigend
from starkware.cairo.common.cairo_keccak.keccak import finalize_keccak, cairo_keccak_bigend
from starkware.cairo.common.cairo_secp.signature import verify_eth_signature_uint256
from starkware.cairo.common.math_cmp import is_not_zero, is_le
from starkware.cairo.common.memcpy import memcpy
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace EthTransaction {
let (keccak_ptr: felt*) = alloc();
let keccak_ptr_start = keccak_ptr;
with keccak_ptr {
// From keccak/keccak_bigend doc:
// From keccak/cairo_keccak_bigend doc:
// > To use this function, split the input into words of 64 bits (little endian).
// > Same as keccak, but outputs the hash in big endian representation.
// > Note that the input is still treated as little endian.
Expand All @@ -96,7 +96,7 @@ namespace EthTransaction {
dest=words,
dest_index=0,
);
let (tx_hash) = keccak_bigend(inputs=words, n_bytes=rlp_data_len);
let (tx_hash) = cairo_keccak_bigend(inputs=words, n_bytes=rlp_data_len);
}
finalize_keccak(keccak_ptr_start, keccak_ptr);

Expand Down Expand Up @@ -178,7 +178,7 @@ namespace EthTransaction {
let (keccak_ptr: felt*) = alloc();
let keccak_ptr_start = keccak_ptr;
with keccak_ptr {
// From keccak/keccak_bigend doc:
// From keccak/cairo_keccak_bigend doc:
// > To use this function, split the input into words of 64 bits (little endian).
// > Same as keccak, but outputs the hash in big endian representation.
// > Note that the input is still treated as little endian.
Expand All @@ -192,7 +192,7 @@ namespace EthTransaction {
dest=words,
dest_index=0,
);
let (tx_hash) = keccak_bigend(inputs=words, n_bytes=rlp_len + 1);
let (tx_hash) = cairo_keccak_bigend(inputs=words, n_bytes=rlp_len + 1);
}
finalize_keccak(keccak_ptr_start, keccak_ptr);

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/src/kakarot/precompiles/test_blake2f.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
import pytest_asyncio
from eth._utils.blake2.compression import blake2b_compress
from blake2b import compress
from starkware.starknet.testing.starknet import Starknet

from tests.utils.errors import kakarot_error
Expand Down Expand Up @@ -58,6 +58,7 @@ async def test_should_return_blake2f_compression(self, blake2f, f, seed):
).call()

# Then
compress = blake2b_compress(rounds, h_starting_state, m, [t0, t1], bool(f))
expected = [int(x) for x in compress]
m_64 = [pack_64_bits_little(m[i * 8 : (i + 1) * 8]) for i in range(16)]
c = compress(rounds, h_starting_state, m_64, [t0, t1], bool(f))
expected = [int(x) for x in c]
assert got.result.output == expected

0 comments on commit cd1f7c3

Please sign in to comment.