Skip to content

Commit

Permalink
two failing tests remain
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Jul 20, 2024
1 parent 46a5594 commit 4dcf69f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 98 deletions.
173 changes: 87 additions & 86 deletions crates/pyrometer/tests/test_data/logical.sol
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
// SPDX-License-Identifier: MIT or APACHE2
pragma solidity ^0.8.0;
enum MyEnum {
A,
B,
C
}

// enum MyEnum {
// A,
// B,
// C
// }

contract Logical {
function enumCmp() public pure returns (bool) {
return MyEnum.A > MyEnum.B;
}
// function enumCmp() public pure returns (bool) {
// return MyEnum.A > MyEnum.B;
// }

function yulCmp() internal pure {
uint x;
uint y;
assembly {
x := gt(2, 3)
y := eq(2, 3)
}
}
// function yulCmp() internal pure {
// uint x;
// uint y;
// assembly {
// x := gt(2, 3)
// y := eq(2, 3)
// }
// }

function yulComplicatedCmp(address a) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
success := and(eq(a, 0), call(gas(), a, 4, 5, 6, 7, 8)) //error
}
require(success);
}
// function yulComplicatedCmp(address a) internal {
// bool success;
// /// @solidity memory-safe-assembly
// assembly {
// success := and(eq(a, 0), call(gas(), a, 4, 5, 6, 7, 8)) //error
// }
// require(success);
// }

function or(address a) internal virtual {
assembly {
Expand All @@ -39,75 +40,75 @@ contract Logical {
}
}

function eq(address a) public pure {
assembly {
if eq(0x0, a) {
// function eq(address a) public pure {
// assembly {
// if eq(0x0, a) {

}
}
}
// }
// }
// }

function not() public pure {
uint256 a = 100;
bool s = a < 100;
require(!s);
}
// function not() public pure {
// uint256 a = 100;
// bool s = a < 100;
// require(!s);
// }

function cond_not(uint256 a) public pure {
bool s = a < 100;
if (!s) {
require(!s);
} else {
require(s);
}
}
// function cond_not(uint256 a) public pure {
// bool s = a < 100;
// if (!s) {
// require(!s);
// } else {
// require(s);
// }
// }

function cond_and(bool a, bool b) public pure {
if (a && b) {
require(a);
require(b);
bool f = a && b;
require(f);
} else {
require(!a || !b);
}
}
// function cond_and(bool a, bool b) public pure {
// if (a && b) {
// require(a);
// require(b);
// bool f = a && b;
// require(f);
// } else {
// require(!a || !b);
// }
// }

function cond_if(uint256 a) public pure {
bool s = a < 100;
if (s) {
require(s);
} else {
require(!s);
}
}
// function cond_if(uint256 a) public pure {
// bool s = a < 100;
// if (s) {
// require(s);
// } else {
// require(!s);
// }
// }

function and() public pure {
uint256 a = 100;
uint256 b = 1000;
bool s = a > 99;
bool t = b > 999;
require(s && t);
}
// function and() public pure {
// uint256 a = 100;
// uint256 b = 1000;
// bool s = a > 99;
// bool t = b > 999;
// require(s && t);
// }

function or_basic() public pure {
uint256 a = 100;
uint256 b = 1000;
bool s = a > 99;
bool t = b < 1000;
require(s || t);
}
// function or_basic() public pure {
// uint256 a = 100;
// uint256 b = 1000;
// bool s = a > 99;
// bool t = b < 1000;
// require(s || t);
// }

function or() public pure {
uint256 a = 100;
uint256 b = 1000;
bool s = a > 99 || b < 1000;
require(s);
}
// function or() public pure {
// uint256 a = 100;
// uint256 b = 1000;
// bool s = a > 99 || b < 1000;
// require(s);
// }

function or_inline() public pure {
uint256 a = 100;
uint256 b = 1000;
require(a > 99 || b < 1000);
}
// function or_inline() public pure {
// uint256 a = 100;
// uint256 b = 1000;
// require(a > 99 || b < 1000);
// }
}
4 changes: 2 additions & 2 deletions crates/shared/src/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ impl FlatExpr {
| ArrayLiteral(loc, ..) => Some(*loc),

FunctionCallName(..)
| YulExpr(FlatYulExpr::YulStartBlock)
| YulExpr(FlatYulExpr::YulEndBlock) => None,
| YulExpr(FlatYulExpr::YulStartBlock(_))
| YulExpr(FlatYulExpr::YulEndBlock(_)) => None,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/shared/src/flattened_yul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use solang_parser::pt::{

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum FlatYulExpr {
YulStartBlock,
YulStartBlock(usize),
YulVariable(Loc, &'static str),
YulFuncCall(Loc, &'static str, usize),
YulSuffixAccess(Loc, &'static str),
YulAssign(Loc, usize),
YulVarDecl(Loc, usize, bool),
YulFuncDef(Loc, &'static str, usize),
YulEndBlock,
YulEndBlock(usize),
}

impl std::fmt::Display for FlatYulExpr {
Expand Down
30 changes: 22 additions & 8 deletions crates/solc-expressions/src/context_builder/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,14 @@ pub trait Flatten:
flags: _,
block: yul_block,
} => {
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulStartBlock));
self.increment_asm_block();
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulStartBlock(
self.current_asm_block(),
)));
self.traverse_yul_statement(&YulStatement::Block(yul_block.clone()));
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulEndBlock));
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulEndBlock(
self.current_asm_block(),
)));
}
Return(loc, maybe_ret_expr) => {
if let Some(ret_expr) = maybe_ret_expr {
Expand Down Expand Up @@ -414,11 +419,16 @@ pub trait Flatten:
YulStatement::VariableDeclaration(def.loc, def.returns.clone(), None);
self.traverse_yul_statement(&rets_as_var_decl);

self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulStartBlock));
self.increment_asm_block();
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulStartBlock(
self.current_asm_block(),
)));
for stmt in def.body.statements.iter() {
self.traverse_yul_statement(stmt);
}
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulEndBlock));
self.push_expr(FlatExpr::YulExpr(FlatYulExpr::YulEndBlock(
self.current_asm_block(),
)));

let func = self.expr_stack_mut().drain(start_len..).collect::<Vec<_>>();

Expand Down Expand Up @@ -1046,8 +1056,10 @@ pub trait Flatten:
Try { .. } => todo!(),

// Yul
YulExpr(FlatYulExpr::YulStartBlock) => {
self.increment_asm_block();
YulExpr(FlatYulExpr::YulStartBlock(s)) => {
if self.current_asm_block() < s {
self.increment_asm_block();
}
Ok(())
}
YulExpr(yul @ FlatYulExpr::YulVariable(..)) => self.interp_yul_var(arena, ctx, yul),
Expand All @@ -1062,8 +1074,10 @@ pub trait Flatten:
YulExpr(yul @ FlatYulExpr::YulVarDecl(..)) => {
self.interp_yul_var_decl(arena, ctx, stack, yul, parse_idx)
}
YulExpr(FlatYulExpr::YulEndBlock) => {
self.decrement_asm_block();
YulExpr(FlatYulExpr::YulEndBlock(s)) => {
if self.current_asm_block() > s {
self.decrement_asm_block();
}
Ok(())
}
}?;
Expand Down

0 comments on commit 4dcf69f

Please sign in to comment.