-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Karim Taam <[email protected]>
- Loading branch information
Showing
14 changed files
with
290 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...src/main/java/org/hyperledger/besu/ethereum/mainnet/VerkleDevnetBlockHeaderFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.mainnet; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; | ||
import org.hyperledger.besu.ethereum.core.ParsedExtraData; | ||
import org.hyperledger.besu.ethereum.rlp.RLP; | ||
import org.hyperledger.besu.ethereum.rlp.RLPOutput; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
/** Implements the block hashing algorithm for MainNet as per the yellow paper. */ | ||
public class VerkleDevnetBlockHeaderFunctions implements BlockHeaderFunctions { | ||
|
||
@Override | ||
public Hash hash(final BlockHeader header) { | ||
return createHash(header); | ||
} | ||
|
||
public static Hash createHash(final BlockHeader header) { | ||
final Bytes rlp = RLP.encode(rlpOutput -> serializeBlockHeader(header, rlpOutput)); | ||
return Hash.hash(rlp); | ||
} | ||
|
||
// TODO: Remove for mainnet, only needed for the current Verkle devnet. | ||
protected static void serializeBlockHeader(final BlockHeader blockHeader, final RLPOutput out) { | ||
out.startList(); | ||
|
||
out.writeBytes(blockHeader.getParentHash()); | ||
out.writeBytes(blockHeader.getOmmersHash()); | ||
out.writeBytes(blockHeader.getCoinbase()); | ||
out.writeBytes(blockHeader.getStateRoot()); | ||
out.writeBytes(blockHeader.getTransactionsRoot()); | ||
out.writeBytes(blockHeader.getReceiptsRoot()); | ||
out.writeBytes(blockHeader.getLogsBloom()); | ||
out.writeUInt256Scalar(blockHeader.getDifficulty()); | ||
out.writeLongScalar(blockHeader.getNumber()); | ||
out.writeLongScalar(blockHeader.getGasLimit()); | ||
out.writeLongScalar(blockHeader.getGasUsed()); | ||
out.writeLongScalar(blockHeader.getTimestamp()); | ||
out.writeBytes(blockHeader.getExtraData()); | ||
out.writeBytes(blockHeader.getMixHashOrPrevRandao()); | ||
out.writeLong(blockHeader.getNonce()); | ||
do { | ||
if (blockHeader.getBaseFee().isEmpty()) break; | ||
out.writeUInt256Scalar(blockHeader.getBaseFee().get()); | ||
|
||
if (blockHeader.getWithdrawalsRoot().isEmpty()) break; | ||
out.writeBytes(blockHeader.getWithdrawalsRoot().get()); | ||
} while (false); | ||
out.endList(); | ||
} | ||
|
||
@Override | ||
public ParsedExtraData parseExtraData(final BlockHeader header) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.