From 003b53ca290f60531477432e749c9c1ba1292902 Mon Sep 17 00:00:00 2001 From: Maxim Andreev Date: Mon, 24 Feb 2025 12:38:14 +0300 Subject: [PATCH] selectors: vyper o(1) function start offset fix --- src/selectors/mod.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/selectors/mod.rs b/src/selectors/mod.rs index 3e9e468..1582e53 100644 --- a/src/selectors/mod.rs +++ b/src/selectors/mod.rs @@ -42,6 +42,16 @@ fn analyze( *vm.stack.peek_mut()? = Element { data: if ret.op == op::EQ { VAL_0_B } else { VAL_1_B }, label: Some(Label::SelCmp(selector)), + }; + + // Vyper _selector_section_dense()/_selector_section_sparse() + if ret.op == op::EQ && vm.stack.data.len() >= 2 { + let fh = vm.stack.data[vm.stack.data.len() - 2].data; + let target = u16::from_be_bytes([fh[29], fh[30]]) as usize; + // assert!(vm.code[target] == op::JUMPDEST); + if target < vm.code.len() && vm.code[target] == op::JUMPDEST { + selectors.insert(selector, target); + } } } @@ -97,15 +107,6 @@ fn analyze( } } - // Vyper again - StepResult { - op: op::AND, - args: match_first_two!(elabel!(scmp @ Label::SelCmp(_)), ot), - .. - } if ot.data == VAL_1_B => { - vm.stack.peek_mut()?.label = Some(scmp); - } - StepResult { op: op::SHR, args: [_, elabel!(Label::CallData), ..],