mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 08:15:29 +00:00
Keep uncertain EVM fallback and jump payability unknown
This commit is contained in:
1 parent
a784f2e716
commit
17f1b5d20f
2 files changed
+35
-1
No files matched your search
@@ -628,7 +628,10 @@ pub fn analyze(code: &[u8]) -> Result<EvmInterface, FormatError> {
|
||||
|
||||
let (short_calldata, receive) = short_calldata_path(body, &ins, disp_start);
|
||||
let mut fallback = "unknown";
|
||||
// At the selector cap the remaining dispatcher has not been scanned.
|
||||
// Its next comparison is not evidence that a fallback body exists.
|
||||
if let Some(j) = last_jumpi
|
||||
&& functions.len() < MAX_FUNCTIONS
|
||||
&& solc_like > 0
|
||||
{
|
||||
fallback = if reverts_soon(body, &ins, j + 1, &index_of) { "absent" } else { "present" };
|
||||
@@ -694,7 +697,7 @@ fn payability(code: &[u8], ins: &[Ins], start: usize, index_of: &dyn Fn(usize) -
|
||||
match i.op {
|
||||
0x34 if rejects_value(code, ins, k, index_of) => return ("nonpayable", format!("rejects nonzero CALLVALUE at {:#x}", i.off)),
|
||||
0x56 => match jump_destination(code, ins, k, index_of) {
|
||||
Some(t) if hops < 2 => {
|
||||
Some(t) if hops < 2 && ins.get(t).is_some_and(|target| target.op == 0x5b) => {
|
||||
hops += 1;
|
||||
k = t;
|
||||
continue;
|
||||
|
||||
@@ -82,3 +82,34 @@ fn repeated_comparisons_keep_fallback_scan_after_the_last_dispatch() {
|
||||
assert_eq!(report.fallback, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selector_cap_leaves_fallback_unknown() {
|
||||
for ending in [&[0x5f, 0x5f, 0xfd][..], &[0x00][..]] {
|
||||
let mut code = prefix();
|
||||
for selector in 0..4097 {
|
||||
comparison(&mut code, selector, 4, 0);
|
||||
}
|
||||
code.extend_from_slice(ending);
|
||||
let report = evm::analyze(&code).unwrap();
|
||||
assert_eq!(report.functions.len(), 4096);
|
||||
assert_eq!(report.fallback, "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn payability_only_follows_jumps_to_jumpdest() {
|
||||
for (target, expected) in [(&[0x5b, 0x00][..], "payable"), (&[0x00][..], "unknown")] {
|
||||
let mut code = prefix();
|
||||
let entry = u8::try_from(code.len() + 10).unwrap();
|
||||
comparison(&mut code, 0xfeed0001, 4, entry);
|
||||
code.push(0x00);
|
||||
assert_eq!(code.len(), usize::from(entry));
|
||||
code.extend([0x5b, 0x60, entry + 4, 0x56]);
|
||||
code.extend_from_slice(target);
|
||||
let report = evm::analyze(&code).unwrap();
|
||||
assert_eq!(report.functions.len(), 1);
|
||||
assert!(report.functions[0].jumpdest_valid);
|
||||
assert_eq!(report.functions[0].mutability, expected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user