diff --git a/.github/workflows/cairo-zero-ci.yml b/.github/workflows/cairo-zero-ci.yml index ae3819887..016b54bbc 100644 --- a/.github/workflows/cairo-zero-ci.yml +++ b/.github/workflows/cairo-zero-ci.yml @@ -180,6 +180,7 @@ jobs: uses: actions/checkout@v4 with: repository: kkrt-labs/ef-tests + ref: feat/update-base-fee-state - name: Checkout local skip file uses: actions/checkout@v4 with: diff --git a/cairo_zero/backend/starknet.cairo b/cairo_zero/backend/starknet.cairo index 6e8865c6a..0a5c0eb73 100644 --- a/cairo_zero/backend/starknet.cairo +++ b/cairo_zero/backend/starknet.cairo @@ -146,19 +146,15 @@ namespace Starknet { let (block_number) = get_block_number(); let is_next_fee_ready = is_le(next_start_block_number, block_number); - let (res_current_block) = Kakarot_base_fee.read('current_block'); - let current_base_fee = res_current_block[0]; - let current_start_block_number = res_current_block[1]; - let is_already_updated = Helpers.is_zero( - current_start_block_number - next_start_block_number - ); - - if (is_already_updated == FALSE and is_next_fee_ready != FALSE) { - Kakarot_base_fee.write('current_block', (next_base_fee, next_start_block_number)); + if (next_start_block_number != 0 and is_next_fee_ready != FALSE) { + // update current_block storage and return next_block value + Kakarot_base_fee.write('current_block', (next_base_fee, block_number)); + Kakarot_base_fee.write('next_block', (0, 0)); return (next_base_fee,); } - return (current_base_fee,); + let (res_current_block) = Kakarot_base_fee.read('current_block'); + return (res_current_block[0],); } } diff --git a/cairo_zero/tests/src/kakarot/test_kakarot.py b/cairo_zero/tests/src/kakarot/test_kakarot.py index ea6f8efe0..284c31a1d 100644 --- a/cairo_zero/tests/src/kakarot/test_kakarot.py +++ b/cairo_zero/tests/src/kakarot/test_kakarot.py @@ -276,34 +276,34 @@ def test_get_base_fee_should_return_next_block_fee_if_applicable_and_update_curr base_fee = cairo_run("test__get_base_fee") assert base_fee == 2 - # Should read the value from next_block + # Should update current block base fee SyscallHandler.mock_storage.assert_any_call( address=get_storage_var_address( - "Kakarot_base_fee", int.from_bytes(b"next_block", "big") + "Kakarot_base_fee", int.from_bytes(b"current_block", "big") ), value=base_fee, ) SyscallHandler.mock_storage.assert_any_call( address=get_storage_var_address( - "Kakarot_base_fee", int.from_bytes(b"next_block", "big") + "Kakarot_base_fee", int.from_bytes(b"current_block", "big") ) + 1, value=0x101, ) - # Should update current block base fee + # Should nullify the value from next_block SyscallHandler.mock_storage.assert_any_call( address=get_storage_var_address( - "Kakarot_base_fee", int.from_bytes(b"current_block", "big") + "Kakarot_base_fee", int.from_bytes(b"next_block", "big") ), - value=base_fee, + value=0, ) SyscallHandler.mock_storage.assert_any_call( address=get_storage_var_address( - "Kakarot_base_fee", int.from_bytes(b"current_block", "big") + "Kakarot_base_fee", int.from_bytes(b"next_block", "big") ) + 1, - value=0x101, + value=0, ) class TestCoinbase: