From 95bd97dec1872c9d25b2d9bc97b7d9c0821c04e4 Mon Sep 17 00:00:00 2001 From: brock elmore Date: Fri, 2 Aug 2024 11:25:24 -0700 Subject: [PATCH] add require in array slice, remove parsing of emits --- crates/pyrometer/tests/test_data/assign.sol | 4 +++- crates/solc-expressions/src/array.rs | 5 +++++ crates/solc-expressions/src/context_builder/flattened.rs | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/pyrometer/tests/test_data/assign.sol b/crates/pyrometer/tests/test_data/assign.sol index 665ca9b0..facc63bc 100644 --- a/crates/pyrometer/tests/test_data/assign.sol +++ b/crates/pyrometer/tests/test_data/assign.sol @@ -28,7 +28,8 @@ contract Assign { } function array_slices( - uint[] calldata a + uint[] calldata a, + uint x ) public pure returns (uint[] memory) { require(a.length >= 4, "Array must have at least 4 elements"); a[2] = 14; @@ -36,5 +37,6 @@ contract Assign { uint[] memory c = a[1:]; uint[] memory d = a[:2]; uint[] memory e = a[2:4][0:1]; + uint[] memory f = a[2:x]; } } diff --git a/crates/solc-expressions/src/array.rs b/crates/solc-expressions/src/array.rs index 21282ec7..68b6f4ed 100644 --- a/crates/solc-expressions/src/array.rs +++ b/crates/solc-expressions/src/array.rs @@ -26,6 +26,11 @@ pub trait Array: AnalyzerBackend + Sized { loc: Loc, ) -> Result<(), ExprErr> { let arr = ContextVarNode::from(arr.expect_single().into_expr_err(loc)?); + + if let (Some(s), Some(e)) = (&start, &end) { + self.handle_require_inner(arena, ctx, e, s, RangeOp::Gte, loc)?; + } + let start = if let Some(start) = start { Elem::from(ContextVarNode::from( start.expect_single().into_expr_err(loc)?, diff --git a/crates/solc-expressions/src/context_builder/flattened.rs b/crates/solc-expressions/src/context_builder/flattened.rs index faaa8430..7705256a 100644 --- a/crates/solc-expressions/src/context_builder/flattened.rs +++ b/crates/solc-expressions/src/context_builder/flattened.rs @@ -322,8 +322,8 @@ pub trait Flatten: self.push_expr(FlatExpr::Revert(*loc, named_args.len())); } Emit(loc, emit_expr) => { - self.traverse_expression(emit_expr, unchecked); - self.push_expr(FlatExpr::Emit(*loc)); + // self.traverse_expression(emit_expr, unchecked); + // self.push_expr(FlatExpr::Emit(*loc)); } Try(loc, _try_expr, _maybe_returns, _clauses) => { self.push_expr(FlatExpr::Todo( @@ -2075,6 +2075,7 @@ pub trait Flatten: } else { None }; + self.slice_inner(arena, ctx, arr, start, end, loc) }