Skip to content

Commit

Permalink
Change _creationCodeFor so that it uses the same constructor as the o…
Browse files Browse the repository at this point in the history
…ne compiler would generate

This will enable source code verification of the deployed token bridge contracts on the child chain
  • Loading branch information
gvladika committed Nov 22, 2023
1 parent 778ee85 commit 9907fa2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
31 changes: 15 additions & 16 deletions contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,23 @@ contract L2AtomicTokenBridgeFactory {
}

/**
* @notice Generate a creation code that results on a contract with `code` as bytecode.
* Source - https://github.com/0xsequence/sstore2/blob/master/contracts/utils/Bytecode.sol
* @param code The returning value of the resulting `creationCode`
* @return creationCode (constructor) for new contract
* @notice Generate a creation code that results with a contract with `code` as deployed code.
* Generated creation code shall match the one generated by Solidity compiler.
* @dev Prepended constructor bytecode consists of:
* - 608060405234801561001057600080fd5b50 - 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
* @param code Deployed bytecode to which constructor bytecode will be prepended
* @return Creation code of a new contract
*/
function _creationCodeFor(bytes memory code) internal pure returns (bytes memory) {
/*
0x00 0x63 0x63XXXXXX PUSH4 _code.length size
0x01 0x80 0x80 DUP1 size size
0x02 0x60 0x600e PUSH1 14 14 size size
0x03 0x60 0x6000 PUSH1 00 0 14 size size
0x04 0x39 0x39 CODECOPY size
0x05 0x60 0x6000 PUSH1 00 0 size
0x06 0xf3 0xf3 RETURN
<CODE>
*/

return abi.encodePacked(hex"63", uint32(code.length), hex"80600E6000396000F3", code);
return abi.encodePacked(
hex"608060405234801561001057600080fd5b50",
hex"61",
uint16(code.length),
hex"806100206000396000f3fe",
code
);
}
}

Expand Down
31 changes: 15 additions & 16 deletions contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -662,24 +662,23 @@ contract L1AtomicTokenBridgeCreator is Initializable, OwnableUpgradeable {
}

/**
* @notice Generate a creation code that results on a contract with `code` as bytecode.
* Source - https://github.com/0xsequence/sstore2/blob/master/contracts/utils/Bytecode.sol
* @param code The returning value of the resulting `creationCode`
* @return creationCode (constructor) for new contract
* @notice Generate a creation code that results with a contract with `code` as deployed code.
* Generated creation code shall match the one generated by Solidity compiler.
* @dev Prepended constructor bytecode consists of:
* - 608060405234801561001057600080fd5b50 - 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
* @param code Deployed bytecode to which constructor bytecode will be prepended
* @return Creation code of a new contract
*/
function _creationCodeFor(bytes memory code) internal pure returns (bytes memory) {
/*
0x00 0x63 0x63XXXXXX PUSH4 _code.length size
0x01 0x80 0x80 DUP1 size size
0x02 0x60 0x600e PUSH1 14 14 size size
0x03 0x60 0x6000 PUSH1 00 0 14 size size
0x04 0x39 0x39 CODECOPY size
0x05 0x60 0x6000 PUSH1 00 0 size
0x06 0xf3 0xf3 RETURN
<CODE>
*/

return abi.encodePacked(hex"63", uint32(code.length), hex"80600E6000396000F3", code);
return abi.encodePacked(
hex"608060405234801561001057600080fd5b50",
hex"61",
uint16(code.length),
hex"806100206000396000f3fe",
code
);
}

/**
Expand Down

0 comments on commit 9907fa2

Please sign in to comment.