Skip to content

Commit 27e6df8

Browse files
committed
fix tests for internal function pointers
1 parent a94a22b commit 27e6df8

27 files changed

+411
-191
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
*.bak
2323

2424
# Test solc versions
25-
solc-bin/
25+
**/solc-bin/
26+
**/solc-bin-upstream/

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

era-compiler-solidity/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ doctest = false
1818
structopt = { version = "=0.3.26", default-features = false }
1919
thiserror = "=1.0.64"
2020
anyhow = "=1.0.89"
21+
boolinator = "=2.4.0"
2122
which = "=6.0.3"
2223
path-slash = "=0.2.1"
2324
normpath = "=1.3.0"

era-compiler-solidity/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,7 @@ pub fn standard_json_eravm(
436436
let output_assembly = solc_input
437437
.settings
438438
.output_selection
439-
.as_ref()
440-
.map(|selection| selection.contains_eravm_assembly())
441-
.unwrap_or_default();
439+
.contains_eravm_assembly();
442440

443441
let (mut solc_output, solc_version, project) = match (language, solc_compiler) {
444442
(SolcStandardJsonInputLanguage::Solidity, solc_compiler) => {

era-compiler-solidity/src/solc/standard_json/input/settings/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct Settings {
4040
#[serde(skip_serializing_if = "Option::is_none")]
4141
pub evm_version: Option<era_compiler_common::EVMVersion>,
4242
/// The output selection filters.
43-
#[serde(skip_serializing_if = "Option::is_none")]
44-
pub output_selection: Option<Selection>,
43+
#[serde(default)]
44+
pub output_selection: Selection,
4545
/// The metadata settings.
4646
#[serde(default)]
4747
pub metadata: Metadata,
@@ -114,7 +114,7 @@ impl Settings {
114114
force_evmla: codegen == Some(SolcCodegen::EVMLA),
115115
enable_eravm_extensions,
116116

117-
output_selection: Some(output_selection),
117+
output_selection,
118118
metadata,
119119
llvm_options,
120120
suppressed_errors,
@@ -129,18 +129,14 @@ impl Settings {
129129
/// Sets the necessary defaults for EraVM compilation.
130130
///
131131
pub fn normalize(&mut self, codegen: Option<SolcCodegen>) {
132-
self.output_selection
133-
.get_or_insert_with(Selection::default)
134-
.extend_with_required(codegen);
132+
self.output_selection.extend_with_required(codegen);
135133
}
136134

137135
///
138136
/// Sets the necessary defaults for Yul validation.
139137
///
140138
pub fn normalize_yul_validation(&mut self) {
141-
self.output_selection
142-
.get_or_insert_with(Selection::new_yul_validation)
143-
.extend_with_yul_validation();
139+
self.output_selection.extend_with_yul_validation();
144140
}
145141

146142
///
@@ -150,9 +146,6 @@ impl Settings {
150146
/// Afterwards, the flags are used to prune JSON output before returning it.
151147
///
152148
pub fn get_unset_required(&self) -> HashSet<SelectionFlag> {
153-
self.output_selection
154-
.as_ref()
155-
.map(|selection| selection.get_unset_required())
156-
.unwrap_or_else(|| Selection::default().get_unset_required())
149+
self.output_selection.get_unset_required()
157150
}
158151
}

era-compiler-solidity/src/solc/standard_json/output/contract/eravm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
///
66
/// The `solc --standard-json` output contract EraVM data.
77
///
8-
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
8+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
99
#[serde(rename_all = "camelCase")]
1010
pub struct EraVM {
1111
/// The contract bytecode.

era-compiler-solidity/src/solc/standard_json/output/contract/evm/extra_metadata/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ impl ExtraMetadata {
2828
for function in self.recursive_functions.iter() {
2929
match block_key.code_type {
3030
era_compiler_llvm_context::CodeType::Deploy => {
31-
if let Some(creation_tag) = function.creation_tag {
32-
if num::BigUint::from(creation_tag) == block_key.tag {
33-
return Some(function);
34-
}
31+
if function
32+
.creation_tag
33+
.map(|creation_tag| num::BigUint::from(creation_tag) == block_key.tag)
34+
.unwrap_or_default()
35+
{
36+
return Some(function);
3537
}
3638
}
3739
era_compiler_llvm_context::CodeType::Runtime => {
38-
if let Some(runtime_tag) = function.runtime_tag {
39-
if num::BigUint::from(runtime_tag) == block_key.tag {
40-
return Some(function);
41-
}
40+
if function
41+
.runtime_tag
42+
.map(|runtime_tag| num::BigUint::from(runtime_tag) == block_key.tag)
43+
.unwrap_or_default()
44+
{
45+
return Some(function);
4246
}
4347
}
4448
}

era-compiler-solidity/src/solc/standard_json/output/contract/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ impl Contract {
6868
&& self.metadata.is_none()
6969
&& self.devdoc.is_none()
7070
&& self.userdoc.is_none()
71-
&& self.evm.is_none()
7271
&& self.ir_optimized.is_none()
72+
&& self.evm.is_none()
73+
&& self.eravm.is_none()
7374
&& self.hash.is_none()
7475
&& self.factory_dependencies.is_empty()
7576
&& self.missing_libraries.is_none()

era-compiler-solidity/src/solc/standard_json/output/error/source_location.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,3 @@ impl SourceLocation {
6767
))
6868
}
6969
}
70-
71-
impl std::fmt::Display for SourceLocation {
72-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
73-
write!(f, "{}", self.file)?;
74-
if self.start > 0 {
75-
write!(f, ":{}", self.start)?;
76-
if self.end > 0 {
77-
write!(f, ":{}", self.end)?;
78-
}
79-
}
80-
Ok(())
81-
}
82-
}

era-compiler-solidity/src/solc/standard_json/output/source.rs

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
use std::collections::BTreeMap;
66

7+
use boolinator::Boolinator;
8+
79
use crate::error_type::ErrorType;
810
use crate::solc::codegen::Codegen as SolcCodegen;
911
use crate::solc::standard_json::input::source::Source as StandardJSONInputSource;
@@ -45,18 +47,12 @@ impl Source {
4547
) -> Option<SolcStandardJsonOutputError> {
4648
let ast = ast.as_object()?;
4749

48-
if ast.get("nodeType")?.as_str()? != "FunctionCall" {
49-
return None;
50-
}
50+
(ast.get("nodeType")?.as_str()? == "FunctionCall").as_option()?;
5151

5252
let expression = ast.get("expression")?.as_object()?;
53-
if expression.get("nodeType")?.as_str()? != "MemberAccess" {
54-
return None;
55-
}
53+
(expression.get("nodeType")?.as_str()? == "MemberAccess").as_option()?;
5654
let member_name = expression.get("memberName")?.as_str()?;
57-
if !["send", "transfer"].contains(&member_name) {
58-
return None;
59-
}
55+
["send", "transfer"].contains(&member_name).as_option()?;
6056

6157
let expression = expression.get("expression")?.as_object()?;
6258
let type_descriptions = expression.get("typeDescriptions")?.as_object()?;
@@ -65,9 +61,7 @@ impl Source {
6561
if solc_version.default < semver::Version::new(0, 5, 0) {
6662
affected_types.push("t_address");
6763
}
68-
if !affected_types.contains(&type_identifier) {
69-
return None;
70-
}
64+
affected_types.contains(&type_identifier).as_option()?;
7165

7266
Some(SolcStandardJsonOutputError::error_send_and_transfer(
7367
ast.get("src")?.as_str(),
@@ -86,22 +80,16 @@ impl Source {
8680
) -> Option<SolcStandardJsonOutputError> {
8781
let ast = ast.as_object()?;
8882

89-
if ast.get("nodeType")?.as_str()? != "MemberAccess" {
90-
return None;
91-
}
92-
if ast.get("memberName")?.as_str()? != "runtimeCode" {
93-
return None;
94-
}
83+
(ast.get("nodeType")?.as_str()? == "MemberAccess").as_option()?;
84+
(ast.get("memberName")?.as_str()? == "runtimeCode").as_option()?;
9585

9686
let expression = ast.get("expression")?.as_object()?;
9787
let type_descriptions = expression.get("typeDescriptions")?.as_object()?;
98-
if !type_descriptions
88+
type_descriptions
9989
.get("typeIdentifier")?
10090
.as_str()?
10191
.starts_with("t_magic_meta_type")
102-
{
103-
return None;
104-
}
92+
.as_option()?;
10593

10694
Some(SolcStandardJsonOutputError::error_runtime_code(
10795
ast.get("src")?.as_str(),
@@ -120,18 +108,14 @@ impl Source {
120108
) -> Option<SolcStandardJsonOutputError> {
121109
let ast = ast.as_object()?;
122110

123-
if ast.get("nodeType")?.as_str()? != "VariableDeclaration" {
124-
return None;
125-
}
111+
(ast.get("nodeType")?.as_str()? == "VariableDeclaration").as_option()?;
126112

127113
let type_descriptions = ast.get("typeDescriptions")?.as_object()?;
128-
if !type_descriptions
114+
type_descriptions
129115
.get("typeIdentifier")?
130116
.as_str()?
131117
.contains("function_internal")
132-
{
133-
return None;
134-
}
118+
.as_option()?;
135119

136120
Some(
137121
SolcStandardJsonOutputError::error_internal_function_pointer(
@@ -152,20 +136,12 @@ impl Source {
152136
) -> Option<SolcStandardJsonOutputError> {
153137
let ast = ast.as_object()?;
154138

155-
if ast.get("nodeType")?.as_str()? != "MemberAccess" {
156-
return None;
157-
}
158-
if ast.get("memberName")?.as_str()? != "origin" {
159-
return None;
160-
}
139+
(ast.get("nodeType")?.as_str()? == "MemberAccess").as_option()?;
140+
(ast.get("memberName")?.as_str()? == "origin").as_option()?;
161141

162142
let expression = ast.get("expression")?.as_object()?;
163-
if expression.get("nodeType")?.as_str()? != "Identifier" {
164-
return None;
165-
}
166-
if expression.get("name")?.as_str()? != "tx" {
167-
return None;
168-
}
143+
(expression.get("nodeType")?.as_str()? == "Identifier").as_option()?;
144+
(expression.get("name")?.as_str()? == "tx").as_option()?;
169145

170146
Some(SolcStandardJsonOutputError::warning_tx_origin(
171147
ast.get("src")?.as_str(),
@@ -187,20 +163,18 @@ impl Source {
187163

188164
match ast.get("nodeType")?.as_str()? {
189165
"InlineAssembly" if solc_version.default < semver::Version::new(0, 6, 0) => {
190-
if !ast.get("operations")?.as_str()?.contains("origin()") {
191-
return None;
192-
}
166+
ast.get("operations")?
167+
.as_str()?
168+
.contains("origin()")
169+
.as_option()?;
193170
}
194171
"YulFunctionCall" if solc_version.default >= semver::Version::new(0, 6, 0) => {
195-
if ast
196-
.get("functionName")?
172+
(ast.get("functionName")?
197173
.as_object()?
198174
.get("name")?
199175
.as_str()?
200-
!= "origin"
201-
{
202-
return None;
203-
}
176+
== "origin")
177+
.as_option()?;
204178
}
205179
_ => return None,
206180
}

era-compiler-solidity/tests/cli/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ pub const TEST_SOLIDITY_STANDARD_JSON_SOLC_INVALID_PATH: &str =
101101
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_RECURSION_PATH: &str =
102102
"tests/data/standard_json_input/solidity_zksolc_recursion.json";
103103

104+
/// A test input file.
105+
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_INTERNAL_FUNCTION_POINTERS_PATH: &str =
106+
"tests/data/standard_json_input/solidity_zksolc_internal_function_pointers.json";
107+
104108
/// A test input file.
105109
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_INVALID_PATH: &str =
106110
"tests/data/standard_json_input/solidity_zksolc_invalid.json";
@@ -247,6 +251,7 @@ pub fn execute_zksolc_with_target(
247251
pub fn execute_solc(args: &[&str]) -> anyhow::Result<assert_cmd::assert::Assert> {
248252
let solc_compiler = crate::common::get_solc_compiler(
249253
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
254+
false,
250255
)?
251256
.executable;
252257
let mut cmd = Command::new(solc_compiler);

era-compiler-solidity/tests/cli/solc.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ fn with_solc() -> anyhow::Result<()> {
88
common::setup()?;
99

1010
let mut zksolc = Command::cargo_bin(era_compiler_solidity::DEFAULT_EXECUTABLE_NAME)?;
11-
let solc_compiler =
12-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
13-
.executable;
11+
let solc_compiler = common::get_solc_compiler(
12+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
13+
false,
14+
)?
15+
.executable;
1416

1517
let assert = zksolc
1618
.arg(cli::TEST_SOLIDITY_CONTRACT_PATH)
@@ -48,9 +50,11 @@ fn with_solc_standard_json_mode() -> anyhow::Result<()> {
4850
common::setup()?;
4951

5052
let mut zksolc = Command::cargo_bin(era_compiler_solidity::DEFAULT_EXECUTABLE_NAME)?;
51-
let solc_compiler =
52-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
53-
.executable;
53+
let solc_compiler = common::get_solc_compiler(
54+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
55+
false,
56+
)?
57+
.executable;
5458

5559
let assert = zksolc
5660
.arg("--solc")
@@ -88,9 +92,11 @@ fn without_solc_standard_json_mode() -> anyhow::Result<()> {
8892
fn with_solc_llvm_ir_mode() -> anyhow::Result<()> {
8993
common::setup()?;
9094

91-
let solc_compiler =
92-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
93-
.executable;
95+
let solc_compiler = common::get_solc_compiler(
96+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
97+
false,
98+
)?
99+
.executable;
94100

95101
let args = &[
96102
"--solc",
@@ -112,9 +118,11 @@ fn with_solc_llvm_ir_mode() -> anyhow::Result<()> {
112118
fn with_solc_eravm_assembly_mode() -> anyhow::Result<()> {
113119
common::setup()?;
114120

115-
let solc_compiler =
116-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
117-
.executable;
121+
let solc_compiler = common::get_solc_compiler(
122+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
123+
false,
124+
)?
125+
.executable;
118126

119127
let args = &[
120128
"--solc",

0 commit comments

Comments
 (0)