mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Changelog and test for the KeccakCaching bug
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
function f() public view returns (bool ret) {
|
||||
assembly {
|
||||
let x := calldataload(0)
|
||||
mstore(0, x)
|
||||
mstore(0x20, x)
|
||||
let a := keccak256(0, 4)
|
||||
let b := keccak256(0x20, 4)
|
||||
ret := eq(a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> true
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
function f() public view returns (bool ret) {
|
||||
assembly {
|
||||
let x := calldataload(0)
|
||||
mstore(0, x)
|
||||
mstore(0x20, x)
|
||||
let a := keccak256(0, 4)
|
||||
let b := keccak256(0x20, 8)
|
||||
ret := eq(a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> false
|
||||
@@ -0,0 +1,21 @@
|
||||
contract C {
|
||||
uint[] data;
|
||||
|
||||
function val() public returns (bool) {
|
||||
assembly {
|
||||
sstore(0, 2)
|
||||
mstore(0, 0)
|
||||
sstore(keccak256(0, 32), 234)
|
||||
// A bug in the caching mechanism previously caused keccak256(0, 23) to be the same as
|
||||
// keccak256(0, 32), leading to `data[1] == 123` being true.
|
||||
sstore(add(keccak256(0, 23), 1), 123)
|
||||
}
|
||||
assert(data[1] != 123);
|
||||
assert(data[1] == 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// val() -> true
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
function f(string memory s) public returns (bool ret) {
|
||||
assembly {
|
||||
let a := keccak256(s, 32)
|
||||
let b := keccak256(s, 8)
|
||||
ret := eq(a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(string): "" -> false
|
||||
// f(string): 0x20, 5, "hello" -> false
|
||||
// f(string): 0x20, 0x2e, 29457663690442756349866640336617293820574110049925353194191585327958485180523, 45859201465615193776739262511799714667061496775486067316261261194408342061056 -> false
|
||||
Reference in New Issue
Block a user