Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: rm check on the the number of block header fields within proveAncestralBlockHashes #70

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions packages/evm/contracts/adapters/BlockHashAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ abstract contract BlockHashAdapter is IBlockHashAdapter, Adapter {
function proveAncestralBlockHashes(uint256 chainId, bytes[] memory blockHeaders) external {
for (uint256 i = 0; i < blockHeaders.length; i++) {
RLPReader.RLPItem memory blockHeaderRLP = RLPReader.toRlpItem(blockHeaders[i]);

if (!blockHeaderRLP.isList()) revert InvalidBlockHeaderRLP();

RLPReader.RLPItem[] memory blockHeaderContent = blockHeaderRLP.toList();

// A block header should have between 15 and 17 elements (baseFee and withdrawalsRoot have been added later)
if (blockHeaderContent.length < 15 || blockHeaderContent.length > 17)
revert InvalidBlockHeaderLength(blockHeaderContent.length);

bytes32 blockParent = bytes32(blockHeaderContent[0].toUint());
uint256 blockNumber = uint256(blockHeaderContent[8].toUint());

bytes32 blockHash = keccak256(blockHeaders[i]);
bytes32 storedBlockHash = getHash(chainId, blockNumber);

if (blockHash != storedBlockHash) revert ConflictingBlockHeader(blockNumber, blockHash, storedBlockHash);

_storeHash(chainId, blockNumber - 1, blockParent);
Expand Down
1 change: 0 additions & 1 deletion packages/evm/contracts/interfaces/IAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pragma solidity ^0.8.0;
*/
interface IAdapter {
error ConflictingBlockHeader(uint256 blockNumber, bytes32 blockHash, bytes32 storedBlockHash);
error InvalidBlockHeaderLength(uint256 length);
error InvalidBlockHeaderRLP();

/**
Expand Down
20 changes: 0 additions & 20 deletions packages/evm/test/adapters/02_Adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,5 @@ describe("Adapter", function () {
"InvalidBlockHeaderRLP",
)
})

it("Reverts if block proof doesn't match valid block header lengths", async function () {
const { adapter, blocks } = await setup()
const blockHeaderContents = RLP.decode(blockRLP(blocks[0]))
const blockHeaderTooShortContents = blockHeaderContents.slice(0, 14)
const blockHeaderTooShort = RLP.encode(blockHeaderTooShortContents)

// Block header RLP contains too few elements
await expect(adapter.proveAncestralBlockHashes(CHAIN_ID, [blockHeaderTooShort]))
.to.revertedWithCustomError(adapter, "InvalidBlockHeaderLength")
.withArgs(blockHeaderTooShortContents.length)

const blockHeaderTooLongContents = blockHeaderContents.concat([adapter.address, adapter.address])
const blockHeaderTooLong = RLP.encode(blockHeaderTooLongContents)

// Block header RLP contains too many elements
await expect(adapter.proveAncestralBlockHashes(CHAIN_ID, [blockHeaderTooLong]))
.to.revertedWithCustomError(adapter, "InvalidBlockHeaderLength")
.withArgs(blockHeaderTooLongContents.length)
})
})
})
Loading