Skip to content
Closed
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
21 changes: 11 additions & 10 deletions Cargo.lock

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

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Benchmarks TBD in the future, but:
- [ ] `run-tx`
- [x] `send` (partial)
- [ ] `sign`
- [ ] `storage`
- [x] `storage`
- [ ] `tx`
- dapp
- [ ] test
Expand All @@ -137,13 +137,16 @@ Benchmarks TBD in the future, but:
- [ ] Symbolic execution
- [ ] Coverage
- [ ] HEVM-style Solidity cheatcodes
- [x] roll
- [x] warp
- [x] ffi
- [x] store
- [x] load
- [ ] sign
- [ ] addr
- [x] roll: Sets block.number
- [x] warp: Sets block.timestamp
- [x] ffi: Perform foreign function call to terminal
- [x] store: Sets address storage slot
- [x] load: Loads address storage slot
- [x] deal: Sets account balance
- [x] prank: Performs a call as another address (changes msg.sender for a call)
- [x] sign: Signs data
- [x] addr: Gets address for a private key
- [x] etch: Sets the code of an address
- [ ] makeEOA
- ...?
- [ ] Structured tracing with abi decoding
Expand Down
1 change: 1 addition & 0 deletions dapptools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ evmodin = { git = "https://github.com/vorot93/evmodin", optional = true }
proptest = "1.0.0"
git2 = "0.13.22"
glob = "0.3.0"
semver = "1.0.4"

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
14 changes: 13 additions & 1 deletion dapptools/src/dapp_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ impl std::convert::TryFrom<&BuildOpts> for Project {
let paths = paths_builder.build()?;

// build the project w/ allowed paths = root and all the libs
let project = Project::builder().paths(paths).allowed_path(root).build()?;
let mut builder = Project::builder().paths(paths).allowed_path(root);

if opts.no_auto_detect {
builder = builder.no_auto_detect();
}

let project = builder.build()?;

Ok(project)
}
Expand Down Expand Up @@ -251,6 +257,12 @@ pub struct BuildOpts {

#[structopt(help = "choose the evm version", long, default_value = "london")]
pub evm_version: EvmVersion,

#[structopt(
help = "if set to true, skips auto-detecting solc and uses what is in the user's $PATH ",
long
)]
pub no_auto_detect: bool,
}
#[derive(Clone, Debug)]
pub enum EvmType {
Expand Down
31 changes: 21 additions & 10 deletions dapptools/src/seth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ async fn main() -> eyre::Result<()> {
let opts = Opts::from_args();
match opts.sub {
Subcommands::FromUtf8 { text } => {
println!("{}", SimpleSeth::from_utf8(&text));
let val = unwrap_or_stdin(text)?;
println!("{}", SimpleSeth::from_utf8(&val));
}
Subcommands::ToHex { decimal } => {
let val = unwrap_or_stdin(decimal)?;
println!("{}", SimpleSeth::hex(U256::from_dec_str(&val)?));
}
Subcommands::ToHexdata { input } => {
let output = match input {
let val = unwrap_or_stdin(input)?;
let output = match val {
s if s.starts_with('@') => {
let var = std::env::var(&s[1..])?;
var.as_bytes().to_hex()
Expand All @@ -45,16 +47,20 @@ async fn main() -> eyre::Result<()> {
println!("0x{}", output);
}
Subcommands::ToCheckSumAddress { address } => {
println!("{}", SimpleSeth::checksum_address(&address)?);
let val = unwrap_or_stdin(address)?;
println!("{}", SimpleSeth::checksum_address(&val)?);
}
Subcommands::ToAscii { hexdata } => {
println!("{}", SimpleSeth::ascii(&hexdata)?);
let val = unwrap_or_stdin(hexdata)?;
println!("{}", SimpleSeth::ascii(&val)?);
}
Subcommands::ToBytes32 { bytes } => {
println!("{}", SimpleSeth::bytes32(&bytes)?);
let val = unwrap_or_stdin(bytes)?;
println!("{}", SimpleSeth::bytes32(&val)?);
}
Subcommands::ToDec { hexvalue } => {
println!("{}", SimpleSeth::to_dec(&hexvalue)?);
let val = unwrap_or_stdin(hexvalue)?;
println!("{}", SimpleSeth::to_dec(&val)?);
}
Subcommands::ToFix { decimals, value } => {
let val = unwrap_or_stdin(value)?;
Expand All @@ -64,7 +70,8 @@ async fn main() -> eyre::Result<()> {
);
}
Subcommands::ToUint256 { value } => {
println!("{}", SimpleSeth::to_uint256(value)?);
let val = unwrap_or_stdin(value)?;
println!("{}", SimpleSeth::to_uint256(&val)?);
}
Subcommands::ToWei { value, unit } => {
let val = unwrap_or_stdin(value)?;
Expand Down Expand Up @@ -166,6 +173,11 @@ async fn main() -> eyre::Result<()> {
}
println!("{}", name);
}
Subcommands::Storage { address, slot, rpc_url, block } => {
let provider = Provider::try_from(rpc_url)?;
let value = provider.get_storage_at(address, slot, block).await?;
println!("{:?}", value);
}
};

Ok(())
Expand All @@ -179,10 +191,9 @@ where
Ok(match what {
Some(what) => what,
None => {
use std::io::Read;
let mut input = std::io::stdin();
let input = std::io::stdin();
let mut what = String::new();
input.read_to_string(&mut what)?;
input.read_line(&mut what)?;
T::from_str(&what.replace("\n", ""))?
}
})
Expand Down
44 changes: 35 additions & 9 deletions dapptools/src/seth_opts.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{convert::TryFrom, str::FromStr, sync::Arc};

use ethers::{
providers::{Http, Provider},
signers::{coins_bip39::English, LocalWallet, MnemonicBuilder},
types::{Address, BlockId, BlockNumber, NameOrAddress, H256, U64},
};
use eyre::Result;
use std::{convert::TryFrom, str::FromStr};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand All @@ -13,7 +14,7 @@ pub enum Subcommands {
#[structopt(aliases = &["--from-ascii"])]
#[structopt(name = "--from-utf8")]
#[structopt(about = "convert text data into hexdata")]
FromUtf8 { text: String },
FromUtf8 { text: Option<String> },
#[structopt(name = "--to-hex")]
#[structopt(about = "convert a decimal number into hex")]
ToHex { decimal: Option<String> },
Expand All @@ -26,25 +27,26 @@ pub enum Subcommands {
- absolute path to file
- @tag, where $TAG is defined in environment variables
"#)]
ToHexdata { input: String },
ToHexdata { input: Option<String> },
#[structopt(aliases = &["--to-checksum"])] // Compatibility with dapptools' seth
#[structopt(name = "--to-checksum-address")]
#[structopt(about = "convert an address to a checksummed format (EIP-55)")]
ToCheckSumAddress { address: Address },
ToCheckSumAddress { address: Option<Address> },
#[structopt(name = "--to-ascii")]
#[structopt(about = "convert hex data to text data")]
ToAscii { hexdata: String },
ToAscii { hexdata: Option<String> },
#[structopt(name = "--to-bytes32")]
#[structopt(about = "left-pads a hex bytes string to 32 bytes)")]
ToBytes32 { bytes: String },
ToBytes32 { bytes: Option<String> },
#[structopt(name = "--to-dec")]
#[structopt(about = "convert hex value into decimal number")]
ToDec { hexvalue: String },
ToDec { hexvalue: Option<String> },
#[structopt(name = "--to-fix")]
#[structopt(about = "convert integers into fixed point with specified decimals")]
ToFix { decimals: Option<u128>, value: Option<String> },
#[structopt(name = "--to-uint256")]
#[structopt(about = "convert a number into uint256 hex string with 0x prefix")]
ToUint256 { value: String },
ToUint256 { value: Option<String> },
#[structopt(name = "--to-wei")]
#[structopt(about = "convert an ETH amount into wei")]
ToWei { value: Option<String>, unit: Option<String> },
Expand Down Expand Up @@ -180,6 +182,22 @@ pub enum Subcommands {
)]
verify: bool,
},
#[structopt(name = "storage", about = "Show the raw value of a contract's storage slot")]
Storage {
#[structopt(help = "the contract address", parse(try_from_str = parse_name_or_address))]
address: NameOrAddress,
#[structopt(help = "the storage slot number (hex or number)", parse(try_from_str = parse_slot))]
slot: H256,
#[structopt(short, long, env = "ETH_RPC_URL")]
rpc_url: String,
#[structopt(
long,
short,
help = "the block you want to query, can also be earliest/latest/pending",
parse(try_from_str = parse_block_id)
)]
block: Option<BlockId>,
},
}

fn parse_name_or_address(s: &str) -> eyre::Result<NameOrAddress> {
Expand All @@ -199,6 +217,15 @@ fn parse_block_id(s: &str) -> eyre::Result<BlockId> {
})
}

fn parse_slot(s: &str) -> eyre::Result<H256> {
Ok(if s.starts_with("0x") {
let padded = format!("{:0>64}", s.strip_prefix("0x").unwrap());
H256::from_str(&padded)?
} else {
H256::from_low_u64_be(u64::from_str(s)?)
})
}

#[derive(Debug, StructOpt)]
pub struct Opts {
#[structopt(subcommand)]
Expand Down Expand Up @@ -226,7 +253,6 @@ pub struct EthereumOpts {
}

// TODO: Improve these so that we return a middleware trait object
use std::sync::Arc;
impl EthereumOpts {
#[allow(unused)]
pub fn provider(&self) -> eyre::Result<Arc<Provider<Http>>> {
Expand Down
Loading