Skip to content

Commit f03516d

Browse files
authored
Add support for Solidity 0.8.31 (#1479)
Add support for Solidity 0.8.31 - Added new Yul builtin `clz` https://www.soliditylang.org/blog/2025/12/03/solidity-0.8.31-release-announcement
1 parent 44b7d6f commit f03516d

File tree

39 files changed

+1121
-34
lines changed

39 files changed

+1121
-34
lines changed

.changeset/wise-garlics-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/slang": patch
3+
---
4+
5+
Add support for Solidity `0.8.31`

crates/solidity-v2/inputs/language/src/definition.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ language_v2_macros::compile!(Language(
2727
"0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", "0.8.9", "0.8.10", "0.8.11",
2828
"0.8.12", "0.8.13", "0.8.14", "0.8.15", "0.8.16", "0.8.17", "0.8.18", "0.8.19", "0.8.20",
2929
"0.8.21", "0.8.22", "0.8.23", "0.8.24", "0.8.25", "0.8.26", "0.8.27", "0.8.28", "0.8.29",
30-
"0.8.30"
30+
"0.8.30", "0.8.31"
3131
],
3232
sections = [
3333
Section(
@@ -6917,6 +6917,12 @@ language_v2_macros::compile!(Language(
69176917
name = "mcopy",
69186918
parameters = ["uint256 t", "uint256 f", "uint256 s"],
69196919
enabled = From("0.8.24")
6920+
),
6921+
BuiltInFunction(
6922+
name = "clz",
6923+
parameters = ["uint256 x"],
6924+
return_type = "uint256",
6925+
enabled = From("0.8.31")
69206926
)
69216927
]
69226928
)

crates/solidity-v2/outputs/cargo/common/src/versions/language_versions.generated.rs

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

crates/solidity/inputs/language/src/definition.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ language_macros::compile!(Language(
2727
"0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", "0.8.9", "0.8.10", "0.8.11",
2828
"0.8.12", "0.8.13", "0.8.14", "0.8.15", "0.8.16", "0.8.17", "0.8.18", "0.8.19", "0.8.20",
2929
"0.8.21", "0.8.22", "0.8.23", "0.8.24", "0.8.25", "0.8.26", "0.8.27", "0.8.28", "0.8.29",
30-
"0.8.30"
30+
"0.8.30", "0.8.31"
3131
],
3232
sections = [
3333
Section(
@@ -7193,6 +7193,12 @@ language_macros::compile!(Language(
71937193
name = "mcopy",
71947194
parameters = ["uint256 t", "uint256 f", "uint256 s"],
71957195
enabled = From("0.8.24")
7196+
),
7197+
BuiltInFunction(
7198+
name = "clz",
7199+
parameters = ["uint256 x"],
7200+
return_type = "uint256",
7201+
enabled = From("0.8.31")
71967202
)
71977203
]
71987204
)

crates/solidity/outputs/cargo/crate/src/backend/built_ins.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::cst::NodeId;
66
use crate::utils::versions::{
77
VERSION_0_4_12, VERSION_0_4_17, VERSION_0_4_21, VERSION_0_4_22, VERSION_0_5_0, VERSION_0_5_3,
88
VERSION_0_6_0, VERSION_0_6_2, VERSION_0_6_7, VERSION_0_6_8, VERSION_0_7_0, VERSION_0_8_0,
9-
VERSION_0_8_11, VERSION_0_8_15, VERSION_0_8_18, VERSION_0_8_2, VERSION_0_8_24, VERSION_0_8_4,
10-
VERSION_0_8_7, VERSION_0_8_8,
9+
VERSION_0_8_11, VERSION_0_8_15, VERSION_0_8_18, VERSION_0_8_2, VERSION_0_8_24, VERSION_0_8_31,
10+
VERSION_0_8_4, VERSION_0_8_7, VERSION_0_8_8,
1111
};
1212

1313
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -108,6 +108,7 @@ pub enum BuiltIn {
108108
YulCall,
109109
YulCallvalue,
110110
YulChainid,
111+
YulClz,
111112
YulCodecopy,
112113
YulCodesize,
113114
YulCoinbase,
@@ -238,6 +239,8 @@ impl<'a> BuiltInsResolver<'a> {
238239

239240
#[allow(clippy::too_many_lines)]
240241
pub(crate) fn lookup_yul_global(&self, symbol: &str) -> Option<BuiltIn> {
242+
// TODO(validation): Yul built-in function names should be considered reserved words.
243+
// They're currently parsed as Identifiers to facilitate their manipulation.
241244
match symbol {
242245
"add" => Some(BuiltIn::YulAdd),
243246
"addmod" => Some(BuiltIn::YulAddmod),
@@ -259,6 +262,7 @@ impl<'a> BuiltInsResolver<'a> {
259262
"call" => Some(BuiltIn::YulCall),
260263
"callvalue" => Some(BuiltIn::YulCallvalue),
261264
"chainid" => Some(BuiltIn::YulChainid),
265+
"clz" if self.language_version >= VERSION_0_8_31 => Some(BuiltIn::YulClz),
262266
"codecopy" => Some(BuiltIn::YulCodecopy),
263267
"codesize" => Some(BuiltIn::YulCodesize),
264268
"coinbase" => Some(BuiltIn::YulCoinbase),

crates/solidity/outputs/cargo/crate/src/backend/passes/p5_resolve_references/visitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ impl Visitor for Pass {
3232
input_ir::visitor::accept_inheritance_type(inheritance_type, self);
3333
}
3434
if let Some(ref storage_layout) = node.storage_layout {
35+
// TODO(validation): check that the expression is not binding constant variables up until 0.8.31
36+
// https://www.soliditylang.org/blog/2025/12/03/solidity-0.8.31-release-announcement
3537
input_ir::visitor::accept_expression(storage_layout, self);
3638
}
3739

0 commit comments

Comments
 (0)