Skip to content

Commit

Permalink
undo dead code removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Dec 5, 2024
1 parent cb3e456 commit 649f09a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions actors/evm/src/interpreter/instructions/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ pub fn call_generic<RT: Runtime>(
// this is how the EVM behaves.
ContractType::Account | ContractType::NotFound => Ok(None),
// If we're calling a "native" actor, always revert.
ContractType::Native => {
log::info!("attempted to delegatecall a native actor at {dst:?}");
ContractType::Native(cid) => {
log::info!("attempted to delegatecall a native actor {cid} at {dst:?}");
Err(None)
}
ContractType::Precompile => {
Expand Down
8 changes: 4 additions & 4 deletions actors/evm/src/interpreter/instructions/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn extcodesize(
ContractType::EVM(addr) => {
get_evm_bytecode(system, &addr).map(|bytecode| bytecode.len())?
}
ContractType::Native => 1,
ContractType::Native(_) => 1,
// account, not found, and precompiles are 0 size
_ => 0,
};
Expand All @@ -45,7 +45,7 @@ pub fn extcodehash(
let addr = match get_contract_type(system.rt, &addr.into()) {
ContractType::EVM(a) => a,
// _Technically_ since we have native "bytecode" set as 0xfe this is valid, though we cant differentiate between different native actors.
ContractType::Native => return Ok(BytecodeHash::NATIVE_ACTOR.into()),
ContractType::Native(_) => return Ok(BytecodeHash::NATIVE_ACTOR.into()),
// Precompiles "exist" and therefore aren't empty (although spec-wise they can be either 0 or keccak("") ).
ContractType::Precompile => return Ok(BytecodeHash::EMPTY.into()),
// NOTE: There may be accounts that in EVM would be considered "empty" (as defined in EIP-161) and give 0, but we will instead return keccak("").
Expand Down Expand Up @@ -94,7 +94,7 @@ pub enum ContractType {
Precompile,
/// EVM ID Address and the CID of the actor (not the bytecode)
EVM(Address),
Native,
Native(Cid),
Account,
NotFound,
}
Expand All @@ -115,7 +115,7 @@ pub fn get_contract_type<RT: Runtime>(rt: &RT, addr: &EthAddress) -> ContractTyp
Some(Type::Account | Type::Placeholder | Type::EthAccount) => ContractType::Account,
Some(Type::EVM) => ContractType::EVM(Address::new_id(id)),
// remaining builtin actors are native
_ => ContractType::Native,
_ => ContractType::Native(cid),
})
.unwrap_or(ContractType::NotFound)
}
Expand Down
15 changes: 12 additions & 3 deletions actors/evm/src/interpreter/precompiles/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ mod tests {
)
.unwrap();
let res = ec_add(&mut system, &input, PrecompileContext::default());
assert!(matches!(res, Err(PrecompileError::EcErr)));
assert!(matches!(
res,
Err(PrecompileError::EcErr(substrate_bn::CurveError::NotMember))
));
}

const TESTDATA_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/precompile-testdata/");
Expand Down Expand Up @@ -590,7 +593,10 @@ mod tests {
)
.unwrap();
let res = ec_mul(&mut system, &input, PrecompileContext::default());
assert!(matches!(res, Err(PrecompileError::EcErr)));
assert!(matches!(
res,
Err(PrecompileError::EcErr(substrate_bn::CurveError::NotMember))
));

let input = hex::decode(
"\
Expand Down Expand Up @@ -672,7 +678,10 @@ mod tests {
)
.unwrap();
let res = ec_pairing(&mut system, &input, PrecompileContext::default());
assert!(matches!(res, Err(PrecompileError::EcErr)));
assert!(matches!(
res,
Err(PrecompileError::EcErr(substrate_bn::CurveError::NotMember))
));
// invalid input length
let input = hex::decode(
"\
Expand Down
18 changes: 9 additions & 9 deletions actors/evm/src/interpreter/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ impl<RT: Runtime> Precompiles<RT> {
#[derive(Debug)]
pub enum PrecompileError {
// EVM precompile errors
EcErr,
EcErr(CurveError),
IncorrectInputSize,
// FVM precompile errors
InvalidInput,
CallForbidden,
TransferFailed,
VMError,
VMError(ActorError),
}

impl From<ActorError> for PrecompileError {
fn from(_: ActorError) -> Self {
Self::VMError
fn from(e: ActorError) -> Self {
Self::VMError(e)
}
}
impl From<TryFromIntError> for PrecompileError {
Expand All @@ -141,20 +141,20 @@ impl From<OverflowError> for PrecompileError {
}

impl From<FieldError> for PrecompileError {
fn from(_: FieldError) -> Self {
PrecompileError::EcErr
fn from(src: FieldError) -> Self {
PrecompileError::EcErr(src.into())
}
}

impl From<CurveError> for PrecompileError {
fn from(_: CurveError) -> Self {
PrecompileError::EcErr
fn from(src: CurveError) -> Self {
PrecompileError::EcErr(src)
}
}

impl From<GroupError> for PrecompileError {
fn from(_: GroupError) -> Self {
PrecompileError::EcErr
PrecompileError::EcErr(CurveError::NotMember)
}
}

Expand Down

0 comments on commit 649f09a

Please sign in to comment.