From 9adf01a90249824ca6ca35b163a36e292979ae8e Mon Sep 17 00:00:00 2001 From: Oba Date: Fri, 8 Nov 2024 12:32:48 +0100 Subject: [PATCH] fix: last 10 blockhash are 0 --- .../kakarot/instructions/block_information.cairo | 4 +++- tests/end_to_end/PlainOpcodes/test_plain_opcodes.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cairo_zero/kakarot/instructions/block_information.cairo b/cairo_zero/kakarot/instructions/block_information.cairo index 6f736322c..a0f928263 100644 --- a/cairo_zero/kakarot/instructions/block_information.cairo +++ b/cairo_zero/kakarot/instructions/block_information.cairo @@ -165,7 +165,9 @@ namespace Internals { } let lower_bound = Helpers.saturated_sub(evm.message.env.block_number, 256); - let in_range = is_in_range(block_number.low, lower_bound, evm.message.env.block_number); + let in_range = is_in_range( + block_number.low, lower_bound, evm.message.env.block_number - 10 + ); if (in_range == FALSE) { Stack.push_uint256(Uint256(0, 0)); diff --git a/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py b/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py index cb24f2040..e755223be 100644 --- a/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py +++ b/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py @@ -63,6 +63,19 @@ async def test_should_return_zero_with_invalid_block_number( assert int.from_bytes(blockhash_invalid_number, byteorder="big") == 0 + async def test_should_return_zero_for_last_10_blocks( + self, plain_opcodes, block_number + ): + last_10_block_hashes = [ + await plain_opcodes.opcodeBlockHash(await block_number("latest") - i) + for i in range(10) + ] + # assert all blockhashes are zero + assert all( + int.from_bytes(blockhash, byteorder="big") == 0 + for blockhash in last_10_block_hashes + ) + class TestAddress: async def test_should_return_self_address(self, plain_opcodes): address = await plain_opcodes.opcodeAddress()