-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is mostly just removing a bunch of async/await stuff as we convert the final 3 functions in abis.ts to use `foundation/crypto/pedersen`. There are two things that are iffy, but not sure if that should block a merge as everything passes: * `vkHash`, I've hardcoded a couple of values I don't fully understand (coset generator and root, which are pulled from evalutation domain in the C++). * `computePublicCallStackItemHash` the C++ did something funky when `isExecutionRequest` is true. I don't fully understand what and if it needs reproducing here, but again, everything passes. Have left the commented C++ code in the two places above for reference.
- Loading branch information
1 parent
48d8c7f
commit 6307e12
Showing
121 changed files
with
1,888 additions
and
930 deletions.
There are no files selected for viewing
25 changes: 14 additions & 11 deletions
25
barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#include "c_bind.hpp" | ||
#include "aes128.hpp" | ||
#include "barretenberg/common/wasm_export.hpp" | ||
#include "barretenberg/common/serialize.hpp" | ||
|
||
WASM_EXPORT void aes__encrypt_buffer_cbc(uint8_t* in, uint8_t* iv, const uint8_t* key, const size_t length, uint8_t* r) | ||
WASM_EXPORT void aes_encrypt_buffer_cbc( | ||
uint8_t const* in, uint8_t const* iv, uint8_t const* key, uint32_t const* length, uint8_t** r) | ||
{ | ||
crypto::aes128::encrypt_buffer_cbc(in, iv, key, length); | ||
for (size_t i = 0; i < length; ++i) { | ||
r[i] = in[i]; | ||
} | ||
auto len = ntohl(*length); | ||
crypto::aes128::encrypt_buffer_cbc((uint8_t*)in, (uint8_t*)iv, key, len); | ||
std::vector<uint8_t> result(in, in + len); | ||
*r = to_heap_buffer(result); | ||
} | ||
|
||
WASM_EXPORT void aes__decrypt_buffer_cbc(uint8_t* in, uint8_t* iv, const uint8_t* key, const size_t length, uint8_t* r) | ||
WASM_EXPORT void aes_decrypt_buffer_cbc( | ||
uint8_t const* in, uint8_t const* iv, uint8_t const* key, uint32_t const* length, uint8_t** r) | ||
{ | ||
crypto::aes128::decrypt_buffer_cbc(in, iv, key, length); | ||
for (size_t i = 0; i < length; ++i) { | ||
r[i] = in[i]; | ||
} | ||
auto len = ntohl(*length); | ||
crypto::aes128::decrypt_buffer_cbc((uint8_t*)in, (uint8_t*)iv, key, len); | ||
std::vector<uint8_t> result(in, in + len); | ||
*r = to_heap_buffer(result); | ||
} |
11 changes: 11 additions & 0 deletions
11
barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
#include <barretenberg/common/serialize.hpp> | ||
#include <barretenberg/common/wasm_export.hpp> | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
WASM_EXPORT void aes_encrypt_buffer_cbc( | ||
uint8_t const* input, uint8_t const* iv, uint8_t const* key, uint32_t const* length, uint8_t** r); | ||
|
||
WASM_EXPORT void aes_decrypt_buffer_cbc( | ||
uint8_t const* input, uint8_t const* iv, uint8_t const* key, uint32_t const* length, uint8_t** r); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
barretenberg/ts/src/barretenberg/__snapshots__/pedersen.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`pedersen sync pedersenCommit 1`] = ` | ||
Point { | ||
"x": Fr { | ||
"value": Uint8Array [ | ||
40, | ||
159, | ||
125, | ||
144, | ||
234, | ||
153, | ||
219, | ||
166, | ||
76, | ||
75, | ||
47, | ||
51, | ||
253, | ||
27, | ||
9, | ||
101, | ||
2, | ||
145, | ||
223, | ||
38, | ||
43, | ||
114, | ||
5, | ||
21, | ||
90, | ||
97, | ||
2, | ||
6, | ||
219, | ||
97, | ||
109, | ||
152, | ||
], | ||
}, | ||
"y": Fr { | ||
"value": Uint8Array [ | ||
5, | ||
175, | ||
199, | ||
200, | ||
35, | ||
67, | ||
88, | ||
76, | ||
19, | ||
203, | ||
45, | ||
50, | ||
137, | ||
153, | ||
67, | ||
200, | ||
57, | ||
87, | ||
22, | ||
209, | ||
141, | ||
173, | ||
205, | ||
189, | ||
23, | ||
215, | ||
206, | ||
3, | ||
174, | ||
112, | ||
128, | ||
11, | ||
], | ||
}, | ||
} | ||
`; | ||
|
||
exports[`pedersen sync pedersenHash 1`] = ` | ||
Fr { | ||
"value": Uint8Array [ | ||
4, | ||
194, | ||
53, | ||
42, | ||
6, | ||
13, | ||
74, | ||
193, | ||
205, | ||
251, | ||
96, | ||
62, | ||
188, | ||
67, | ||
39, | ||
181, | ||
118, | ||
69, | ||
151, | ||
35, | ||
22, | ||
20, | ||
246, | ||
29, | ||
36, | ||
91, | ||
243, | ||
87, | ||
114, | ||
192, | ||
134, | ||
150, | ||
], | ||
} | ||
`; | ||
|
||
exports[`pedersen sync pedersenHashBuffer 1`] = ` | ||
Fr { | ||
"value": Uint8Array [ | ||
43, | ||
213, | ||
196, | ||
82, | ||
160, | ||
201, | ||
113, | ||
98, | ||
41, | ||
79, | ||
201, | ||
223, | ||
208, | ||
241, | ||
224, | ||
157, | ||
14, | ||
9, | ||
201, | ||
95, | ||
165, | ||
237, | ||
63, | ||
241, | ||
73, | ||
251, | ||
222, | ||
243, | ||
102, | ||
203, | ||
81, | ||
249, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Barretenberg, BarretenbergSync } from './index.js'; | ||
import { Buffer32, Fr } from '../types/index.js'; | ||
|
||
describe('blake2s async', () => { | ||
let api: Barretenberg; | ||
|
||
beforeAll(async () => { | ||
api = await Barretenberg.new(1); | ||
}); | ||
|
||
afterAll(async () => { | ||
await api.destroy(); | ||
}); | ||
|
||
it('blake2s', async () => { | ||
const input = Buffer.from('abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789'); | ||
const expected = Buffer32.fromBuffer( | ||
new Uint8Array([ | ||
0x44, 0xdd, 0xdb, 0x39, 0xbd, 0xb2, 0xaf, 0x80, 0xc1, 0x47, 0x89, 0x4c, 0x1d, 0x75, 0x6a, 0xda, 0x3d, 0x1c, | ||
0x2a, 0xc2, 0xb1, 0x00, 0x54, 0x1e, 0x04, 0xfe, 0x87, 0xb4, 0xa5, 0x9e, 0x12, 0x43, | ||
]), | ||
); | ||
const result = await api.blake2s(input); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('blake2sToField', async () => { | ||
const input = Buffer.from('abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789'); | ||
const expected = Fr.fromBufferReduce( | ||
new Uint8Array([ | ||
0x44, 0xdd, 0xdb, 0x39, 0xbd, 0xb2, 0xaf, 0x80, 0xc1, 0x47, 0x89, 0x4c, 0x1d, 0x75, 0x6a, 0xda, 0x3d, 0x1c, | ||
0x2a, 0xc2, 0xb1, 0x00, 0x54, 0x1e, 0x04, 0xfe, 0x87, 0xb4, 0xa5, 0x9e, 0x12, 0x43, | ||
]), | ||
); | ||
const result = await api.blake2sToField(input); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('blake2s sync', () => { | ||
let api: BarretenbergSync; | ||
|
||
beforeAll(async () => { | ||
api = await BarretenbergSync.new(); | ||
}); | ||
|
||
it('blake2s', () => { | ||
const input = Buffer.from('abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789'); | ||
const expected = Buffer32.fromBuffer( | ||
new Uint8Array([ | ||
0x44, 0xdd, 0xdb, 0x39, 0xbd, 0xb2, 0xaf, 0x80, 0xc1, 0x47, 0x89, 0x4c, 0x1d, 0x75, 0x6a, 0xda, 0x3d, 0x1c, | ||
0x2a, 0xc2, 0xb1, 0x00, 0x54, 0x1e, 0x04, 0xfe, 0x87, 0xb4, 0xa5, 0x9e, 0x12, 0x43, | ||
]), | ||
); | ||
const result = api.blake2s(input); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('blake2sToField', () => { | ||
const input = Buffer.from('abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789'); | ||
const expected = Fr.fromBufferReduce( | ||
new Uint8Array([ | ||
0x44, 0xdd, 0xdb, 0x39, 0xbd, 0xb2, 0xaf, 0x80, 0xc1, 0x47, 0x89, 0x4c, 0x1d, 0x75, 0x6a, 0xda, 0x3d, 0x1c, | ||
0x2a, 0xc2, 0xb1, 0x00, 0x54, 0x1e, 0x04, 0xfe, 0x87, 0xb4, 0xa5, 0x9e, 0x12, 0x43, | ||
]), | ||
); | ||
const result = api.blake2sToField(input); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.