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

Devin Support #51

Merged
merged 5 commits into from
Mar 10, 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
523 changes: 259 additions & 264 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ codegen-units = 1
corebc = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-addressbook = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-core = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-contract = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-contract = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-contract-abigen = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-providers = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-signers = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-blockindex = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-middleware = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-blockindex = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
corebc-ylem = { git = "https://github.com/core-coin/corebc-rs.git", default-features = false }
revm = { git = "https://github.com/core-coin/cvm.git", default-features = false }
solang-parser = "=0.3.0"
solang-parser = "=0.3.0"
2 changes: 1 addition & 1 deletion abi/src/bindings/console.rs

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

13 changes: 10 additions & 3 deletions cli/src/cmd/probe/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use corebc::{
abi::Address,
prelude::{artifacts::ContractBytecodeSome, ArtifactId, Middleware},
types::H176,
types::{Network, H176},
};
use eyre::WrapErr;
use foxar_config::{find_project_root_path, Config};
Expand Down Expand Up @@ -95,7 +95,11 @@ impl RunArgs {

// Set up the execution environment
let env = evm_opts.evm_env().await;
let db = Backend::spawn(evm_opts.get_fork(&config, env.clone())).await;
let db = Backend::spawn(
evm_opts.get_fork(&config, env.clone()),
&Network::from(env.cfg.network_id),
)
.await;

// configures a bare version of the evm executor: no cheatcode inspector is enabled,
// tracing will be enabled only for the targeted transaction
Expand Down Expand Up @@ -220,7 +224,10 @@ impl RunArgs {
None
});

let mut decoder = CallTraceDecoderBuilder::new().with_labels(labeled_addresses).build();
let mut decoder =
CallTraceDecoderBuilder::new(&Network::from(executor.env().cfg.network_id))
.with_labels(labeled_addresses)
.build();

decoder.add_signature_identifier(SignaturesIdentifier::new(
Config::foxar_cache_dir(),
Expand Down
8 changes: 6 additions & 2 deletions cli/src/cmd/spark/script/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl ScriptArgs {
None => {
let backend = Backend::spawn(
script_config.evm_opts.get_fork(&script_config.config, env.clone()),
&Network::from(env.cfg.network_id),
)
.await;
script_config.backends.insert(url.clone(), backend);
Expand All @@ -298,8 +299,11 @@ impl ScriptArgs {
// It's only really `None`, when we don't pass any `--fork-url`. And if so, there is
// no need to cache it, since there won't be any onchain simulation that we'd need
// to cache the backend for.
Backend::spawn(script_config.evm_opts.get_fork(&script_config.config, env.clone()))
.await
Backend::spawn(
script_config.evm_opts.get_fork(&script_config.config, env.clone()),
&Network::from(env.cfg.network_id),
)
.await
}
};

Expand Down
14 changes: 8 additions & 6 deletions cli/src/cmd/spark/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use corebc::{
providers::Middleware,
signers::LocalWallet,
types::{
transaction::eip2718::TypedTransaction, Address, Log, NameOrAddress, TransactionRequest,
U256,
transaction::eip2718::TypedTransaction, Address, Log, NameOrAddress, Network,
TransactionRequest, U256,
},
ylem::contracts::ArtifactContracts,
};
Expand Down Expand Up @@ -208,10 +208,12 @@ impl ScriptArgs {
)?;

let mut local_identifier = LocalTraceIdentifier::new(known_contracts);
let mut decoder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.clone())
.with_verbosity(verbosity)
.build();
let mut decoder = CallTraceDecoderBuilder::new(
&script_config.evm_opts.get_remote_chain_id().unwrap_or(Network::Mainnet),
)
.with_labels(result.labeled_addresses.clone())
.with_verbosity(verbosity)
.build();

decoder.add_signature_identifier(SignaturesIdentifier::new(
Config::foxar_cache_dir(),
Expand Down
20 changes: 15 additions & 5 deletions cli/src/cmd/spark/script/runner.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::*;
use corebc::types::{Address, Bytes, NameOrAddress, U256};
use corebc::types::{Address, Bytes, NameOrAddress, Network, U256};
use spark::{
default_caller,
executor::{CallResult, DeployResult, EvmError, ExecutionErr, Executor, RawCallResult},
revm::interpreter::{return_ok, InstructionResult},
trace::{TraceKind, Traces},
CALLER,
};
use tracing::log::trace;

Expand Down Expand Up @@ -40,7 +40,9 @@ impl ScriptRunner {
trace!(target: "script", "executing setUP()");

if !is_broadcast {
if self.sender == Config::DEFAULT_SENDER {
if self.sender ==
Config::default_sender(&Network::from(self.executor.env().cfg.network_id))
{
// We max out their balance so that they can deploy and make calls.
self.executor.set_balance(self.sender, U256::MAX)?;
}
Expand All @@ -53,7 +55,10 @@ impl ScriptRunner {
self.executor.set_nonce(self.sender, sender_nonce.as_u64())?;

// We max out their balance so that they can deploy and make calls.
self.executor.set_balance(CALLER, U256::MAX)?;
self.executor.set_balance(
default_caller(&Network::from(self.executor.env().cfg.network_id)),
U256::MAX,
)?;

// Deploy libraries
let mut traces: Traces = libraries
Expand All @@ -78,7 +83,12 @@ impl ScriptRunner {
..
} = self
.executor
.deploy(CALLER, code.0, 0u32.into(), None)
.deploy(
default_caller(&Network::from(self.executor.env().cfg.network_id)),
code.0,
0u32.into(),
None,
)
.map_err(|err| eyre::eyre!("Failed to deploy script:\n{}", err))?;

traces.extend(constructor_traces.map(|traces| (TraceKind::Deployment, traces)));
Expand Down
14 changes: 8 additions & 6 deletions cli/src/cmd/spark/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
suggestions, utils,
};
use clap::Parser;
use corebc::types::U256;
use corebc::types::{Network, U256};
use foxar_common::{
compile::{self, ProjectCompiler},
evm::EvmArgs,
Expand Down Expand Up @@ -596,11 +596,13 @@ async fn test(

if !result.traces.is_empty() {
// Identify addresses in each trace
let mut decoder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.clone())
.with_events(local_identifier.events().cloned())
.with_verbosity(verbosity)
.build();
let mut decoder = CallTraceDecoderBuilder::new(
&config.network_id.unwrap_or(Network::Mainnet),
)
.with_labels(result.labeled_addresses.clone())
.with_events(local_identifier.events().cloned())
.with_verbosity(verbosity)
.build();

// Signatures are of no value for gas reports
if !gas_reporting {
Expand Down
8 changes: 6 additions & 2 deletions cli/src/opts/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,18 @@ pub trait WalletTrait {
fn get_from_interactive(&self) -> Result<LocalWallet> {
let private_key = rpassword::prompt_password("Enter private key: ")?;
let private_key = private_key.strip_prefix("0x").unwrap_or(&private_key);
Ok(LocalWallet::from_str(private_key)?)

let mut wallet = LocalWallet::from_str(private_key)?;
wallet = wallet.with_network_id(self.network().unwrap_or(Network::Mainnet));

Ok(wallet)
}

#[track_caller]
fn get_from_private_key(&self, private_key: &str) -> Result<LocalWallet> {
let privk = private_key.trim().strip_prefix("0x").unwrap_or(private_key);
match LocalWallet::from_str(privk) {
Ok(pk) => Ok(pk),
Ok(pk) => Ok(pk.with_network_id(self.network().unwrap_or(Network::Mainnet))),
Err(err) => {
// helper closure to check if pk was meant to be an env var, this usually happens if
// `$` is missing
Expand Down
3 changes: 2 additions & 1 deletion cli/src/opts/wallet/multi_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ impl MultiWallet {
let mut error_msg = String::new();

// This is an actual used address
if addresses.contains(&Config::DEFAULT_SENDER) {
if addresses.contains(&Config::default_sender(&self.network().unwrap_or(Network::Mainnet)))
{
error_msg += "\nYou seem to be using Foxar's default sender. Be sure to set your own --sender.\n";
}

Expand Down
37 changes: 27 additions & 10 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#![deny(missing_docs, unsafe_code, unused_crate_dependencies)]

use crate::cache::StorageCachingConfig;
use corebc_core::types::{Address, Network, H176, U256};
use corebc_core::{
types::{Address, Network, H160, H176, U256},
utils::to_ican,
};
pub use corebc_ylem::artifacts::OptimizerDetails;
use corebc_ylem::{
artifacts::{
Expand Down Expand Up @@ -397,12 +400,16 @@ impl Config {
pub const FOXAR_DIR_NAME: &'static str = ".foxar";

/// Default address for tx.origin
///
/// `0xcb681804c8ab1f12e6bbf3894d4083f33e07309d1f38`
pub const DEFAULT_SENDER: H176 = H176([
0xcb, 0x68, 0x18, 0x04, 0xc8, 0xAB, 0x1F, 0x12, 0xE6, 0xbb, 0xF3, 0x89, 0x4D, 0x40, 0x83,
0xF3, 0x3E, 0x07, 0x30, 0x9D, 0x1F, 0x38,
]);
/// Depending on network has different prefix and checksum
pub fn default_sender(network: &Network) -> H176 {
/// `0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38`
const DEFAULT_SENDER: &H160 = &H160([
0x18, 0x04, 0xc8, 0xAB, 0x1F, 0x12, 0xE6, 0xbb, 0xF3, 0x89, 0x4D, 0x40, 0x83, 0xF3,
0x3E, 0x07, 0x30, 0x9D, 0x1F, 0x38,
]);

to_ican(DEFAULT_SENDER, network)
}

/// Returns the current `Config`
///
Expand Down Expand Up @@ -1749,8 +1756,8 @@ impl Default for Config {
fuzz: Default::default(),
invariant: Default::default(),
ffi: false,
sender: Config::DEFAULT_SENDER,
tx_origin: Config::DEFAULT_SENDER,
sender: Config::default_sender(&Network::Mainnet),
tx_origin: Config::default_sender(&Network::Mainnet),
initial_balance: U256::from(0xffffffffffffffffffffffffu128),
block_number: 1,
fork_block_number: None,
Expand Down Expand Up @@ -2488,9 +2495,19 @@ mod tests {
#[test]
fn default_sender() {
assert_eq!(
Config::DEFAULT_SENDER,
Config::default_sender(&Network::Mainnet),
"cb681804c8ab1f12e6bbf3894d4083f33e07309d1f38".parse().unwrap()
);

assert_eq!(
Config::default_sender(&Network::Devin),
"ab861804c8ab1f12e6bbf3894d4083f33e07309d1f38".parse().unwrap()
);

assert_eq!(
Config::default_sender(&Network::Private(5)),
"ce591804c8ab1f12e6bbf3894d4083f33e07309d1f38".parse().unwrap()
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ During the first execution stage on `spark script`, foxar has to adjust the nonc

Making sure that `msg.sender` is our signer when calling `setUp()` and `run()` and that its nonce is correct (decreased by one on each call) when calling `vm.broadcast` to create a contract.

We skip this, if the user hasn't set a sender and they're using the `Config::DEFAULT_SENDER`.
We skip this, if the user hasn't set a sender and they're using the `Config::default_sender({network})`.


```mermaid
Expand Down
Loading