Skip to content

Commit c65a63f

Browse files
committed
fix: change contract metadata from JSON to string
1 parent 6b340e8 commit c65a63f

18 files changed

Lines changed: 73 additions & 95 deletions

File tree

solx-solc/src/solc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Compiler {
105105

106106
let mut error_message = std::ptr::null_mut();
107107
let error_pointer = &mut error_message;
108-
let output_ffi = unsafe {
108+
let output_string = unsafe {
109109
let output_pointer = solidity_compile_default_callback(
110110
input_c_string.as_ptr(),
111111
base_path,
@@ -125,7 +125,7 @@ impl Compiler {
125125
};
126126

127127
let mut solc_output = match era_compiler_common::deserialize_from_str::<StandardJsonOutput>(
128-
output_ffi.as_str(),
128+
output_string.as_str(),
129129
) {
130130
Ok(solc_output) => solc_output,
131131
Err(error) => {

solx-solc/src/standard_json/input/settings/metadata.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@ pub struct Metadata {
1111
/// Whether to use literal content.
1212
#[serde(default)]
1313
pub use_literal_content: bool,
14-
1514
/// The metadata hash type.
16-
#[serde(
17-
alias = "bytecodeHash",
18-
default = "Metadata::default_hash_type",
19-
skip_serializing
20-
)]
21-
pub hash_type: era_compiler_common::HashType,
15+
#[serde(default = "Metadata::default_bytecode_hash", skip_serializing)]
16+
pub bytecode_hash: era_compiler_common::HashType,
2217
}
2318

2419
impl Default for Metadata {
2520
fn default() -> Self {
26-
Self::new(false, Self::default_hash_type())
21+
Self::new(false, Self::default_bytecode_hash())
2722
}
2823
}
2924

@@ -33,15 +28,15 @@ impl Metadata {
3328
///
3429
pub fn new(use_literal_content: bool, hash_type: era_compiler_common::HashType) -> Self {
3530
Self {
36-
hash_type,
31+
bytecode_hash: hash_type,
3732
use_literal_content,
3833
}
3934
}
4035

4136
///
4237
/// The default metadata hash type.
4338
///
44-
fn default_hash_type() -> era_compiler_common::HashType {
45-
era_compiler_common::HashType::Keccak256
39+
fn default_bytecode_hash() -> era_compiler_common::HashType {
40+
era_compiler_common::HashType::Ipfs
4641
}
4742
}

solx-solc/src/standard_json/input/settings/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct Settings {
5050
pub metadata: Metadata,
5151

5252
/// The extra LLVM options.
53-
#[serde(default, rename = "LLVMOptions", skip_serializing)]
53+
#[serde(default, skip_serializing)]
5454
pub llvm_options: Vec<String>,
5555
}
5656

solx-solc/src/standard_json/input/settings/selection/file.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ impl File {
5858
/// Afterwards, the flags are used to prune JSON output before returning it.
5959
///
6060
pub fn selection_to_prune(&self) -> Self {
61-
let required_per_file = vec![Selector::AST];
62-
let required_per_contract = vec![
63-
Selector::MethodIdentifiers,
64-
Selector::Metadata,
65-
Selector::Yul,
66-
Selector::EVMLA,
67-
];
61+
let required_per_file = vec![];
62+
let required_per_contract = vec![Selector::Yul, Selector::EVMLA];
6863

6964
let mut unset_per_file = HashSet::with_capacity(required_per_file.len());
7065
let mut unset_per_contract = HashSet::with_capacity(required_per_contract.len());

solx-solc/src/standard_json/input/settings/selection/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ impl Selection {
3232
/// Creates the selection required by EraVM compilation process.
3333
///
3434
pub fn new_required(via_ir: bool) -> Self {
35-
Self::new(vec![
36-
Selector::AST,
37-
Selector::MethodIdentifiers,
38-
Selector::Metadata,
39-
via_ir.into(),
40-
])
35+
Self::new(vec![via_ir.into(), Selector::ABI]) // TODO: investigate why ABI is required
4136
}
4237

4338
///

solx-solc/src/standard_json/output/contract/mod.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub struct Contract {
2525
#[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
2626
pub transient_storage_layout: serde_json::Value,
2727
/// The contract metadata.
28-
#[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
29-
pub metadata: serde_json::Value,
28+
#[serde(default, skip_serializing_if = "String::is_empty")]
29+
pub metadata: String,
3030
/// The contract developer documentation.
3131
#[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
3232
pub devdoc: serde_json::Value,
@@ -41,16 +41,28 @@ pub struct Contract {
4141
pub evm: Option<EVM>,
4242

4343
/// Unlinked factory dependencies.
44-
#[serde(default, skip_deserializing)]
44+
#[serde(
45+
default,
46+
skip_serializing_if = "BTreeSet::is_empty",
47+
skip_deserializing
48+
)]
4549
pub factory_dependencies_unlinked: BTreeSet<String>,
4650
/// Linked factory dependencies.
47-
#[serde(default, skip_deserializing)]
51+
#[serde(
52+
default,
53+
skip_serializing_if = "BTreeMap::is_empty",
54+
skip_deserializing
55+
)]
4856
pub factory_dependencies: BTreeMap<String, String>,
4957
/// Missing linkable libraries.
50-
#[serde(default, skip_deserializing)]
58+
#[serde(
59+
default,
60+
skip_serializing_if = "BTreeSet::is_empty",
61+
skip_deserializing
62+
)]
5163
pub missing_libraries: BTreeSet<String>,
5264
/// Binary object format.
53-
#[serde(default, skip_deserializing)]
65+
#[serde(default, skip_serializing_if = "Option::is_none", skip_deserializing)]
5466
pub object_format: Option<era_compiler_common::ObjectFormat>,
5567
}
5668

@@ -62,7 +74,7 @@ impl Contract {
6274
self.abi.is_null()
6375
&& self.storage_layout.is_null()
6476
&& self.transient_storage_layout.is_null()
65-
&& self.metadata.is_null()
77+
&& self.metadata.is_empty()
6678
&& self.devdoc.is_null()
6779
&& self.userdoc.is_null()
6880
&& self.ir_optimized.is_empty()

solx-solc/src/standard_json/output/mod.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,20 @@ impl Output {
9696
/// Prunes the output JSON and prints it to stdout.
9797
///
9898
pub fn write_and_exit(mut self, selection_to_prune: Selection) -> ! {
99-
let sources = self.sources.values_mut().collect::<Vec<&mut Source>>();
100-
for source in sources.into_iter() {
101-
if selection_to_prune.contains(&Selector::AST) {
102-
source.ast = None;
103-
}
104-
}
105-
10699
let contracts = self
107100
.contracts
108101
.values_mut()
109102
.flat_map(|contracts| contracts.values_mut())
110103
.collect::<Vec<&mut Contract>>();
111104
for contract in contracts.into_iter() {
112-
if selection_to_prune.contains(&Selector::Metadata) {
113-
contract.metadata = serde_json::Value::Null;
114-
}
105+
contract.metadata = String::new(); // TODO: fix metadata
115106
if selection_to_prune.contains(&Selector::Yul) {
116107
contract.ir_optimized = String::new();
117108
}
118109
if let Some(ref mut evm) = contract.evm {
119110
if selection_to_prune.contains(&Selector::EVMLA) {
120111
evm.legacy_assembly = serde_json::Value::Null;
121112
}
122-
if selection_to_prune.contains(&Selector::MethodIdentifiers) {
123-
evm.method_identifiers.clear();
124-
}
125113
}
126114
}
127115

solx/src/build_evm/contract/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct Contract {
2424
pub runtime_object: Object,
2525
/// The metadata hash.
2626
pub metadata_hash: Option<era_compiler_common::Hash>,
27-
/// The metadata JSON.
28-
pub metadata_json: serde_json::Value,
27+
/// The metadata string.
28+
pub metadata_string: String,
2929
/// The unlinked missing libraries.
3030
pub missing_libraries: BTreeSet<String>,
3131
/// The binary object format.
@@ -41,7 +41,7 @@ impl Contract {
4141
deploy_object: Object,
4242
runtime_object: Object,
4343
metadata_hash: Option<era_compiler_common::Hash>,
44-
metadata_json: serde_json::Value,
44+
metadata_string: String,
4545
missing_libraries: BTreeSet<String>,
4646
object_format: era_compiler_common::ObjectFormat,
4747
) -> Self {
@@ -50,7 +50,7 @@ impl Contract {
5050
deploy_object,
5151
runtime_object,
5252
metadata_hash,
53-
metadata_json,
53+
metadata_string,
5454
missing_libraries,
5555
object_format,
5656
}
@@ -67,7 +67,7 @@ impl Contract {
6767
) -> anyhow::Result<()> {
6868
writeln!(std::io::stdout(), "\n======= {path} =======")?;
6969
if output_metadata {
70-
writeln!(std::io::stdout(), "Metadata:\n{}", self.metadata_json)?;
70+
writeln!(std::io::stdout(), "Metadata:\n{}", self.metadata_string)?;
7171
}
7272
if output_binary {
7373
writeln!(
@@ -118,7 +118,7 @@ impl Contract {
118118
} else {
119119
std::fs::write(
120120
output_path.as_path(),
121-
self.metadata_json.to_string().as_bytes(),
121+
self.metadata_string.to_string().as_bytes(),
122122
)
123123
.map_err(|error| anyhow::anyhow!("File {output_path:?} writing: {error}"))?;
124124
}
@@ -155,7 +155,7 @@ impl Contract {
155155
self,
156156
standard_json_contract: &mut solx_solc::StandardJsonOutputContract,
157157
) -> anyhow::Result<()> {
158-
standard_json_contract.metadata = self.metadata_json;
158+
standard_json_contract.metadata = self.metadata_string;
159159
standard_json_contract
160160
.evm
161161
.get_or_insert_with(solx_solc::StandardJsonOutputContractEVM::default)

solx/src/evmla/assembly/instruction/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ impl Instruction {
137137
Name::PUSH => 1,
138138
Name::PUSH_Data => 1,
139139
Name::PUSH_Tag => 1,
140-
Name::PUSH_ContractHash => 1,
141-
Name::PUSH_ContractHashSize => 1,
140+
Name::PUSH_DataOffset => 1,
141+
Name::PUSH_DataSize => 1,
142142
Name::PUSHLIB => 1,
143143
Name::PUSHDEPLOYADDRESS => 1,
144144

@@ -286,7 +286,7 @@ impl Instruction {
286286
for instruction in instructions.iter_mut() {
287287
match instruction {
288288
Instruction {
289-
name: Name::PUSH_ContractHash | Name::PUSH_ContractHashSize,
289+
name: Name::PUSH_DataOffset | Name::PUSH_DataSize,
290290
value: Some(value),
291291
..
292292
} => {

0 commit comments

Comments
 (0)