Skip to content
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
27 changes: 18 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", default-featu
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", default-features = false }

chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
hex = { package = "const-hex", version = "1.6", features = ["hex"] }
solang-parser = "=0.3.1"

#[patch."https://github.com/gakonst/ethers-rs"]
Expand Down
3 changes: 1 addition & 2 deletions cast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ ethers-providers = { workspace = true }
ethers-signers = { workspace = true }
futures = "0.3"
eyre = "0.6"
rustc-hex = "2"
serde = "1"
serde_json = "1"
chrono.workspace = true
hex = "0.4"
hex.workspace = true
rayon = "1"

# aws
Expand Down
21 changes: 8 additions & 13 deletions cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub use rusoto_core::{
request::HttpClient as AwsHttpClient, Client as AwsClient,
};
pub use rusoto_kms::KmsClient;
use rustc_hex::{FromHexIter, ToHex};
use std::{
path::PathBuf,
str::FromStr,
Expand Down Expand Up @@ -915,8 +914,7 @@ impl SimpleCast {
/// }
/// ```
pub fn from_utf8(s: &str) -> String {
let s: String = s.as_bytes().to_hex();
format!("0x{s}")
hex::encode_prefixed(s)
}

/// Converts hex data into text data
Expand All @@ -935,13 +933,11 @@ impl SimpleCast {
/// }
/// ```
pub fn to_ascii(hex: &str) -> Result<String> {
let hex_trimmed = hex.trim_start_matches("0x");
let iter = FromHexIter::new(hex_trimmed);
let mut ascii = String::new();
for letter in iter.collect::<Vec<_>>() {
ascii.push(letter? as char);
let bytes = hex::decode(hex)?;
if !bytes.iter().all(u8::is_ascii) {
return Err(eyre::eyre!("Invalid ASCII bytes"))
}
Ok(ascii)
Ok(String::from_utf8(bytes).unwrap())
}

/// Converts fixed point number into specified number of decimals
Expand Down Expand Up @@ -1457,7 +1453,7 @@ impl SimpleCast {
}
};
let calldata = match encode_args(&func, args) {
Ok(res) => res.to_hex::<String>(),
Ok(res) => hex::encode(res),
Err(e) => eyre::bail!("Could not ABI encode the function and arguments. Did you pass in the right types?\nError\n{}", e),
};
let encoded = &calldata[8..];
Expand All @@ -1482,7 +1478,7 @@ impl SimpleCast {
pub fn calldata_encode(sig: impl AsRef<str>, args: &[impl AsRef<str>]) -> Result<String> {
let func = HumanReadableParser::parse_function(sig.as_ref())?;
let calldata = encode_args(&func, args)?;
Ok(format!("0x{}", calldata.to_hex::<String>()))
Ok(hex::encode_prefixed(calldata))
}

/// Generates an interface in solidity from either a local file ABI or a verified contract on
Expand Down Expand Up @@ -1609,8 +1605,7 @@ impl SimpleCast {
}
}

let namehash: String = node.to_hex();
Ok(format!("0x{namehash}"))
Ok(hex::encode_prefixed(node))
}

/// Keccak-256 hashes arbitrary data
Expand Down
3 changes: 1 addition & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ tempfile = "3"
# misc
eyre = "0.6"
color-eyre = "0.6"
rustc-hex = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
regex = { version = "1", default-features = false }
rpassword = "7"
hex = "0.4"
hex = { workspace = true, features = ["serde"] }
itertools = "0.10"
proptest = "1"
semver = "1"
Expand Down
19 changes: 3 additions & 16 deletions cli/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use foundry_common::{
},
};
use foundry_config::Config;
use rustc_hex::ToHex;
use std::time::Instant;

#[tokio::main]
Expand Down Expand Up @@ -83,21 +82,9 @@ async fn main() -> eyre::Result<()> {
Subcommands::ToHexdata { input } => {
let value = stdin::unwrap_line(input)?;
let output = match value {
s if s.starts_with('@') => {
let var = std::env::var(&s[1..])?;
var.as_bytes().to_hex()
}
s if s.starts_with('/') => {
let input = fs::read(s)?;
input.to_hex()
}
s => {
let mut output = String::new();
for s in s.split(':') {
output.push_str(&s.trim_start_matches("0x").to_lowercase())
}
output
}
s if s.starts_with('@') => hex::encode(std::env::var(&s[1..])?),
s if s.starts_with('/') => hex::encode(fs::read(s)?),
s => s.split(':').map(|s| s.trim_start_matches("0x").to_lowercase()).collect(),
};
println!("0x{output}");
}
Expand Down
8 changes: 3 additions & 5 deletions cli/src/cmd/forge/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use ethers::{
};
use eyre::Context;
use foundry_common::{abi::parse_tokens, compile, estimate_eip1559_fees};
use rustc_hex::ToHex;
use serde_json::json;
use std::{path::PathBuf, sync::Arc};

Expand Down Expand Up @@ -263,10 +262,9 @@ impl CreateArgs {
let code = Vec::new();
let encoded_args = abi
.constructor()
.ok_or(eyre::eyre!("could not find constructor"))?
.encode_input(code, &args)?
.to_hex::<String>();
constructor_args = Some(encoded_args);
.ok_or_else(|| eyre::eyre!("could not find constructor"))?
.encode_input(code, &args)?;
constructor_args = Some(hex::encode(encoded_args));
}

self.verify_preflight_check(constructor_args.clone(), chain).await?;
Expand Down
5 changes: 2 additions & 3 deletions cli/src/cmd/forge/verify/etherscan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use foundry_utils::Retry;
use futures::FutureExt;
use once_cell::sync::Lazy;
use regex::Regex;
use rustc_hex::ToHex;
use semver::{BuildMetadata, Version};
use std::{
fmt::Debug,
Expand Down Expand Up @@ -432,8 +431,8 @@ impl EtherscanVerificationProvider {
let encoded_args = encode_args(
&func,
&read_constructor_args_file(constructor_args_path.to_path_buf())?,
)?
.to_hex::<String>();
)?;
let encoded_args = hex::encode(encoded_args);
return Ok(Some(encoded_args[8..].into()))
}

Expand Down
2 changes: 1 addition & 1 deletion evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ethers = { workspace = true, features = ["ethers-solc"] }
# Encoding/decoding
serde_json = "1"
serde = "1"
hex = "0.4"
hex.workspace = true
jsonpath_lib = "0.3"

# Error handling
Expand Down
29 changes: 12 additions & 17 deletions evm/src/executor/inspector/cheatcodes/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use ethers::{
};
use foundry_common::{fmt::*, fs, get_artifact_path};
use foundry_config::fs_permissions::FsAccessKind;
use hex::FromHex;
use serde::Deserialize;
use serde_json::Value;
use std::{collections::BTreeMap, env, path::Path, process::Command, str::FromStr};
use std::{collections::BTreeMap, env, path::Path, process::Command};

/// Invokes a `Command` with the given args and returns the abi encoded response
///
Expand Down Expand Up @@ -211,22 +210,18 @@ fn value_to_token(value: &Value) -> Result<Token> {
Err(fmt_err!("Unsupported value: {number:?}"))
}
Value::String(string) => {
if let Some(val) = string.strip_prefix("0x") {
// If it can decoded as an address, it's an address
if let Ok(addr) = H160::from_str(string) {
Ok(Token::Address(addr))
} else if hex::decode(val).is_ok() {
// if length == 32 bytes, then encode as Bytes32, else Bytes
Ok(if val.len() == 64 {
Token::FixedBytes(Vec::from_hex(val).unwrap())
} else {
Token::Bytes(Vec::from_hex(val).unwrap())
})
} else {
// If incorrect length, pad 0 at the beginning
let arr = format!("0{val}");
Ok(Token::Bytes(Vec::from_hex(arr).unwrap()))
if let Some(mut val) = string.strip_prefix("0x") {
let s;
if val.len() % 2 != 0 {
s = format!("0{}", val);
val = &s[..];
}
let bytes = hex::decode(val)?;
Ok(match bytes.len() {
20 => Token::Address(Address::from_slice(&bytes)),
32 => Token::FixedBytes(bytes),
_ => Token::Bytes(bytes),
})
} else {
Ok(Token::String(string.to_owned()))
}
Expand Down
2 changes: 1 addition & 1 deletion forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ethers = { workspace = true, features = ["solc-full"] }
comfy-table = "6"
eyre = "0.6"
glob = "0.3"
hex = "0.4"
hex.workspace = true
once_cell = "1"
parking_lot = "0.12"
proptest = "1"
Expand Down
2 changes: 1 addition & 1 deletion ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ethers = { workspace = true }

crossterm = "0.26"
eyre = "0.6"
hex = "0.4"
hex.workspace = true
revm = { version = "3", features = ["std", "serde"] }
tui = { version = "0.19", default-features = false, features = ["crossterm"] }
3 changes: 1 addition & 2 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ ethers-solc = { workspace = true }
eyre = { version = "0.6", default-features = false }
futures = "0.3"
glob = "0.3"
hex = "0.4"
hex.workspace = true
once_cell = "1"
rand = "0.8"
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls"] }
rlp = "0.5"
rustc-hex = { version = "2", default-features = false }
serde = "1"
serde_json = { version = "1", default-features = false }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
Expand Down