Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

[KGA-32] [KGA-143] [KGA-86] [KGA-88]fix: last 10 blockhash are 0 #1593

Merged
merged 1 commit into from
Nov 8, 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
4 changes: 3 additions & 1 deletion cairo_zero/kakarot/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions tests/end_to_end/PlainOpcodes/test_plain_opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading