Skip to content

[frontend] Make hash tweaking into a function#819

Closed
paulcadman wants to merge 2 commits intomainfrom
hash_tweaking_function
Closed

[frontend] Make hash tweaking into a function#819
paulcadman wants to merge 2 commits intomainfrom
hash_tweaking_function

Conversation

@paulcadman
Copy link
Copy Markdown
Contributor

@paulcadman paulcadman commented Aug 27, 2025

This PR changes the ChainTweak circuit from a struct:

pub struct ChainTweak {
  ... inout wires to be populated ...
}


impl ChainTweak {
  fn new(builder:: &CircuitBuilder, params) -> Self {
     ... build circuit ...
  }
}

To a function:

pub fn verify_chain_tweak(builder: &CircuitBuilder, params, ... inout wires ..., ) -> Keccak {
  ... build circuit ...
}

The populate_*functions are also removed, the caller is reponsible for populating the wires.

The function reutrns a Keccak verifier that must be populated with the expected digest and message.

A base verify_tweaked_keccak​ is also factored out which handles all tweaks of the form Keccak256(param || tweak || additional)​, this circuit will be used as a common function by all the tweaking circuits we need for hash-based signatures.

Note

Ideally the message wries would be passed in as an argument to the function, but there’s added complexity with this approach. The Keccak circuit contains a padded version of the message. This would have to be constructed and passed into the verify_chain_tweak​ function separately. So in this case it is arguable that it’s simpler to reuse the Keccak struct.

Copy link
Copy Markdown
Contributor Author

paulcadman commented Aug 27, 2025


How to use the Graphite Merge Queue

Add the label merge-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@paulcadman paulcadman changed the base branch from 08-20-_frontend_add_hash_chain_verification to graphite-base/819 August 27, 2025 18:26
@paulcadman paulcadman force-pushed the hash_tweaking_function branch from 2a86a1d to 92a189f Compare August 27, 2025 18:27
@paulcadman paulcadman changed the base branch from graphite-base/819 to main August 27, 2025 18:27
@paulcadman paulcadman marked this pull request as ready for review August 28, 2025 15:22
@paulcadman paulcadman requested a review from jadnohra August 28, 2025 15:48
@paulcadman paulcadman force-pushed the hash_tweaking_function branch from 92a189f to 4ffb0a9 Compare August 28, 2025 17:46
@paulcadman paulcadman force-pushed the hash_tweaking_function branch from c92982e to 75246c9 Compare September 1, 2025 12:08
@graphite-app
Copy link
Copy Markdown

graphite-app bot commented Sep 1, 2025

Merge activity

  • Sep 1, 3:16 PM UTC: paulcadman added this pull request to the Graphite merge queue.
  • Sep 1, 3:16 PM UTC: CI is running for this pull request on a draft pull request (#897) due to your merge queue CI optimization settings.
  • Sep 1, 3:22 PM UTC: Merged by the Graphite merge queue via draft PR: #897.

graphite-app bot pushed a commit that referenced this pull request Sep 1, 2025
This PR changes the ChainTweak circuit from a struct:

```
pub struct ChainTweak {
  ... inout wires to be populated ...
}

impl ChainTweak {
  fn new(builder:: &CircuitBuilder, params) -> Self {
     ... build circuit ...
  }
}
```

To a function:

```
pub fn verify_chain_tweak(builder: &CircuitBuilder, params, ... inout wires ..., ) -> Keccak {
  ... build circuit ...
}
```

The `populate_*`functions are also removed, the caller is reponsible for populating the wires.

The function reutrns a Keccak verifier that must be populated with the expected digest and message.

A base `verify_tweaked_keccak`​ is also factored out which handles all tweaks of the form `Keccak256(param || tweak || additional)`​, this circuit will be used as a common function by all the tweaking circuits we need for hash-based signatures.

### Note

Ideally the message wries would be passed in as an argument to the function, but there’s added complexity with this approach. The Keccak circuit contains a padded version of the message. This would have to be constructed and passed into the `verify_chain_tweak`​ function separately. So in this case it is arguable that it’s simpler to reuse the Keccak struct.

​
@graphite-app graphite-app bot closed this Sep 1, 2025
@graphite-app graphite-app bot deleted the hash_tweaking_function branch September 1, 2025 15:22
lockedloop pushed a commit that referenced this pull request Sep 8, 2025
This PR changes the ChainTweak circuit from a struct:

```
pub struct ChainTweak {
  ... inout wires to be populated ...
}

impl ChainTweak {
  fn new(builder:: &CircuitBuilder, params) -> Self {
     ... build circuit ...
  }
}
```

To a function:

```
pub fn verify_chain_tweak(builder: &CircuitBuilder, params, ... inout wires ..., ) -> Keccak {
  ... build circuit ...
}
```

The `populate_*`functions are also removed, the caller is reponsible for populating the wires.

The function reutrns a Keccak verifier that must be populated with the expected digest and message.

A base `verify_tweaked_keccak`​ is also factored out which handles all tweaks of the form `Keccak256(param || tweak || additional)`​, this circuit will be used as a common function by all the tweaking circuits we need for hash-based signatures.

### Note

Ideally the message wries would be passed in as an argument to the function, but there’s added complexity with this approach. The Keccak circuit contains a padded version of the message. This would have to be constructed and passed into the `verify_chain_tweak`​ function separately. So in this case it is arguable that it’s simpler to reuse the Keccak struct.

​
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.

2 participants