mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adjust data section size during creation.
This commit is contained in:
@@ -5,14 +5,31 @@ contract D {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this is horrible and hopefully avoided at the spec level
|
||||
function adjustContractCodeForArgSize(bytes memory x, uint16 argSize)
|
||||
{
|
||||
assembly {
|
||||
let memPos := add(x, 32)
|
||||
let numCodeSections := shr(240, mload(add(memPos, 7)))
|
||||
let dataSectionSizeOffset := add(memPos, add(10, mul(numCodeSections, 2)))
|
||||
let tmp := mload(dataSectionSizeOffset)
|
||||
let dataSectionSize := shr(240, tmp)
|
||||
dataSectionSize := add(dataSectionSize, argSize)
|
||||
if gt(dataSectionSize, 0xFFFF) { revert(0,0) }
|
||||
mstore(dataSectionSizeOffset, or(shr(16, shl(16, tmp)), shl(240, dataSectionSize)))
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
function createDSalted(bytes32 salt, uint arg) public {
|
||||
bytes memory creationCode = type(D).creationCode;
|
||||
adjustContractCodeForArgSize(creationCode, 32);
|
||||
address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked(
|
||||
bytes1(0xff),
|
||||
address(this),
|
||||
salt,
|
||||
keccak256(abi.encodePacked(
|
||||
type(D).creationCode,
|
||||
creationCode,
|
||||
arg
|
||||
))
|
||||
)))));
|
||||
|
||||
Reference in New Issue
Block a user