Skip to content

Commit

Permalink
Fix publishing to crates.io; Release 0.2.2 (#638)
Browse files Browse the repository at this point in the history
* fix publishing script by copying files to target folder.

* add step to circleci build process to ensure that problems are catched on time

* changes

* edit ci pipeline

* edit ci config

* edit ci config

* circle ci config

* edit ci config

* edit script + ci

* ci config

* reduced ci

* restore ci

* config

* extend command

* edit cp

* edit script

* move files around and change constants

* restore config with all steps

* refactor files and fix test

* remove files

* fix test

* edit script

* skip testing for faster ci

* check another command

* reduce ci steps

* try with latest stable toolchain

* Revert "try with latest stable toolchain"

This reverts commit 388e56b.

* restore scrits

* changed constant

* update version to 0.2.2

* remove empty line

* edit ci config

* website new version

* edit generate_artifacts script to copy file to starknet-devnet-core crate
  • Loading branch information
marioiordanov authored Oct 30, 2024
1 parent 6fbc80c commit ef789b7
Show file tree
Hide file tree
Showing 39 changed files with 1,456 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ cairo-lang-syntax = "=2.7.0"
cairo-lang-utils = "=2.7.0"

# Inner dependencies
starknet-types = { version = "0.2.1", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.2.1", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.2.1", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }
starknet-types = { version = "0.2.2", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.2.2", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.2.2", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }

# Dependabot alerts
zerocopy = "0.7.31"
Expand Down
3 changes: 2 additions & 1 deletion contracts/generate_artifacts.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ set -eu

# Bash script to generate the artifacts required by Devnet to compile.
mkdir -p l1-l2-artifacts
mkdir -p ../crates/starknet-devnet-core/contracts/l1-l2-artifacts

# L1-L2 messaging:
## SOLIDITY
forge build --root ./l1-l2-messaging/solidity
cp ./l1-l2-messaging/solidity/out/MockStarknetMessaging.sol/MockStarknetMessaging.json ./l1-l2-artifacts/
cp ./l1-l2-messaging/solidity/out/L1L2.sol/L1L2Example.json ./l1-l2-artifacts/
cp ./l1-l2-messaging/solidity/out/MockStarknetMessaging.sol/MockStarknetMessaging.json ../crates/starknet-devnet-core/contracts/l1-l2-artifacts/

## CAIRO
scarb --manifest-path ./l1-l2-messaging/cairo/Scarb.toml build
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-core"
version = "0.2.1"
version = "0.2.2"
edition.workspace = true
repository.workspace = true
license-file.workspace = true
Expand Down
37 changes: 25 additions & 12 deletions crates/starknet-devnet-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@ use nonzero_ext::nonzero;
use starknet_rs_core::types::Felt;
use starknet_types::chain_id::ChainId;

pub const CAIRO_0_ACCOUNT_CONTRACT: &str = include_str!(
"../../../contracts/accounts_artifacts/OpenZeppelin/0.5.1/Account.cairo/Account.json"
);
pub const CAIRO_0_ACCOUNT_CONTRACT: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/accounts_artifacts/OpenZeppelin/0.5.1/Account.cairo/Account.json"
));

pub const CAIRO_0_ACCOUNT_CONTRACT_HASH: &str =
"0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f";

/// only used in tests; if artifact needed in production, use CAIRO_1_ACCOUNT_CONTRACT_SIERRA
pub const CAIRO_1_ACCOUNT_CONTRACT_SIERRA_PATH: &str =
"../../contracts/accounts_artifacts/OpenZeppelin/0.8.1/Account.cairo/Account.sierra";
pub const CAIRO_1_ACCOUNT_CONTRACT_SIERRA_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/accounts_artifacts/OpenZeppelin/0.8.1/Account.cairo/Account.sierra"
);

pub const CAIRO_1_ACCOUNT_CONTRACT_SIERRA: &str = include_str!(
"../../../contracts/accounts_artifacts/OpenZeppelin/0.8.1/Account.cairo/Account.sierra"
pub const CAIRO_1_ACCOUNT_CONTRACT_0_8_0_SIERRA_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/accounts_artifacts/OpenZeppelin/0.8.0/Account.cairo/Account.sierra"
);

pub const CAIRO_1_ACCOUNT_CONTRACT_SIERRA: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/accounts_artifacts/OpenZeppelin/0.8.1/Account.cairo/Account.sierra"
));

pub const CAIRO_1_ACCOUNT_CONTRACT_SIERRA_HASH: &str =
"0x061dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f";

pub const CAIRO_1_ERC20_CONTRACT: &str =
include_str!("../../../contracts/accounts_artifacts/ERC20_Mintable_OZ_0.8.1.sierra");
pub const CAIRO_1_ERC20_CONTRACT: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/system_artifacts/ERC20_Mintable_OZ_0.8.1.sierra"
));

/// ERC20 class hash is hardcoded to be the same as OZ class hash ERC20.cairo although it should be
/// different, due to commented key attributes in struct Approval (owner and spender), and add of
Expand All @@ -34,7 +45,7 @@ pub const CAIRO_1_ERC20_CONTRACT_CLASS_HASH: Felt =

/// only used in tests; if artifact needed in production, add a new constant that uses include_str!
pub const CAIRO_0_ERC20_CONTRACT_PATH: &str =
"../../contracts/accounts_artifacts/ERC20_Mintable_OZ_0.2.0.json";
concat!(env!("CARGO_MANIFEST_DIR"), "/contracts/system_artifacts/ERC20_Mintable_OZ_0.2.0.json");

pub const CAIRO_0_ERC20_CONTRACT_CLASS_HASH: &str =
"0x6A22BF63C7BC07EFFA39A25DFBD21523D211DB0100A0AFD054D172B81840EAF";
Expand All @@ -45,8 +56,10 @@ pub const ETH_ERC20_CONTRACT_ADDRESS: Felt =
pub const STRK_ERC20_CONTRACT_ADDRESS: Felt =
Felt::from_hex_unchecked("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d");

pub(crate) const UDC_CONTRACT: &str =
include_str!("../../../contracts/accounts_artifacts/UDC_OZ_0.5.0.json");
pub(crate) const UDC_CONTRACT: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/contracts/system_artifacts/UDC_OZ_0.5.0.json"
));

pub const UDC_CONTRACT_CLASS_HASH: Felt =
Felt::from_hex_unchecked("0x7B3E05F48F0C69E4A65CE5E076A66271A527AFF2C34CE1083EC6E1526997A69");
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-core/src/messaging/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod abigen {
use ethers::prelude::abigen;
abigen!(
MockStarknetMessaging,
"../../contracts/l1-l2-artifacts/MockStarknetMessaging.json",
"$CARGO_MANIFEST_DIR/contracts/l1-l2-artifacts/MockStarknetMessaging.json",
event_derives(serde::Serialize, serde::Deserialize)
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-server"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
repository.workspace = true
license-file.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-types"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
description = "Starknet types for the devnet"
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
repository.workspace = true
license-file.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions crates/starknet-devnet/tests/test_fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ mod fork_tests {
use std::sync::Arc;

use server::test_utils::assert_contains;
use starknet_core::constants::CAIRO_1_ERC20_CONTRACT_CLASS_HASH;
use starknet_core::constants::{
CAIRO_1_ACCOUNT_CONTRACT_0_8_0_SIERRA_PATH, CAIRO_1_ERC20_CONTRACT_CLASS_HASH,
};
use starknet_rs_accounts::{
Account, AccountFactory, AccountFactoryError, ExecutionEncoding,
OpenZeppelinAccountFactory, SingleOwnerAccount,
Expand Down Expand Up @@ -368,7 +370,7 @@ mod fork_tests {
"--state-archive-capacity",
"full",
"--account-class-custom",
"../../contracts/accounts_artifacts/OpenZeppelin/0.8.0/Account.cairo/Account.sierra",
CAIRO_1_ACCOUNT_CONTRACT_0_8_0_SIERRA_PATH,
])
.await
.unwrap();
Expand Down
85 changes: 85 additions & 0 deletions website/versioned_docs/version-0.2.2/account-impersonation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Account impersonation

:::info

This page is about account impersonation. To read about account class selection and deployment, click [here](./predeployed).

:::

## Introduction

Devnet allows you to use impersonated account from mainnet/testnet. This means that a transaction sent from an impersonated account will not fail with an invalid signature error. In the general case, a transaction sent with an account that is not in the local state fails with the aforementioned error. For impersonation to work, Devnet needs to be run in [forking mode](./forking.md).

:::warning Caveat

- Only `INVOKE` and `DECLARE` transactions are supported. `DEPLOY_ACCOUNT` transaction is not supported, but you can create an `INVOKE` transaction to UDC.
- Overall fee, for transactions sent with an impersonated account, will be lower compared to normal transactions. The reason is that validation part is skipped.
- The most common way of sending a transaction is via starknet-rs/starknet.js or starkli. Trying to send with an account that **does not** exist even in the origin network will return an error:
- In transaction construction, if account nonce is not hardcoded, Devnet is queried and returns `ContractNotFound`.
- Otherwise the nonce fetching part is skipped and `InsufficientAccountBalance` is returned.

:::

## Disabling impersonation

Click [here](./restrictive.md) to learn how to disable account impersonation.

## API

Account impersonation follows JSON-RPC method specification. Each method returns an empty response:

### devnet_impersonateAccount

Impersonates a specific account address nonexistent in the local state.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_impersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_stopImpersonateAccount

Stops the impersonation of an account previously marked for impersonation.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopImpersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_autoImpersonate

Enables automatic account impersonation. Every account that does not exist in the local state will be impersonated.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_autoImpersonate",
"params": {}
}
```

### devnet_stopAutoImpersonate

Stops the effect of [automatic impersonation](#devnet_autoimpersonate).

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopAutoImpersonate",
"params": {}
}
```
70 changes: 70 additions & 0 deletions website/versioned_docs/version-0.2.2/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
sidebar_position: 3
---

# API

## JSON-RPC API

Both Starknet's and Devnet's JSON-RPC API are reachable at `/rpc` and `/`. E.g. if spawning Devnet with default settings, these URLs are functionally equivalent: `http://127.0.0.1:5050/rpc` and `http://127.0.0.1:5050/`. The difference between these two groups of methods is their prefix: `starknet_` (e.g. `starknet_getNonce`) and `devnet_` (e.g. `devnet_mint`).

### Starknet API

Unlike Pythonic Devnet, which also supported Starknet's gateway and feeder gateway API, Devnet in Rust supports [Starknet's JSON-RPC API](https://github.com/starkware-libs/starknet-specs/tree/master/api). Since JSON-RPC v0.6.0, to find out which JSON-RPC version is supported by which Devnet version, check out the [releases page](https://github.com/0xspaceshard/starknet-devnet-rs/releases).

### Devnet API

Devnet has many additional features which are available via their own endpoints and JSON-RPC. The RPC methods are documented throughout the documentation in their corresponding pages, but are also aggregated [here](https://github.com/0xSpaceShard/starknet-devnet-rs/blob/main/website/static/devnet_api.json).

:::warning Deprecation notice

New features are only supported as part of the JSON-RPC API. Older non-RPC requests are still supported, but considered deprecated - they will be removed in the future, except the [healthcheck endpoint](#healthcheck).

:::

#### Healthcheck

To check if a Devnet instance is alive, send an HTTP request `GET /is_alive`. If alive, the Devnet will reply with a `200 OK` and an appropriate message.

## Interacting with Devnet in JavaScript and TypeScript

To spawn Devnet and interact with it using the [Devnet API](#devnet-api), you can use [`starknet-devnet-js`](https://github.com/0xSpaceShard/starknet-devnet-js/). This can be especially useful in achieving [L1-L2 communication](./postman.md#l1-l2-interaction-via-postman).

To interact with Devnet using the [Starknet API](#starknet-api), use [starknet.js](https://www.starknetjs.com/).

## Config API

To retrieve the current configuration of Devnet, as specified via [CLI](running/cli.md) and later requests, send a `GET` request to `/config` or `JSON-RPC` request with method name `devnet_getConfig`. Example response is attached below. It can be interpreted as a JSON mapping of CLI input parameters, both specified and default ones, with some irrelevant parameters omitted. So use `starknet-devnet --help` to better understand the meaning of each value, though keep in mind that some of the parameters have slightly modified names.

```json
{
"seed": 4063802897,
"total_accounts": 10,
"account_contract_class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
"predeployed_accounts_initial_balance": "1000000000000000000000",
"start_time": null,
"gas_price_wei": 100000000000,
"gas_price_fri": 100000000000,
"data_gas_price_wei": 100000000000,
"data_gas_price_fri": 100000000000,
"chain_id": "SN_SEPOLIA",
"dump_on": "exit",
"dump_path": "dump_path.json",
"state_archive": "none",
"fork_config": {
"url": "http://rpc.pathfinder.equilibrium.co/integration-sepolia/rpc/v0_7",
"block_number": 26429
},
"server_config": {
"host": "127.0.0.1",
"port": 5050,
"timeout": 120,
"request_body_size_limit": 2000000,
"restricted_methods": null
},
"block_generation": null,
"lite_mode": false,
"eth_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0",
"strk_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0"
}
```
Loading

0 comments on commit ef789b7

Please sign in to comment.