Files
revive/crates/integration/contracts/AddressPredictor.sol
T
xermicus dab29bc89b bugfix missing byte swap for the create2 salt value (#272)
Found in https://github.com/paritytech/contract-issues/issues/45, thanks
@albertov19 and @sekisamu

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-03 15:20:22 +02:00

34 lines
880 B
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
contract Predicted {
uint public salt;
constructor(uint _salt) {
salt = _salt;
}
}
contract AddressPredictor {
constructor(uint _salt, bytes memory _bytecode) payable {
address deployed = address(new Predicted{salt: bytes32(_salt)}(_salt));
address predicted = predictAddress(_salt, _bytecode);
assert(deployed == predicted);
}
function predictAddress(
uint _foo,
bytes memory _bytecode
) public view returns (address predicted) {
bytes32 addr = keccak256(
abi.encodePacked(
bytes1(0xff),
address(this),
bytes32(_foo),
keccak256(abi.encodePacked(_bytecode, abi.encode(_foo)))
)
);
predicted = address(uint160(uint(addr)));
}
}