2020-03-09 21:14:07 +00:00
|
|
|
contract D {
|
|
|
|
bytes32 public x;
|
|
|
|
|
2020-06-23 12:14:24 +00:00
|
|
|
constructor() {
|
2020-03-09 21:14:07 +00:00
|
|
|
bytes32 codeHash;
|
|
|
|
assembly {
|
|
|
|
let size := codesize()
|
|
|
|
codecopy(mload(0x40), 0, size)
|
|
|
|
codeHash := keccak256(mload(0x40), size)
|
|
|
|
}
|
|
|
|
x = codeHash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract C {
|
|
|
|
function testRuntime() public returns (bool) {
|
|
|
|
D d = new D();
|
|
|
|
bytes32 runtimeHash = keccak256(type(D).runtimeCode);
|
|
|
|
bytes32 otherHash;
|
|
|
|
uint256 size;
|
|
|
|
assembly {
|
|
|
|
size := extcodesize(d)
|
|
|
|
extcodecopy(d, mload(0x40), 0, size)
|
|
|
|
otherHash := keccak256(mload(0x40), size)
|
|
|
|
}
|
|
|
|
require(size == type(D).runtimeCode.length);
|
|
|
|
require(runtimeHash == otherHash);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCreation() public returns (bool) {
|
|
|
|
D d = new D();
|
|
|
|
bytes32 creationHash = keccak256(type(D).creationCode);
|
|
|
|
require(creationHash == d.x());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 15:26:51 +00:00
|
|
|
// ====
|
|
|
|
// compileViaYul: also
|
2020-03-09 21:14:07 +00:00
|
|
|
// ----
|
|
|
|
// testRuntime() -> true
|
|
|
|
// testCreation() -> true
|