Skip to content

standard-json: check a the sources keccak256 - #677

Merged
xermicus merged 3 commits into
mainfrom
cl/standard-json-input-parity
Oct 16, 2026
Merged

xermicus merged 3 commits into
mainfrom
cl/standard-json-input-parity

Conversation

@xermicus

@xermicus xermicus commented Oct 7, 2026

Copy link
Copy Markdown
Member

Closes #663

Signed-off-by: xermicus <cyrill@parity.io>
@xermicus
xermicus requested review from elle-j and jubnzv October 7, 2026 10:24
Comment on lines +40 to +43
/// The settings `solc` assumes when the optimizer is omitted.
pub fn solc_default() -> Self {
Self::new(false, Self::default_mode(), Details::default())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue we should change this approach a bit (whether in this PR or another one). I don't think this crate should have to own the solc defaults, but rather if a key is optional and is omitted, then we also omit it when passing the input to solc. This way solc's defaults will always be used, instead of us having to keep it in sync.

Depending on the solc version, solc also sometimes treats an omitted key differently from an explicit false value (e.g. before 0.8.6, "settings.optimizer.enabled": false was not the same as omitting it).

Keeping fields omitted if the user also omitted them is how the other Settings fields currently work, so I think we should update this to be the same for the optimizer. (This would also handle this case: "settings.optimizer": {}, which otherwise breaks).

Something like this (plus whatever call sites need updating):

crates/solc-json-interface/src/standard_json/input/settings/optimizer/mod.rs:

 pub struct Optimizer {
     /// Whether the optimizer is enabled.
-    pub enabled: bool,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub enabled: Option<bool>,
     ...
 }
 
 impl Optimizer {
     /// A shortcut constructor.
     pub fn new(enabled: bool, mode: char, details: Details) -> Self {
         Self {
-            enabled,
+            enabled: Some(enabled),
             mode,
             details,
         }
     }
     ...
-    /// The settings `solc` assumes when the optimizer is omitted.
-    pub fn solc_default() -> Self {
-        Self::new(false, Self::default_mode(), Details::default())
-    }
 }

crates/solc-json-interface/src/standard_json/input/settings/mod.rs:

 pub struct Settings {
     ...
-    #[serde(default = "Optimizer::solc_default")]
-    pub optimizer: Optimizer,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub optimizer: Option<Optimizer>,
     ...
 }

The rest of the PR LGTM though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's the right call.

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
@xermicus
xermicus requested a review from elle-j October 16, 2026 08:07
@xermicus
xermicus merged commit af717d8 into main Oct 16, 2026
34 checks passed
@xermicus
xermicus deleted the cl/standard-json-input-parity branch October 16, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standard JSON sources.*.keccak256 is not checked: a source that does not match its declared hash compiles silently

3 participants