Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for BLOCKHASH conversion error #1025

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package net.consensys.linea.blockcapture;

import java.math.BigInteger;
import java.util.List;
import java.util.Set;

Expand All @@ -39,6 +38,10 @@
import org.hyperledger.besu.plugin.data.BlockHeader;

public class BlockCapturer implements ConflationAwareOperationTracer {
public static final int MAX_RELATIVE_BLOCK = 256;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use BLOCKHASH_MAX_HISTORY in GlobalConstants.java

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well maybe at some point I'll put that in


private static final int MAX_BLOCK_ARG_SIZE = 8;

/**
* The {@link Reaper} will collect all the data that will need to be mimicked to replay the block.
*/
Expand Down Expand Up @@ -160,13 +163,21 @@ public void tracePreExecution(MessageFrame frame) {

case BLOCKHASH -> {
if (frame.stackSize() > 0) {
BigInteger peek0 = frame.getStackItem(0).toUnsignedBigInteger();
// Determine block number requested
final long blockNumber = peek0.longValueExact();
// Use enclosing frame to determine hash
Hash blockHash = frame.getBlockHashLookup().apply(blockNumber);
// Record it was seen
this.reaper.touchBlockHash(blockNumber, blockHash);
// Determine current block number
final long currentBlockNumber = frame.getBlockValues().getNumber();
final Bytes arg = frame.getStackItem(0).trimLeadingZeros();
// Check arguments fits within 8 bytes
if (arg.size() <= 8) {
// Determine block number requested
final long blockNumber = arg.toLong();
// Sanity check block within last 256 blocks.
if (blockNumber < currentBlockNumber && (currentBlockNumber - blockNumber) <= 256) {
// Use enclosing frame to determine hash
Hash blockHash = frame.getBlockHashLookup().apply(blockNumber);
// Record it was seen
this.reaper.touchBlockHash(blockNumber, blockHash);
}
}
}
}
}
Expand Down
Loading