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

Commit

Permalink
[KGA-32] [KGA-143] [KGA-86] [KGA-88]fix: last 10 blockhash are 0 (#1593)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #<Issue number>

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

Last 10 blocks returns 0 for blockhash

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1593)
<!-- Reviewable:end -->
  • Loading branch information
obatirou authored Nov 8, 2024
1 parent b2f53ba commit d962582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit d962582

Please sign in to comment.