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

bug: Parsing risc0 proof which is 0 padded does not parse correctly #230

Closed
stefanMadzharov opened this issue Oct 16, 2024 · 3 comments
Closed
Assignees

Comments

@stefanMadzharov
Copy link
Contributor

stefanMadzharov commented Oct 16, 2024

Bug Report

Garaga version:

Current behavior:

In the moment if we have for example in the proof.json the following journal value:
{ "journal": "0x00000000000000000000000000000000000000000000000000000000000f3893" }
the
return Groth16Proof._from_risc0( seal=bytes.fromhex(seal[2:]), image_id=bytes.fromhex(image_id[2:]), journal=bytes.fromhex(journal[2:]), ) is failing because the line
journal=bytes.fromhex(journal[2:]), is failing and the fallback option is to call
public_inputs = find_item_from_key_patterns(data, ["public"]) which fails.

Expected behavior:

The correct behavior would be to correctly parse the journal.

Steps to reproduce:

Just put
{ "journal": "0x00000000000000000000000000000000000000000000000000000000000f3893" } in the proof.json and it would fail.

@stefanMadzharov
Copy link
Contributor Author

I think I can fix it.

@feltroidprime
Copy link
Collaborator

feltroidprime commented Oct 16, 2024

Right.
Important finding indeed.

I would suggest

  • creating a specific Exception "KeyPatternNotFound" to
    def find_item_from_key_patterns(data: dict, key_patterns: List[str]) -> Any:
    best_match = None
    best_score = -1
    for key, value in data.items():
    for pattern in key_patterns:
    if key.lower() == pattern.lower():
    # Exact match
    return value
    elif pattern.lower() in key.lower():
    # Partial match
    score = key.lower().count(pattern.lower())
    if score > best_score:
    best_match = value
    best_score = score
    if best_match is not None:
    return best_match
    else:
    raise ValueError(f"No key found with patterns {key_patterns}")
    to catch specifically this exception and pass only for this one
    except ValueError:
    pass
    except KeyError:
    pass
    except Exception as e:
    print(f"Error: {e}")
    raise e
  • Changing the logic
            seal = io.to_hex_str(find_item_from_key_patterns(data, ["seal"]))
            image_id = io.to_hex_str(find_item_from_key_patterns(data, ["image_id"]))
            journal = io.to_hex_str(find_item_from_key_patterns(data, ["journal"]))

io.to_hex_str is trimming the 0's on the left hence when taking bytes of even number of nibbles it's failing.

@feltroidprime
Copy link
Collaborator

closed by #233

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

No branches or pull requests

2 participants