Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
[account-address] Make all inputs fuzzy for unknown hex literals
Browse files Browse the repository at this point in the history
Given that there is a lot of code around hex literals, including a bunch that are
questionable about how they add 0x in front, I've switched them to fuzzy for now.

We can clean them up later and ensure it's in a better state later, but some functionality
is currently broken due to inconsistent outputs.
  • Loading branch information
gregnazario committed Apr 20, 2022
1 parent 9ddee79 commit b76efe2
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions language/extensions/async/move-async-vm/tests/testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ impl Harness {
if parts.len() != 3 {
bail!("malformed instance decl `{}`", inst)
}
let address = AccountAddress::from_hex_literal(parts[0])?;
let address = AccountAddress::from_hex_fuzzy(parts[0])?;
let module = Identifier::from_str(parts[1])?;
let inst_address = AccountAddress::from_hex_literal(parts[2])?;
let inst_address = AccountAddress::from_hex_fuzzy(parts[2])?;
result.push((ModuleId::new(address, module), inst_address))
}
Ok(result)
Expand Down
4 changes: 2 additions & 2 deletions language/move-core/types/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<I: Iterator<Item = Token>> Parser<I> {
vec![]
};
TypeTag::Struct(StructTag {
address: AccountAddress::from_hex_literal(&addr)?,
address: AccountAddress::from_hex_fuzzy(&addr)?,
module: Identifier::new(module)?,
name: Identifier::new(name)?,
type_params: ty_args,
Expand All @@ -311,7 +311,7 @@ impl<I: Iterator<Item = Token>> Parser<I> {
Token::True => TransactionArgument::Bool(true),
Token::False => TransactionArgument::Bool(false),
Token::Address(addr) => {
TransactionArgument::Address(AccountAddress::from_hex_literal(&addr)?)
TransactionArgument::Address(AccountAddress::from_hex_fuzzy(&addr)?)
}
Token::Bytes(s) => TransactionArgument::U8Vector(hex::decode(s)?),
tok => bail!("unexpected token {:?}, expected transaction argument", tok),
Expand Down
2 changes: 1 addition & 1 deletion language/move-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub fn addr_to_big_uint(addr: &AccountAddress) -> BigUint {
pub fn big_uint_to_addr(i: &BigUint) -> AccountAddress {
// TODO: do this in more efficient way (e.g., i.to_le_bytes() and pad out the resulting Vec<u8>
// to ADDRESS_LENGTH
AccountAddress::from_hex_literal(&format!("{:#x}", i)).unwrap()
AccountAddress::from_hex_literal(&format!("{:#X}", i)).unwrap()
}

pub fn parse_addresses_from_options(
Expand Down
2 changes: 1 addition & 1 deletion language/move-prover/interpreter/src/concrete/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'env> Evaluator<'env> {
fn evaluate_constant(&self, val: &Value) -> BaseValue {
match val {
Value::Address(v) => BaseValue::mk_address(
AccountAddress::from_hex_literal(&format!("{:#x}", v)).unwrap(),
AccountAddress::from_hex_literal(&format!("{:#X}", v)).unwrap(),
),
Value::Number(v) => BaseValue::mk_num(v.clone()),
Value::Bool(v) => BaseValue::mk_bool(*v),
Expand Down
2 changes: 1 addition & 1 deletion language/move-prover/interpreter/src/concrete/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl<'env> FunctionContext<'env> {
Constant::U128(v) => TypedValue::mk_u128(*v),
Constant::U256(_) => unimplemented!(),
Constant::Address(v) => TypedValue::mk_address(
AccountAddress::from_hex_literal(&format!("{:#x}", v)).unwrap(),
AccountAddress::from_hex_literal(&format!("{:#X}", v)).unwrap(),
),
Constant::ByteArray(v) => {
let elems = v.iter().map(|e| TypedValue::mk_u8(*e)).collect();
Expand Down
2 changes: 1 addition & 1 deletion language/move-prover/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn parse_entrypoint(input: &str) -> Result<(ModuleId, Identifier)> {
bail!("Invalid entrypoint: {}", input);
}
let module_id = ModuleId::new(
AccountAddress::from_hex_literal(tokens[0])?,
AccountAddress::from_hex_fuzzy(tokens[0])?,
Identifier::new(tokens[1])?,
);
let func_name = Identifier::new(tokens[2])?;
Expand Down
2 changes: 1 addition & 1 deletion language/move-prover/move-errmapgen/src/errmapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'env> ErrmapGen<'env> {

fn get_module_id_for_name(&self, module: &ModuleEnv<'_>) -> ModuleId {
let name = module.get_name();
let addr = AccountAddress::from_hex_literal(&format!("0x{:x}", name.addr())).unwrap();
let addr = AccountAddress::from_hex_literal(&format!("{:#X}", name.addr())).unwrap();
let name = Identifier::new(self.name_string(name.name()).to_string()).unwrap();
ModuleId::new(addr, name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn analyze_read_write_set(

let signer_addresses = signers
.iter()
.map(|s| AccountAddress::from_hex_literal(s))
.map(|s| AccountAddress::from_hex_fuzzy(s))
.collect::<Result<Vec<AccountAddress>, _>>()?;
// TODO: parse Value's directly instead of going through the indirection of TransactionArgument?
let script_args: Vec<Vec<u8>> = convert_txn_args(txn_args);
Expand Down
2 changes: 1 addition & 1 deletion language/tools/move-cli/src/sandbox/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ move run` must be applied to a module inside `storage/`",

let signer_addresses = signers
.iter()
.map(|s| AccountAddress::from_hex_literal(s))
.map(|s| AccountAddress::from_hex_fuzzy(s))
.collect::<Result<Vec<AccountAddress>, _>>()?;
// TODO: parse Value's directly instead of going through the indirection of TransactionArgument?
let vm_args: Vec<Vec<u8>> = convert_txn_args(txn_args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl OnDiskStateView {
match p.parent().map(|parent| parent.parent()).flatten() {
Some(parent) => {
let addr =
AccountAddress::from_hex_literal(parent.file_stem().unwrap().to_str().unwrap())
AccountAddress::from_hex_fuzzy(parent.file_stem().unwrap().to_str().unwrap())
.unwrap();
Some(ModuleId::new(addr, name))
}
Expand Down
4 changes: 2 additions & 2 deletions language/tools/move-coverage/src/coverage_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl CoverageMap {
let func_name = Identifier::new(context_segs.pop().unwrap()).unwrap();
let module_name = Identifier::new(context_segs.pop().unwrap()).unwrap();
let module_addr =
AccountAddress::from_hex_literal(context_segs.pop().unwrap()).unwrap();
AccountAddress::from_hex_fuzzy(context_segs.pop().unwrap()).unwrap();
self.insert(exec_id, module_addr, module_name, func_name, pc);
} else {
// Don't count scripts (for now)
Expand Down Expand Up @@ -286,7 +286,7 @@ impl TraceMap {
let func_name = Identifier::new(context_segs.pop().unwrap()).unwrap();
let module_name = Identifier::new(context_segs.pop().unwrap()).unwrap();
let module_addr =
AccountAddress::from_hex_literal(context_segs.pop().unwrap()).unwrap();
AccountAddress::from_hex_fuzzy(context_segs.pop().unwrap()).unwrap();
self.insert(exec_id, module_addr, module_name, func_name, pc);
} else {
// Don't count scripts (for now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn parse_substitution(tval: TV) -> Result<PM::Substitution> {
let addr_ident = PM::NamedAddress::from(addr_name.as_str());
match tval {
TV::String(addr_or_name) => {
if let Ok(addr) = AccountAddress::from_hex_literal(&addr_or_name) {
if let Ok(addr) = AccountAddress::from_hex_fuzzy(&addr_or_name) {
subst.insert(addr_ident, PM::SubstOrRename::Assign(addr));
} else {
let rename_from = PM::NamedAddress::from(addr_or_name.as_str());
Expand Down

0 comments on commit b76efe2

Please sign in to comment.