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

feat: add coinbase to header field decoder #62

Merged
merged 1 commit into from
Jul 24, 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
2 changes: 1 addition & 1 deletion src/converter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func le_address_chunks_to_felt{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, po
let (w1) = word_reverse_endian_64{bitwise_ptr=bitwise_ptr}([right_shifted + 1]);
let (w2) = word_reverse_endian_64{bitwise_ptr=bitwise_ptr}([right_shifted + 2]);

return (address=w0 * 2 ** 128 + w1 * 2 ** 64 + w2);
return (address=w0 * pow2_array[128] + w1 * pow2_array[64] + w2);
}
8 changes: 2 additions & 6 deletions src/decoders/header_decoder.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ namespace HeaderDecoder {
func get_field_felt{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, pow2_array: felt*}(
rlp: felt*, field: felt
) -> (value: felt*, value_len: felt, bytes_len: felt) {
if (field == HeaderField.COINBASE) {
let value = get_address_value(rlp, 8, 6);
return (value=value, value_len=3, bytes_len=20);
}

if (field == HeaderField.BLOOM) {
return get_bloom_filter(rlp);
}
Expand All @@ -79,7 +74,8 @@ namespace HeaderDecoder {
return get_hash_value(rlp, 4, 5);
}
if (field == HeaderField.COINBASE) {
assert 1 = 0; // must use get_coinbase
let address = get_address_value(rlp, 8, 6);
return (Uint256(low=[address] + [address + 1] * pow2_array[64], high=[address + 2]));
}
if (field == HeaderField.STATE_ROOT) {
return get_hash_value(rlp, 11, 3);
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_header_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def fetch_header_dict(block_number):
(low, high) = reverse_and_split_256_bytes(block.receiptsRoot)
block_dict["receipts_root"] = {"low": low, "high": high}

coinbase = bytes_to_8_bytes_chunks_little(block.coinbase)
block_dict["coinbase"] = coinbase
(low, high) = reverse_and_split_256_bytes(block.coinbase)
block_dict["coinbase"] = {"low": low, "high": high}

block_dict["difficulty"] = block.difficulty
block_dict["number"] = block.number
Expand Down
12 changes: 6 additions & 6 deletions tests/utils/header.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func test_header_decoding{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, pow2_ar
local header_type: felt;
local expected_parent_hash: Uint256;
local expected_uncles_hash: Uint256;
let (expected_coinbase) = alloc();
local expected_coinbase: Uint256;
local expected_state_root: Uint256;
local expected_tx_root: Uint256;
local expected_receipts_root: Uint256;
Expand Down Expand Up @@ -51,7 +51,8 @@ func test_header_decoding{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, pow2_ar
ids.expected_parent_hash.high = header['parent_hash']["high"]
ids.expected_uncles_hash.low = header['uncles_hash']["low"]
ids.expected_uncles_hash.high = header['uncles_hash']["high"]
segments.write_arg(ids.expected_coinbase, header['coinbase'])
ids.expected_coinbase.low = header['coinbase']["low"]
ids.expected_coinbase.high = header['coinbase']["high"]
ids.expected_state_root.low = header['state_root']["low"]
ids.expected_state_root.high = header['state_root']["high"]
ids.expected_tx_root.low = header['tx_root']["low"]
Expand Down Expand Up @@ -102,10 +103,9 @@ func test_header_decoding{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, pow2_ar
assert uncles_hash.low = expected_uncles_hash.low;
assert uncles_hash.high = expected_uncles_hash.high;

let (coinbase, _, _) = HeaderDecoder.get_field_felt(rlp, HeaderField.COINBASE);
assert coinbase[0] = expected_coinbase[0];
assert coinbase[1] = expected_coinbase[1];
assert coinbase[2] = expected_coinbase[2];
let coinbase = HeaderDecoder.get_field(rlp, HeaderField.COINBASE);
assert coinbase.low = expected_coinbase.low;
assert coinbase.high = expected_coinbase.high;

let state_root = HeaderDecoder.get_field(rlp, HeaderField.STATE_ROOT);
assert state_root.low = expected_state_root.low;
Expand Down
Loading