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: blob_hash #489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: blob_hash #489

wants to merge 1 commit into from

Conversation

obatirou
Copy link
Contributor

Close #479


// If index is within bounds, get the hash at that index
// Otherwise return zero bytes
let (high, low) = split_felt(blob_hashes.value.len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it's fine to do this because we don't want to over analyze the evm

but blob_hashes.value.len right now is between 2 and 5, in the future it'll be at most 200 or maybe 1000

if (out_of_bounds.value == 0) {
tempvar blob_hash = Bytes32(new Bytes32Struct(0, 0));
} else {
tempvar blob_hash = blob_hashes.value.data[index.value.low];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're only using index.value.low, we should probably assert index.value.high == 0, as well as blob_hashes.value.len.high ==0,
then just compare the two low felt values

Copy link
Collaborator

@enitrat enitrat Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably assert index.value.high == 0,

no, this would be a deviation to spec. MAX_U256 would be a valid blob_hash index query and would return zero. We must not assume anything on the validity range of this input value.

for len(blob_hashes), we can assume (and assert) that this number is way below 2**128.

so either:

  1. just do u256 comparison, which is done now and is correct
  2. assert len(blob_hashes) < 2128, and return zero if input >= 2128 or if input < len

// If index is within bounds, get the hash at that index
// Otherwise return zero bytes
let (high, low) = split_felt(blob_hashes.value.len);
let out_of_bounds = U256_lt(index, U256(new U256Struct(low, high)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_bounds ?

Suggested change
let out_of_bounds = U256_lt(index, U256(new U256Struct(low, high)));
let in_bounds = U256_lt(index, U256(new U256Struct(low, high)));

if (out_of_bounds.value == 0) {
tempvar blob_hash = Bytes32(new Bytes32Struct(0, 0));
} else {
tempvar blob_hash = blob_hashes.value.data[index.value.low];
Copy link
Collaborator

@enitrat enitrat Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably assert index.value.high == 0,

no, this would be a deviation to spec. MAX_U256 would be a valid blob_hash index query and would return zero. We must not assume anything on the validity range of this input value.

for len(blob_hashes), we can assume (and assert) that this number is way below 2**128.

so either:

  1. just do u256 comparison, which is done now and is correct
  2. assert len(blob_hashes) < 2128, and return zero if input >= 2128 or if input < len

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blob_hash
3 participants