Fix optimization specific SREM edge case (#527)

Existing test coverage didn't catch a signed remainder overflow
semantics edge case behavior where at least one the operators is being
constant folded by LLVM instead of solc. This PR fixes the SREM
translation bug and adds missing test coverage for division ops with
constants.

Closes #524

---------

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus authored and GitHub committed 2026-05-28 09:01:41 +02:00
1 parent 62a62770e3
commit 40e97d11eb
23 files changed
+1336 -21

No files matched your search

+20
View File
@@ -277,6 +277,16 @@ pub enum Code {
#[serde(default)]
libraries: SolcStandardJsonInputSettingsLibraries,
},
/// Compile a raw Yul source file and use the blob of `contract`.
///
/// The PVM blob is produced via revive's Yul-to-LLVM path (bypassing solc's
/// Yul optimizer), and the EVM bytecode is produced via `solc --strict-assembly`
/// without `--optimize` so literal operands reach both runtimes intact.
#[cfg(feature = "resolc")]
Yul {
path: std::path::PathBuf,
contract: String,
},
/// Read the contract blob from disk
Path(std::path::PathBuf),
/// A contract blob
@@ -315,6 +325,16 @@ impl From<Code> for pallet_revive::Code {
libraries,
))
}
#[cfg(feature = "solidity")]
Code::Yul { path, contract } => {
let Ok(source_code) = std::fs::read_to_string(&path) else {
panic!("Failed to read Yul source from {}", path.display());
};
pallet_revive::Code::Upload(resolc::test_utils::compile_yul_blob(
&contract,
&source_code,
))
}
Code::Path(path) => pallet_revive::Code::Upload(std::fs::read(path).unwrap()),
Code::Bytes(bytes) => pallet_revive::Code::Upload(bytes),
Code::Hash(hash) => pallet_revive::Code::Existing(hash),
+30 -19
View File
@@ -312,15 +312,6 @@ impl Specs {
salt,
..
} => {
let Code::Solidity {
path: Some(path),
solc_optimizer,
contract,
libraries,
} = code
else {
panic!("the differential runner requires Code::Solidity source");
};
assert!(
salt.0.is_none(),
"salt is not supported in differential mode"
@@ -331,17 +322,37 @@ impl Specs {
"configuring the origin is not supported in differential mode"
);
let deploy_code = match std::fs::read_to_string(&path) {
Ok(solidity_source) => hex::encode(compile_evm_deploy_code(
&contract,
&solidity_source,
solc_optimizer.unwrap_or(true),
let deploy_code = match code {
Code::Solidity {
path: Some(path),
solc_optimizer,
contract,
libraries,
)),
Err(err) => panic!(
"failed to read solidity source\n . path: '{}'\n . error: {:?}",
path.display(),
err
} => match std::fs::read_to_string(&path) {
Ok(solidity_source) => hex::encode(compile_evm_deploy_code(
&contract,
&solidity_source,
solc_optimizer.unwrap_or(true),
libraries,
)),
Err(err) => panic!(
"failed to read solidity source\n . path: '{}'\n . error: {:?}",
path.display(),
err
),
},
Code::Yul { path, contract } => match std::fs::read_to_string(&path) {
Ok(yul_source) => {
hex::encode(compile_yul_evm_deploy_code(&contract, &yul_source))
}
Err(err) => panic!(
"failed to read Yul source\n . path: '{}'\n . error: {:?}",
path.display(),
err
),
},
_ => panic!(
"the differential runner requires Code::Solidity or Code::Yul source"
),
};
let mut vm = evm