Skip to content

Commit

Permalink
Update hardcoded bytecode used to craft creation code from runtime code
Browse files Browse the repository at this point in the history
0.8.28 compiler version uses PUSH0 so code differes from previously used 0.8.16
  • Loading branch information
gvladika committed Oct 22, 2024
1 parent ad1a925 commit d283585
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions contracts/tokenbridge/libraries/CreationCodeHelper.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
pragma solidity 0.8.28;

library CreationCodeHelper {
/**
* @notice Generate a creation code that results with a contract with `code` as deployed code.
* @notice Generate a creation code that results with a contract with `runtimeCode` as deployed code.
* Generated creation code shall match the one generated by Solidity compiler with an empty constructor.
* @dev Prepended constructor bytecode consists of:
* - 608060405234801561001057600080fd5b50 - store free memory pointer, then check no callvalue is provided
* - 6080604052348015600e575f5ffd5b50 - store free memory pointer, then check no callvalue is provided
* - 61xxxx - push 2 bytes of `code` length
* - 806100206000396000f3fe - copy deployed code to memory and return the location of it
* - 8061001c5f395ff3fe - copy deployed code to memory and return the location of it
* @param runtimeCode Deployed bytecode to which constructor bytecode will be prepended
* @return Creation code of a new contract
*/
function getCreationCodeFor(bytes memory runtimeCode) internal pure returns (bytes memory) {
return abi.encodePacked(
hex"608060405234801561001057600080fd5b50",
hex"6080604052348015600e575f5ffd5b50",
hex"61",
uint16(runtimeCode.length),
hex"806100206000396000f3fe",
hex"8061001c5f395ff3fe",
runtimeCode
);
}
Expand Down
2 changes: 1 addition & 1 deletion test-foundry/AtomicTokenBridgeFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ contract AtomicTokenBridgeCreatorTest is Test {
assertTrue(l2bpf.code.length > 0, "l2bpf code");
assertEq(l2ue, 0x297eA477216C8E118278cB1D91D2A1dE761460f6, "l2ue");
assertTrue(l2ue.code.length > 0, "l2ue code");
assertEq(l2mc, 0x0313A116ef65CBc0342AeE389EB10dAC28b48804, "l2mc");
assertEq(l2mc, 0xfb61c207b20a581FA4559f90C1C50eb356c3BE10, "l2mc");
assertTrue(l2mc.code.length > 0, "l2mc code");
}
}
Expand Down

0 comments on commit d283585

Please sign in to comment.