-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataFlowAnalyzer: Fix variable clearing nondeterminism (affecting CSE…
… and bytecode reproducibility) due to set insertions during iteration
- Loading branch information
Showing
8 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
object "C" { | ||
code {} | ||
|
||
object "C_deployed" { | ||
code { | ||
sstore(0, main(sload(0), sload(0), sload(0), sload(0))) | ||
|
||
function main(a, d, b, c) -> v { | ||
for {} 1 {} | ||
{ | ||
if iszero(b) { break } | ||
|
||
let mid := avg(b, c) | ||
switch gt(1, c) | ||
case 0 { | ||
b := cadd(mid, 0) | ||
} | ||
default { | ||
sstore(0x20, mid) | ||
} | ||
} | ||
} | ||
|
||
function f(x) -> r {} | ||
|
||
function avg(x, y) -> var { | ||
// In the other file `_1` is called `_2`. | ||
let _1 := add(x, y) | ||
var := add(_1, _1) | ||
} | ||
|
||
function cadd(x, y) -> sum { | ||
sum := add(x, y) | ||
|
||
if gt(0, sum) { | ||
mstore(0, 0) | ||
mstore(0, 0) | ||
revert(0, 0) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
object "C" { | ||
code {} | ||
|
||
object "C_deployed" { | ||
code { | ||
sstore(0, main(sload(0), sload(0), sload(0), sload(0))) | ||
|
||
function main(a, d, b, c) -> v { | ||
for {} 1 {} | ||
{ | ||
if iszero(b) { break } | ||
|
||
let mid := avg(b, c) | ||
switch gt(1, c) | ||
case 0 { | ||
b := cadd(mid, 0) | ||
} | ||
default { | ||
sstore(0x20, mid) | ||
} | ||
} | ||
} | ||
|
||
function f(x) -> r {} | ||
|
||
function avg(x, y) -> var { | ||
// In the other file `_2` is called `_1`. | ||
let _2 := add(x, y) | ||
var := add(_2, _2) | ||
} | ||
|
||
function cadd(x, y) -> sum { | ||
sum := add(x, y) | ||
|
||
if gt(0, sum) { | ||
mstore(0, 0) | ||
mstore(0, 0) | ||
revert(0, 0) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
# This is a regression test against https://github.com/ethereum/solidity/issues/14494 | ||
# Note that the two input files in this test differ only by the name of a single variable. | ||
# Due to the bug, a decision about which variable to use to replace a subexpression in CSE would | ||
# depend on sorting order of variable names. A variable not being used as a replacement could lead | ||
# to it being unused in general and removed by Unused Pruner. This would show up as a difference | ||
# in the bytecode. | ||
|
||
# shellcheck source=scripts/common.sh | ||
source "${REPO_ROOT}/scripts/common.sh" | ||
# shellcheck source=scripts/common_cmdline.sh | ||
source "${REPO_ROOT}/scripts/common_cmdline.sh" | ||
|
||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) | ||
|
||
function assemble { | ||
local input_file="$1" | ||
msg_on_error --no-stderr \ | ||
"$SOLC" --strict-assembly "$input_file" --optimize --debug-info none | | ||
stripCLIDecorations | ||
} | ||
|
||
diff_values \ | ||
"$(assemble "${SCRIPT_DIR}/input1.yul")" \ | ||
"$(assemble "${SCRIPT_DIR}/input2.yul")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters