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

Dynamic SHA2 #25

Merged
merged 47 commits into from
Oct 29, 2024
Merged

Dynamic SHA2 #25

merged 47 commits into from
Oct 29, 2024

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Oct 11, 2024

closes #27

adds an implementation of sha2 for a dynamic-length byte string. this primitive will be necessary for a variety of credential signatures.

overhead compared to sha2 on static-sized inputs is about 8% (in case the max number of blocks is not bigger than the actual number). This seems pretty good and hard to improve, most of it comes from a single pass over the input message asserting that the out-of-bounds elements are all 0.

also adds general-purpose types for:

  • dynamic-length arrays
  • static-length arrays

Todo

Results

> node --experimental-strip-types src/attestations/dynamic-sha256.test.ts

dynamic {
  'Total rows': 40840,
  Generic: 14318,
  EndoMulScalar: 11762,
  Xor16: 9840,
  Zero: 4920
}
static {
  'Total rows': 37779,
  Generic: 11529,
  EndoMulScalar: 11562,
  Xor16: 9792,
  Zero: 4896
}

static # of bytes: 407
max dynamic # of bytes: 430
static # of blocks: 7
max dynamic # of blocks: 7
constraint overhead for dynamic: 8.10%

@mitschabaude mitschabaude merged commit f624aba into main Oct 29, 2024
2 checks passed
@mitschabaude mitschabaude deleted the feature/dynamic-bytes branch October 29, 2024 12:10
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.

Dynamic SHA256
1 participant