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

Add execute_from_outside #1246

Merged
merged 55 commits into from
Jul 17, 2024

Conversation

ClementWalter
Copy link
Member

@ClementWalter ClementWalter commented Jul 1, 2024

What

Add the SNIP9 entrypoint

Todo

  • decode the tx only once at the beginning
  • update accounts.library.validate to get the signature in argument and not from tx_info
  • block __validate__ and __execute__ usage
    with_attr error_message("EOA: declare not supported") {
        assert 1 = 0;
    }
    return ();
  • remove recursion in Account.validate and inline Internals.validate
  • remove useless storage Account_cairo1_helpers_class_hash add get class from Kakarot.get_cairo1_helpers_class_hash()
  • add in Account.validate the logic from Interpreter.execute (see here)
  • fix unit tests
  • update all python utils to have the relayer send the txs
  • update ef-tests / remove Account_cairo1_helpers_class_hash storage / ensure nonce is not increased anymore (see here)

Snippet to send a tx with relayer in python

#%% Imports
import os
import random
os.environ["STARKNET_NETWORK"] = "katana"

from eth_account import Account as EvmAccount

from kakarot_scripts.utils.kakarot import *
from kakarot_scripts.utils.starknet import *
from kakarot_scripts.constants import RPC_CLIENT, NETWORK, DEFAULT_GAS_PRICE
from tests.utils.helpers import pack_calldata, rlp_encode_signed_data
from tests.utils.uint256 import int_to_uint256

#%% Get accounts
relayer = await get_starknet_account()
eoa = await get_eoa()

# %% Send tx
current_timestamp = (await RPC_CLIENT.get_block("latest")).timestamp
nonce = await eoa.get_nonce()
outside_execution = {
    "caller": int.from_bytes(b"ANY_CALLER", "big"),
    "nonce": nonce,
    "execute_after": current_timestamp - 60 * 60,
    "execute_before": current_timestamp + 60 * 60,
}
data_len = 130_000
random.seed(data_len)
typed_transaction = TypedTransaction.from_dict({
    "type": 0x2,
    "chainId": NETWORK["chain_id"],
    "nonce": nonce,
    "gas": 2_000_000,
    "maxPriorityFeePerGas": 1,
    "maxFeePerGas": DEFAULT_GAS_PRICE,
    "to": None,
    "value": 0,
    "data": os.urandom(data_len),
}).as_dict()
evm_tx = EvmAccount.sign_transaction(
    typed_transaction,
    hex(eoa.signer.private_key),
)
encoded_unsigned_tx = rlp_encode_signed_data(typed_transaction)
packed_encoded_unsigned_tx = pack_calldata(bytes(encoded_unsigned_tx))

response = await get_contract("account_contract", address=eoa.address, provider=relayer).functions["execute_from_outside"].invoke_v1(
    outside_execution=outside_execution,
    call_array=[{
        "to": 0xDEAD,
        "selector": 0xDEAD,
        "data_offset": 0,
        "data_len": len(packed_encoded_unsigned_tx),
    }],
    calldata=list(packed_encoded_unsigned_tx),
    signature=[
        *int_to_uint256(evm_tx.r),
        *int_to_uint256(evm_tx.s),
        evm_tx.v,
    ],
    max_fee=int(1e18)
)

Resolves: #1240


This change is Reviewable

@ClementWalter ClementWalter marked this pull request as draft July 1, 2024 13:20
@obatirou
Copy link
Collaborator

obatirou commented Jul 2, 2024

Todo:

  • create a function to calculate the access list cost without using the one from the interpreter
  • Unpack the tx data should be done only once directly execute_from_outside (362ae65)

@obatirou
Copy link
Collaborator

obatirou commented Jul 2, 2024

Todo:

  • validate gas in Account.validate (maybe rename to reflect validation of signature and gas)
  • move last validation steps from execute to validate

src/kakarot/gas.cairo Outdated Show resolved Hide resolved
src/kakarot/gas.cairo Outdated Show resolved Hide resolved
@obatirou obatirou force-pushed the cw/execute-from-outside branch 2 times, most recently from af0382b to 148463c Compare July 3, 2024 13:31
@ClementWalter ClementWalter merged commit 47c5ba1 into kkrt-labs:main Jul 17, 2024
6 checks passed
@ClementWalter ClementWalter deleted the cw/execute-from-outside branch July 17, 2024 11:14
matthieuauger pushed a commit to matthieuauger/kakarot that referenced this pull request Nov 9, 2024
rm StoredTransactionHash and transaction_hashes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: use execute_from_outside (SNIP-9) to broadcast eth tx
4 participants