-
Notifications
You must be signed in to change notification settings - Fork 615
Expand file tree
/
Copy pathnote_validation_request.nr
More file actions
64 lines (59 loc) · 3.07 KB
/
Copy pathnote_validation_request.nr
File metadata and controls
64 lines (59 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::messages::logs::note::MAX_NOTE_PACKED_LEN;
use crate::protocol::{address::AztecAddress, traits::{Deserialize, Serialize}};
/// Intermediate struct used to perform batch note validation by PXE. The
/// `aztec_utl_validateAndStoreEnqueuedNotesAndEvents` oracle expects for values of this type to be stored in a
/// `EphemeralArray`.
#[derive(Serialize, Deserialize)]
pub struct NoteValidationRequest {
pub contract_address: AztecAddress,
pub owner: AztecAddress,
pub storage_slot: Field,
pub randomness: Field,
pub note_nonce: Field,
pub packed_note: BoundedVec<Field, MAX_NOTE_PACKED_LEN>,
pub note_hash: Field,
pub nullifier: Field,
pub tx_hash: Field,
}
mod test {
use crate::protocol::{address::AztecAddress, traits::{FromField, Serialize}};
use super::NoteValidationRequest;
#[test]
fn serialization_matches_typescript() {
let request = NoteValidationRequest {
contract_address: AztecAddress::from_field(1),
owner: AztecAddress::from_field(50),
storage_slot: 2,
randomness: 42,
note_nonce: 3,
packed_note: BoundedVec::from_array([4, 5]),
note_hash: 6,
nullifier: 7,
tx_hash: 8,
};
// We define the serialization in Noir and the deserialization in TS. If the deserialization changes from the
// snapshot value below, then note_validation_request.test.ts must be updated with the same value. Ideally we'd
// autogenerate this, but for now we only have single-sided snapshot generation, from TS to Noir, which is not
// what we need here.
let expected_serialization = [
0x0000000000000000000000000000000000000000000000000000000000000001,
0x0000000000000000000000000000000000000000000000000000000000000032,
0x0000000000000000000000000000000000000000000000000000000000000002,
0x000000000000000000000000000000000000000000000000000000000000002a,
0x0000000000000000000000000000000000000000000000000000000000000003,
0x0000000000000000000000000000000000000000000000000000000000000004,
0x0000000000000000000000000000000000000000000000000000000000000005,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000002,
0x0000000000000000000000000000000000000000000000000000000000000006,
0x0000000000000000000000000000000000000000000000000000000000000007,
0x0000000000000000000000000000000000000000000000000000000000000008,
];
assert_eq(request.serialize(), expected_serialization);
}
}