kkrt-labs / kakarot-rpc Goto Github PK
View Code? Open in Web Editor NEWKakarot ZK EVM Ethereum RPC adapter
License: MIT License
Kakarot ZK EVM Ethereum RPC adapter
License: MIT License
decode_execute_at_address_return
is out-of-date compared to the latest version of Kakarot.
Update it in order to properly parse the return params of Kakarot.
There is now a last argument gas_used
in Kakarot execute_at_address
return payload
What chainID should we choose for the RPC ? I first though of 9001 because it's over 9000 but EVMOS already took it.
So 9000 as a fallback but seems not satisfying
Propose your ideas
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getBlockByHash
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Returns the current network id.
This method does not interact with the kakarot contract or any other starknet contract. The method returns a constant variable name CHAIN_ID
which needs to be determined see this issue.
Requests a specific account's number of transactions, in order to compute its nonce.
Call the Starknet starknet_getNonce
json rpc method. Return it.
Call an RPC node to estimate tx related gas : https://ethereum.github.io/execution-apis/api-documentation/
Describe the interaction with Kakarot and/or Starknet.
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_blockNumber
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the method
Does not interact with Kakarot
Calls Syncing in Starknet light client
Returns a list of accounts owned by the client.
No Kakarot logic.
For now, returns an empty Vector.
Returns token balances for a specific address given a list of contracts.
address
: The address for which token balances will be checked.contractAddresses
: An array of contract addresses.An object with the following fields:
address
: The address for which token balances were checked.tokenBalances
: An array of token balance objects. Each object contains:
contractAddress
: The address of the contract.tokenBalance
: The balance of the contract, as a string representing a base-10 number.error
: An error string. Either error
or tokenBalance
will be null.Calls Kakarot execute_at_address with "call signature" once for each contractAddresses
index -> calls balanceOf(address owner)
with parameter owner == address
.
Reconstructs the return format.
Call execute_at_address
n times,n == contractAddresses.len()
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getTransactionCount
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
As per @ClementWalter
and it seems like we don’t respect the workspace layout as defined in https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getTransactionReceipt
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the Feature Request
Ethereum JSON RPC spec manipulates various variables linked with gas -> gas_used, gas_price, baseFee, priorityFee etc.
Currently, Starknet does not have a market for gas but rather fixed gas prices as per a formula https://docs.starknet.io/documentation/architecture_and_concepts/Fees/fee-mechanism/
There are some challenges to separate actual_fee (variable caught from starknet transaction receipt) and separate it between gas_used and gas_price (baseFee + priorityFee)
Wherever gas_used / gas_price are used, should find a way them from derive actual_fee and max_fee
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_gasPrice
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getBlockByNumber
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Returns the number of most recent block.
This method does not interact with the kakarot contract or any other starknet contract.
Would be calling the corresponding starknet_blockNumber
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md
Currently we are getting an error when calling blockByNumber with full_txs = true, only full_txs = false is working, fix to return full txs data correctly.
Describe Preferred Solution
Describe Alternatives
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Describe the Feature Request
Currently, getTransactionReceipt allows for getting a specific starknet transaction receipt and converting it to the Ethereum format.
Unfortunately, logs are not yet included in this process.
Describe Preferred Solution
Write util to convert starknetlogs to eth logs.
Describe the Feature Request
Convert starknet transaction receipt logs to be EVM-format 'friendly' so it can be used in transaction_receipt.
Describe Preferred Solution
Describe Alternatives
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Describe the Feature Request
We currently use reth_primitives::H256
and reth_primitives::rpc::H256
types which create mismatch errors.
Currently we import both types :
use reth_primitives::{
rpc::H256,
H256 as PrimitiveH256,
};
reth_primitives::rpc::H256
is reexported from ethers-rs, we should use the main reth_primitives::H256
type instead which is a ruint::H256
.
Describe Preferred Solution
Use reth_primitives::H256
in the repo.
Doing this currently results in an error when using reth_primitives::rpc::BlockId::Hash
as it's reexported from ethers which uses primitives_types::H256
and not ruint::H256
. An issue is opened on reth repo to add a reth native BlockId type.
Describe Alternatives
In the meantime a workaround would be to use H256::from(val.0)
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Currently eth_getBlockTransactionCountByHash
and eth_getBlockTransactionCountByNumber
functions both fetch starknet_getBlockWithTxHashes
endpoint and then count the number of transactions in the block. When block is pending, both endpoints do not return anything.
Both functions should use starknet_getBlockTransactionCount
which returns the number of transactions for accepted and pending blocks.
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_estimateGas
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getLogs
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Returns the chain ID of the current network.
This method does not interact with the kakarot contract or any other starknet contract. The method returns a constant variable name CHAIN_ID
which needs to be determined see this issue.
Returns Keccak-256 (not the standardized SHA3-256) of the given data.
This method does not interact with the kakarot contract or any other starknet contract. This method uses the rust-crypto
package to hash the provided bytes with the keccak256 hash algorithm. The hex data provided was previously parsed by the hex
utils.
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_call
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the Feature Request
Currently, we don't handle discrepancies between EVM transaction hashes vs. Starknet transaction hashes. We should programmatically "know" whether a user is manipulating starknet tx hashes or evm tx hashes, and return the correct hash.
Example:
1.
User calls getTransactionReceipt, they will use an EVM tx hash, as this is the return value they get when calling eth_sendRawTransaction.
Thus, we need a deterministic mapping between an EVM tx hash and the resulting Starknet tx hash
Describe the method
-Bytecode : bytes
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_getCode
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Add unit testing for the function vec_felt_to_bytes
in the helpers.rs file
Returns true
if client is actively listening for network connections.
true
when listening, otherwise false
.For the moment, Kakarot is not a layer 3 so not a dedicated network. The RPC is not connected to any specific network with other nodes except to starknet. So as a temporary solution it returns true
if the connection is successful with the starknet RPC and if not it returns false
.
we don't need let tx_receipt = self.client.get_transaction_receipt(tx_hash).await?; to get blockhash_opt and blocknum_opt
we have access to block_id in the scope, we can simply design a module function that takes block_id and gets the missing info -> if block_id is a block_number, then get corresponding block_hash (with a client get_block_hash or smth with block_number and vice versa).
Currently, for speed / simplicity, we replicated types from eth inside types.rs
Let's delete them all and use only the reth types. Either reth_primitives or reth_primitives::rpc depending on our need.
We still need to discover whether or not reth_rpc::types will disappear as they suggested it was tech debt
Currently, we convert the signature array from starknet transactions to r, s, v parameters that are used in ECDSA.
Currently, signatures has only two items, example of a starknet tx:
{
"calldata": [
"0x1",
"0x4a3621276a83251b557a8140e915599ae8e7b6207b067ea701635c0d509801e",
"0x2d4c8ea4c8fb9f571d1f6f9b7692fff8e5ceaf73b1df98e7da8c1109b39ae9a",
"0x0",
"0x2",
"0x2",
"0x4767b873669406d25dddbf67356e385a14480979e5358a411955d692576aa30",
"0x1"
],
"max_fee": "0x11b1d9007c05c",
"nonce": "0x18",
"sender_address": "0xd90fd6aa27edd344c5cbe1fe999611416b268658e866a54265aaf50d9cf28d",
"signature": [
"0x3cd4f193f84704ce73cfb45abcdb0a169067b56821b267b9af6eb52531c94dc",
"0x6e0fac18be9cddae718054b6fe1cf7448015c1ef5a4fa5a7919665e0126e585"
],
"transaction_hash": "0x65eee3bd22766c75d5e5f55c747db41d192d0274a5579d8808b2c5850dd0f6a",
"type": "INVOKE",
"version": "0x1"
},
Current behavior:
The bug manifests as, when transforming to Ethereum transactions, we do:
// Extracting the signature
ether_tx.r = felt_option_to_u256(v1.signature.get(0))?;
ether_tx.s = felt_option_to_u256(v1.signature.get(1))?;
ether_tx.v = felt_option_to_u256(v1.signature.get(2))?;
Expected behavior:
insert short code snippets here
We should find a way to properly map `r, s, v` args in our transaction reports
getWork in PoW -> useless for PoS
Returns the current client version.
This method does not interact with the kakarot contract or any other starknet contract. Instead it will return the version of this repository with this format:
kakarot-rpc-adapter/vX.X.X/OS/rustX.X.X
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_chainId
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Describe the Feature Request
starknet_address_to_ethereum_address
helper function is used to get the EVM address of a Kakarot contract (be it an ExternallyOwnedAccount or a Contract account).
Currently starknet_address_to_ethereum_address
takes the last 20 bytes to represent a starknet address as an EVM address. However, all Kakarot contracts (EVM smart contracts or accounts) have a view method called get_evm_address
.
Describe Preferred Solution
Describe Alternatives
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Tests are not run in CI
cargo test --workspace
when ran, tests fail as we try to instantiate multiple times the rpc server on the same port (3030)
currently we have a mock impl. that is able to return mocked values of starknet json rpc endpoint, we can leverage that to test kakarot rpc core logic and check that it returns sound evm formatted payloads
Currently, eth_getBlockByNumber and eth_getBlockByHash return a Starknet block in the format of an EVM block-ish (some loss of information, and inserted zeroes).
We'd need to filter for Starknet transactions that interacted with Kakarot.
If there are no Kakarot transactions in a Block, we may return an empty Block.
Describe the Feature Request
Describe Preferred Solution
Describe Alternatives
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Currently we have the need to loop over futures.
We should use the idiomatic join_all
method on futures instead of for loops.
try_join_all
is suboptimal for our use case as it returns a Result<Vec<_>>
meaning that it requires all the calls to succeed.
join_all
returns a Vec<Result<_>>
which lets you handle every case in a singular way.
Task: replace all For loops on Async Futures by futures::join_all
and handle properly error cases for each vector element.
Currently we have an automock on Kakarot Eth Rpc, this results in inefficient testing. We would rather have to mock the StarknetClient!
Describe the Feature Request
Describe Preferred Solution
Describe Alternatives
Related Code
Additional Context
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
Implementing eth_getStorageAt
, quite similar way to eth_getCode
method
Describe the method
Describe the interaction with Kakarot and/or Starknet.
e.g. "this method does not interact with the kakarot contract or any other starknet contract."
Which Kakarot methods are called?
Which Starknet RPC methods are called? e.g. "Would be calling the corresponding starknet_sendRawTransaction
https://github.com/starkware-libs/starknet-specs/blob/master/starknet_vs_ethereum_node_apis.md"
Returns the number of peers currently connected to the client.
For the moment, Kakarot is not a layer 3 so not a dedicated network. The RPC is not connected to any specific network with other nodes except to starknet. So as a temporary solution it returns 0x1
if the connection is successful with the starknet RPC and if not it returns 0x0
.
Describe the Feature Request
Load these values from .env instead
pub const KAKAROT_MAIN_CONTRACT_ADDRESS: &str =
"0x566864dbc2ae76c2d12a8a5a334913d0806f85b7a4dccea87467c3ba3616e75";
pub const PROXY_ACCOUNT_CLASS_HASH: &str =
"0x0775033b738dfe34c48f43a839c3d882ebe521befb3447240f2d218f14816ef5";
Describe Preferred Solution
Use std::env::var("NAME")
Additional Context
This is useful as these parameters are expected to change often
If the feature request is approved, would you be willing to submit a PR?
(Help can be provided if you need assistance submitting a PR)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.