Skip to content

Commit 3b1a5c7

Browse files
committed
feat: partial sha256 & Noir beta 11
1 parent 5430a49 commit 3b1a5c7

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
toolchain: [1.0.0-beta.4, 1.0.0-beta.10]
15+
toolchain: [1.0.0-beta.11]
1616
steps:
1717
- name: Checkout sources
1818
uses: actions/checkout@v4
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install Nargo
3535
uses: noir-lang/[email protected]
3636
with:
37-
toolchain: 1.0.0-beta.10
37+
toolchain: 1.0.0-beta.11
3838

3939
- name: Run formatter
4040
run: nargo fmt --check

Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ keywords = ["Noir", "nodash", "util", "hash"]
88

99

1010
[dependencies]
11-
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
11+
sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" }
1212
keccak256 = { tag = "v0.1.1", git = "https://github.com/noir-lang/keccak256" }
1313
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Nodash is a utility library for [Noir](https://github.com/noir-lang/noir) langua
77
Put this into your Nargo.toml.
88

99
```toml
10-
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.41.3" }
10+
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.42.0" }
1111
```
1212

1313
## Docs
@@ -93,6 +93,10 @@ let hash = keccak256([10, 20]);
9393
let hash = keccak256(BoundedVec::from_parts([10, 20, 0], 2));
9494
```
9595

96+
#### Partial SHA256
97+
98+
Similar to partial [`sha256`](https://github.com/noir-lang/sha256) but supports `BoundedVec<u8, N>` and `[u8; N]` as input.
99+
96100
### `solidity::encode_with_selector`
97101

98102
Equivalent to `abi.encodeWithSelector` in Solidity.

src/hash.nr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ pub fn sha256<let N: u32>(input: impl ArrayOrBoundedVec<u8, N>) -> [u8; 32] {
1313
dep::sha256::sha256_var(input.storage(), input.len() as u64)
1414
}
1515

16+
pub fn partial_sha256_interstitial<let N: u32>(
17+
mut h: [u32; 8],
18+
input: impl ArrayOrBoundedVec<u8, N>,
19+
) -> [u32; 8] {
20+
let input = input.as_bounded_vec();
21+
dep::sha256::partial_sha256_var_interstitial(h, input.storage(), input.len())
22+
}
23+
24+
pub fn partial_sha256_end<let N: u32>(
25+
mut h: [u32; 8],
26+
partial_input: impl ArrayOrBoundedVec<u8, N>,
27+
full_input_len: u32,
28+
) -> [u8; 32] {
29+
let partial_input = partial_input.as_bounded_vec();
30+
dep::sha256::partial_sha256_var_end(
31+
h,
32+
partial_input.storage(),
33+
partial_input.len(),
34+
full_input_len,
35+
)
36+
}
37+
1638
pub fn keccak256<let N: u32>(input: impl ArrayOrBoundedVec<u8, N>) -> [u8; 32] {
1739
let input = input.as_bounded_vec();
1840
dep::keccak256::keccak256(input.storage(), input.len())

0 commit comments

Comments
 (0)