Skip to content

Commit

Permalink
feat(contracts): change hash function in colosseum for shanghai block (
Browse files Browse the repository at this point in the history
…#279)

* feat(contracts): change hash function in colosseum for shanghai block

* chore: bump kroma-geth to v0.4.5-rc.2
  • Loading branch information
0xHansLee authored Mar 27, 2024
1 parent 2e548aa commit d203a4a
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 261 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ require (

replace github.com/ethereum-optimism/optimism v1.4.0 => ./

replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v0.4.5-rc.1
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v0.4.5-rc.2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kroma-network/go-ethereum v0.4.5-rc.1 h1:L1oqaFSsYhYwVMYDw4ziPwCAnuJMzrn3qEJ0Uop7AHo=
github.com/kroma-network/go-ethereum v0.4.5-rc.1/go.mod h1:SsK2EAbCigQsKUmhnHSe9KXrUEg2RKJcKFT2+/f2Q+M=
github.com/kroma-network/go-ethereum v0.4.5-rc.2 h1:bXKnAxYy4X1Yydm84uq3raScdEaKyF2ItkV+WHh7gfU=
github.com/kroma-network/go-ethereum v0.4.5-rc.2/go.mod h1:SsK2EAbCigQsKUmhnHSe9KXrUEg2RKJcKFT2+/f2Q+M=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84 h1:VpLCQx+tFV6Nk0hbs3Noyxma/q9wIDdyacKpGQWUMI8=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84/go.mod h1:w54LrYo5rJEV503BgMPRNONsLTOEQv5V87q+uYaw9sM=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
2 changes: 1 addition & 1 deletion kroma-bindings/bindings/colosseum.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions kroma-bindings/bindings/colosseum_more.go

Large diffs are not rendered by default.

91 changes: 46 additions & 45 deletions op-e2e/testdata/challenge_test_data.go

Large diffs are not rendered by default.

Binary file modified op-e2e/testdata/proof/verify_circuit_final_pair.data
Binary file not shown.
Binary file modified op-e2e/testdata/proof/verify_circuit_proof.data
Binary file not shown.
2 changes: 1 addition & 1 deletion ops-devnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:

l2:
pid: host # allow debugging
image: kromanetwork/geth:v0.4.5-rc.1
image: kromanetwork/geth:v0.4.5-rc.2
ports:
- "9545:8545"
- "9546:8546"
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/contracts/L1/Colosseum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,10 @@ contract Colosseum is Initializable, ISemver {
"Colosseum: the state root must be matched"
);

bytes32 blockHash = Hashing.hashBlockHeader(_publicInput, _rlps);
bytes32 blockHash = Hashing.hashBlockHeaderShanghai(_publicInput, _rlps);
require(
_srcOutputRootProof.nextBlockHash == blockHash,
"Colosseum: the block hash must be matched"
"Colosseum: the block hash from public input must be matched"
);
}

Expand Down
53 changes: 22 additions & 31 deletions packages/contracts/contracts/libraries/Hashing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ library Hashing {
*
* @return Hash of the RLP encoded L2 deposit transaction.
*/
function hashDepositTransaction(Types.UserDepositTransaction memory _tx)
internal
pure
returns (bytes32)
{
function hashDepositTransaction(
Types.UserDepositTransaction memory _tx
) internal pure returns (bytes32) {
return keccak256(Encoding.encodeDepositTransaction(_tx));
}

Expand All @@ -37,11 +35,10 @@ library Hashing {
*
* @return Hash of the deposit transaction's "source hash".
*/
function hashDepositSource(bytes32 _l1BlockHash, uint64 _logIndex)
internal
pure
returns (bytes32)
{
function hashDepositSource(
bytes32 _l1BlockHash,
uint64 _logIndex
) internal pure returns (bytes32) {
bytes32 depositId = keccak256(abi.encode(_l1BlockHash, _logIndex));
return keccak256(abi.encode(bytes32(0), depositId));
}
Expand Down Expand Up @@ -115,11 +112,9 @@ library Hashing {
*
* @return Hashed withdrawal transaction.
*/
function hashWithdrawal(Types.WithdrawalTransaction memory _tx)
internal
pure
returns (bytes32)
{
function hashWithdrawal(
Types.WithdrawalTransaction memory _tx
) internal pure returns (bytes32) {
return
keccak256(
abi.encode(_tx.nonce, _tx.sender, _tx.target, _tx.value, _tx.gasLimit, _tx.data)
Expand All @@ -134,11 +129,9 @@ library Hashing {
*
* @return Hashed output root proof.
*/
function hashOutputRootProof(Types.OutputRootProof memory _outputRootProof)
internal
pure
returns (bytes32)
{
function hashOutputRootProof(
Types.OutputRootProof memory _outputRootProof
) internal pure returns (bytes32) {
if (_outputRootProof.version == bytes32(uint256(0))) {
return hashOutputRootProofV0(_outputRootProof);
} else {
Expand All @@ -154,11 +147,9 @@ library Hashing {
*
* @return Hashed output root proof.
*/
function hashOutputRootProofV0(Types.OutputRootProof memory _outputRootProof)
internal
pure
returns (bytes32)
{
function hashOutputRootProofV0(
Types.OutputRootProof memory _outputRootProof
) internal pure returns (bytes32) {
return
keccak256(
abi.encode(
Expand Down Expand Up @@ -255,7 +246,8 @@ library Hashing {
abi.encodePacked(
_prevStateRoot,
_publicInput.stateRoot,
_publicInput.withdrawalsRoot,
// NOTE(0xHansLee): the withdrawalsRoot is not used in Scroll's zkEVM circuit, so it is filled by zero
bytes32(0),
_publicInput.blockHash,
_publicInput.parentHash,
_publicInput.number,
Expand All @@ -277,11 +269,10 @@ library Hashing {
*
* @return Bytes32 array filled with dummy hash.
*/
function generateDummyHashes(bytes32 _dummyHashes, uint256 _length)
internal
pure
returns (bytes32[] memory)
{
function generateDummyHashes(
bytes32 _dummyHashes,
uint256 _length
) internal pure returns (bytes32[] memory) {
bytes32[] memory hashes = new bytes32[](_length);
for (uint256 i = 0; i < _length; i++) {
hashes[i] = _dummyHashes;
Expand Down
Loading

0 comments on commit d203a4a

Please sign in to comment.