solidity/test/libsolidity/semanticTests/salted_create/prediction_example.sol
Daniel Kirchner 44da8507b1 Change default EVM version to Shanghai.
Co-authored-by: Rodrigo Q. Saramago <rodrigoqsaramago@gmail.com>
2023-05-08 16:34:23 +02:00

30 lines
693 B
Solidity

contract D {
uint public x;
constructor(uint a) {
x = a;
}
}
contract C {
function createDSalted(bytes32 salt, uint arg) public {
address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked(
bytes1(0xff),
address(this),
salt,
keccak256(abi.encodePacked(
type(D).creationCode,
arg
))
)))));
D d = new D{salt: salt}(arg);
require(address(d) == predictedAddress, "Address mismatch.");
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// createDSalted(bytes32,uint256): 42, 64 ->
// gas legacy: 102921