Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 25, 2024
1 parent 1a97698 commit cda6230
Show file tree
Hide file tree
Showing 51 changed files with 299 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct CustomNote {
}
```

### After expansaion
### After expansion

```rust
impl CustomNote {
Expand Down
1 change: 0 additions & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ library Constants {
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 16;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 16;
uint256 internal constant MAX_ARGS_LENGTH = 256;
uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000000000;
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 20000;
Expand Down
44 changes: 28 additions & 16 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ impl<let M: u32> EncryptedLogIncomingBody<M> {
}

mod test {
use crate::encrypted_logs::incoming_body::EncryptedLogIncomingBody;
use dep::protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
scalar::Scalar, point::Point, traits::Serialize, abis::event_selector::EventSelector
scalar::Scalar, point::Point, traits::Serialize, generators::Ga1,
abis::event_selector::EventSelector
};

use crate::{
note::{note_header::NoteHeader, note_interface::NoteInterface},
event::event_interface::EventInterface, oracle::unsafe_rand::unsafe_rand,
context::PrivateContext
encrypted_logs::incoming_body::EncryptedLogIncomingBody, event::event_interface::EventInterface,
oracle::unsafe_rand::unsafe_rand, context::PrivateContext, utils::point::point_to_bytes
};

struct AddressNote {
Expand All @@ -60,7 +60,9 @@ mod test {
global ADDRESS_NOTE_BYTES_LEN = 32 * 3 + 64;

impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
fn compute_note_content_hash(_self: Self) -> Field {1}
fn compute_note_content_hash(self) -> Point {
Ga1
}

fn get_note_type_id() -> Field {
1
Expand Down Expand Up @@ -112,7 +114,8 @@ mod test {
}

#[test]
fn test_encrypted_note_log_incoming_body() {
fn test_encrypted_note_log_incoming_body_matches_typescript() {
// All the values in this test were copied over from `encrypted_note_log_incoming_body.test.ts`
let note = AddressNote::new(
AztecAddress::from_field(0x1),
AztecAddress::from_field(0x2),
Expand All @@ -131,18 +134,25 @@ mod test {
is_infinite: false
};

/// 1. `EncryptedLogIncomingBody::from_note` calls `note.to_be_bytes(storage_slot)` function which serializes
/// the note to bytes - note that in the case of `AddressNote` the `to_be_bytes` function was automatically
/// implemented by Aztec macros.
let body = EncryptedLogIncomingBody::from_note(note, storage_slot);

/// 2. `body.compute_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
// the note plaintext using AES-128.
let ciphertext = body.compute_ciphertext(eph_sk, ivpk);

let expected_note_body_ciphertext = [
166, 212, 106, 246, 139, 59, 228, 9, 133, 152, 127, 172, 141, 166, 237, 199, 195, 85, 255, 81, 66, 72, 192, 192, 96, 10, 54, 139, 136, 153, 252, 114, 248, 128, 253, 66, 249, 16, 71, 45, 2, 213, 250, 193, 241, 75, 90, 70, 39, 26, 104, 139, 20, 45, 1, 1, 166, 72, 133, 55, 247, 142, 150, 215, 217, 224, 84, 23, 245, 71, 207, 166, 136, 34, 221, 76, 90, 166, 44, 217, 246, 98, 157, 34, 198, 164, 99, 117, 15, 185, 145, 231, 189, 140, 201, 241, 135, 94, 71, 131, 156, 86, 144, 131, 248, 242, 83, 101, 18, 189, 1, 94, 25, 238, 76, 106, 85, 205, 4, 70, 21, 9, 64, 63, 27, 164, 73, 181, 75, 199, 86, 255, 105, 239, 216, 34, 217, 184, 154, 76, 67, 1, 210, 251, 23, 185, 114, 146, 195, 28, 76, 219, 150, 175, 37, 76, 144, 227, 99, 243, 123, 161, 66, 171, 148, 181, 162, 2, 196, 53, 207, 154, 114, 166, 155, 166
// The following value was generated by `encrypted_note_log_incoming_body.test.ts`.
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let note_body_ciphertext_from_typescript = [
75, 3, 86, 165, 50, 163, 229, 200, 67, 137, 31, 92, 122, 27, 14, 158, 201, 248, 29, 236, 102, 216, 246, 64, 166, 1, 166, 221, 92, 19, 78, 19, 213, 197, 44, 130, 105, 145, 239, 139, 176, 255, 148, 41, 72, 212, 75, 176, 216, 99, 170, 9, 151, 25, 135, 140, 53, 123, 253, 52, 119, 14, 65, 131, 127, 177, 227, 219, 157, 38, 90, 161, 32, 7, 27, 138, 152, 196, 60, 240, 106, 73, 121, 227, 190, 14, 142, 61, 119, 47, 201, 29, 250, 68, 53, 62, 200, 33, 207, 190, 156, 84, 9, 115, 122, 14, 147, 171, 83, 111, 2, 140, 9, 33, 33, 30, 65, 242, 133, 134, 59, 254, 202, 2, 237, 246, 68, 153, 62, 237, 123, 90, 169, 84, 62, 55, 214, 102, 26, 79, 209, 175, 255, 223, 110, 6, 119, 61, 142, 36, 81, 155, 0, 178, 60, 85, 120, 152, 177, 115, 14, 62, 105, 42, 178, 231, 173, 245, 88, 245, 89, 122, 32, 49, 205, 151
];

assert_eq(expected_note_body_ciphertext.len(), ciphertext.len());
assert_eq(note_body_ciphertext_from_typescript.len(), ciphertext.len());

for i in 0..expected_note_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_note_body_ciphertext[i]);
for i in 0..note_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], note_body_ciphertext_from_typescript[i]);
}
}

Expand Down Expand Up @@ -237,14 +247,16 @@ mod test {

let ciphertext = body.compute_ciphertext(eph_sk, ivpk);

let expected_event_body_ciphertext = [
166, 212, 106, 246, 139, 59, 228, 9, 133, 152, 127, 172, 141, 166, 237, 199, 195, 85, 255, 81, 66, 72, 192, 192, 96, 10, 54, 139, 136, 153, 252, 114, 248, 128, 253, 66, 249, 16, 71, 45, 2, 213, 250, 193, 241, 75, 90, 70, 19, 153, 62, 117, 71, 55, 48, 114, 160, 232, 97, 118, 93, 53, 145, 92, 0, 225, 51, 81, 156, 69, 72, 224, 10, 89, 32, 121, 167, 197, 84, 245, 188, 235, 143, 202, 179, 197, 164, 121, 11, 105, 116, 239, 46, 222, 50, 138, 112, 237, 97, 8, 176, 199, 1, 151, 89, 218, 60, 45, 91, 85, 16, 38, 195, 127, 157, 182, 0, 10, 232, 184, 148, 76, 244, 63, 40, 222, 219, 139, 236, 169, 213, 17, 32, 210, 50, 6, 5, 83, 80, 1, 111, 246, 197, 83, 166, 71, 31, 246, 234, 75, 12, 151, 227, 247, 143, 229, 95, 219, 159, 75, 174, 232, 64, 7, 102, 76, 207, 45, 143, 208, 101, 113, 175, 37, 83, 166
// The following value was generated by `encrypted_event_log_incoming_body.test.ts`
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let event_body_ciphertext_from_typescript = [
226, 240, 253, 6, 28, 52, 19, 131, 33, 132, 178, 212, 245, 62, 14, 190, 147, 228, 160, 190, 146, 61, 95, 203, 124, 153, 68, 168, 17, 150, 92, 0, 99, 214, 85, 64, 191, 78, 157, 131, 149, 96, 236, 253, 96, 172, 157, 30, 185, 29, 14, 152, 216, 130, 219, 151, 80, 185, 43, 223, 167, 8, 89, 189, 88, 188, 101, 137, 255, 136, 84, 252, 79, 18, 52, 3, 110, 54, 54, 206, 244, 209, 246, 226, 207, 247, 143, 253, 211, 75, 160, 224, 172, 41, 45, 7, 208, 137, 90, 56, 59, 4, 234, 48, 53, 23, 130, 230, 49, 249, 142, 243, 170, 72, 183, 242, 49, 124, 46, 52, 198, 75, 55, 102, 56, 89, 254, 67, 59, 157, 249, 120, 184, 67, 154, 16, 148, 227, 93, 37, 120, 199, 93, 166, 80, 127, 173, 52, 80, 135, 87, 1, 168, 164, 51, 48, 126, 120, 47, 102, 211, 227, 234, 170, 208, 99, 111, 198, 170, 226, 156, 244, 241, 174, 206, 30
];

assert_eq(expected_event_body_ciphertext.len(), ciphertext.len());
assert_eq(event_body_ciphertext_from_typescript.len(), ciphertext.len());

for i in 0..expected_event_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_event_body_ciphertext[i]);
for i in 0..event_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], event_body_ciphertext_from_typescript[i]);
}
}
}
16 changes: 10 additions & 6 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ impl EncryptedLogOutgoingBody {
Self { eph_sk, recipient, recipient_ivpk }
}

/// Encrypts ephemeral secret key and recipient's ivpk --> with this information the recipient of outgoing will
/// be able to derive the key with which the incoming log can be decrypted.
pub fn compute_ciphertext(self, ovsk_app: Scalar, eph_pk: Point) -> [u8; 144] {
// Again, we could compute `eph_pk` here, but we keep the interface more similar
// and also make it easier to optimise it later as we just pass it along
Expand Down Expand Up @@ -68,7 +70,7 @@ mod test {
use crate::context::PrivateContext;

#[test]
fn test_encrypted_log_outgoing_body() {
fn test_encrypted_log_outgoing_body_matches_typescript() {
let eph_sk = Scalar {
lo: 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe,
hi: 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb
Expand All @@ -91,13 +93,15 @@ mod test {

let ciphertext = body.compute_ciphertext(sender_ovsk_app, eph_pk);

let expected_outgoing_body_ciphertext = [
127, 84, 96, 176, 101, 107, 236, 57, 68, 8, 53, 202, 138, 74, 186, 54, 74, 193, 245, 7, 109, 59, 218, 33, 1, 31, 205, 225, 241, 209, 64, 222, 94, 245, 4, 150, 47, 241, 187, 64, 152, 20, 102, 158, 200, 217, 213, 82, 1, 240, 170, 185, 51, 80, 27, 109, 63, 231, 235, 120, 174, 44, 133, 248, 10, 97, 60, 40, 222, 190, 147, 76, 187, 48, 91, 206, 48, 106, 56, 118, 38, 127, 82, 4, 182, 188, 44, 224, 31, 129, 47, 107, 134, 252, 20, 25, 249, 193, 215, 137, 195, 43, 98, 42, 54, 96, 254, 89, 134, 31, 103, 142, 16, 43, 92, 211, 145, 113, 217, 253, 161, 240, 121, 205, 146, 200, 168, 160, 221, 32, 229, 116, 26, 216, 86, 189, 78, 120, 10, 224, 85, 52, 40, 244
// The following value was generated by `encrypted_log_outgoing_body.test.ts`
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let outgoing_body_ciphertext_from_typescript = [
126, 10, 214, 39, 130, 143, 96, 143, 79, 143, 22, 36, 55, 41, 234, 255, 226, 26, 138, 236, 91, 188, 204, 216, 172, 133, 134, 69, 161, 237, 134, 5, 75, 192, 10, 6, 229, 54, 194, 56, 103, 243, 57, 248, 147, 237, 4, 3, 39, 28, 226, 30, 237, 228, 212, 115, 246, 244, 105, 39, 129, 119, 126, 207, 176, 14, 75, 134, 241, 23, 2, 187, 239, 86, 47, 56, 239, 20, 92, 176, 70, 12, 219, 226, 150, 70, 192, 43, 125, 53, 230, 153, 135, 228, 210, 197, 227, 106, 242, 138, 119, 83, 182, 150, 233, 111, 9, 104, 128, 222, 85, 136, 205, 244, 77, 230, 210, 217, 223, 106, 220, 4, 115, 33, 157, 212, 217, 133, 87, 179, 67, 158, 81, 85, 226, 105, 22, 8, 154, 130, 193, 214, 144, 212
];

for i in 0..expected_outgoing_body_ciphertext.len() {
assert_eq(ciphertext[i], expected_outgoing_body_ciphertext[i]);
for i in 0..outgoing_body_ciphertext_from_typescript.len() {
assert_eq(ciphertext[i], outgoing_body_ciphertext_from_typescript[i]);
}
assert_eq(expected_outgoing_body_ciphertext.len(), ciphertext.len());
assert_eq(outgoing_body_ciphertext_from_typescript.len(), ciphertext.len());
}
}
18 changes: 12 additions & 6 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub fn compute_encrypted_note_log<Note, let N: u32, let NB: u32, let M: u32>(

/// Converts a base field elememt to scalar field element.
/// This is fine because modulus of the base field is smaller than the modulus of the scalar field.
/// TODO(#7551): Replace the contents of this function with decompose and move the function to scalar.nr
/// - in plenty of the places we then convert the outputs of decompose(...) to Scalar struct so having
// this as a utility function would be useful.
fn fr_to_fq(r: Field) -> Scalar {
let r_bytes = r.to_be_bytes(32);

Expand All @@ -147,7 +150,8 @@ mod test {
use std::test::OracleMock;

#[test]
fn test_compute_encrypted_note_log() {
fn test_encrypted_note_log_matches_typescript() {
// All the values in this test were copied over from `tagged_log.test.ts`
let contract_address = AztecAddress::from_field(0x10f48cd9eff7ae5b209c557c70de2e657ee79166868676b787e9417e19260e04);
let storage_slot = 0x0fe46be583b71f4ab5b70c2657ff1d05cccf1d292a9369628d1a194f944e6599;
let ovsk_app = 0x1b99ba138fa7ef8a2f122a98dd80c8ee70d447218dd780f45e165ac17ca38a5e;
Expand Down Expand Up @@ -180,12 +184,14 @@ mod test {
note
);

let expected_encrypted_note_log = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 141, 70, 12, 14, 67, 77, 132, 110, 193, 234, 40, 110, 64, 144, 235, 86, 55, 111, 242, 123, 221, 193, 170, 202, 225, 216, 86, 84, 159, 112, 31, 167, 159, 53, 114, 117, 237, 57, 131, 19, 111, 150, 50, 83, 173, 155, 234, 225, 71, 187, 141, 79, 245, 43, 111, 83, 219, 149, 124, 68, 12, 244, 253, 216, 0, 62, 108, 232, 118, 80, 87, 140, 215, 185, 111, 48, 128, 236, 110, 92, 46, 205, 7, 226, 131, 66, 205, 0, 103, 83, 217, 90, 60, 138, 6, 172, 246, 129, 92, 172, 69, 73, 77, 65, 147, 18, 231, 20, 35, 217, 180, 253, 72, 242, 32, 57, 45, 11, 2, 235, 24, 96, 244, 224, 33, 61, 151, 225, 136, 173, 178, 40, 2, 125, 229, 20, 220, 82, 28, 191, 147, 133, 137, 1, 45, 243, 229, 140, 115, 165, 150, 154, 96, 22, 120, 223, 237, 213, 182, 252, 192, 8, 132, 43, 21, 56, 243, 116, 144, 182, 75, 16, 30, 222, 222, 60, 205, 147, 214, 53, 41, 62, 53, 16, 147, 117, 72, 169, 220, 125, 208, 210, 45, 65, 233, 40, 87, 88, 140, 237, 200, 161, 9, 86, 82, 128, 191, 51, 4, 195, 243, 100, 102, 240, 54, 129, 176, 116, 139, 73, 27, 98, 222, 1, 243, 199, 72, 238, 213, 66, 91, 159, 183, 143, 36, 103, 94, 5, 62, 50, 13, 217, 161, 79, 30, 231, 41, 228, 109, 139, 243, 119, 166, 54, 37, 250, 193, 6, 67, 29, 148, 185, 153, 58, 64, 210, 164, 219, 165, 80, 35, 75, 109, 177, 14, 168, 136, 105, 21, 235, 62, 159, 71, 61, 245, 193, 234, 169, 100, 165, 8, 222, 157, 239, 41, 221, 223, 67, 80, 61, 252, 54, 27, 100, 1, 104, 2, 121, 62, 41, 23, 132, 15, 124, 120, 21, 198, 113, 151, 172, 42, 161, 64, 240, 166, 205, 80, 169, 58, 191, 111, 130, 55, 58, 141, 26, 97, 118, 114, 216, 69, 207, 212, 227, 250, 199, 21, 72, 144, 85, 43, 76, 213, 28, 132, 134, 16, 221, 105, 112, 82, 238, 114, 61, 36, 144, 179, 178, 68, 198, 162, 212, 85, 100, 116, 186, 131, 232, 33, 229, 101, 251, 5, 251
// The following value was generated by `tagged_log.test.ts`
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let encrypted_note_log_from_typescript = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 141, 70, 12, 14, 67, 77, 132, 110, 193, 234, 40, 110, 64, 144, 235, 86, 55, 111, 242, 123, 221, 193, 170, 202, 225, 216, 86, 84, 159, 112, 31, 167, 126, 79, 51, 186, 47, 71, 253, 172, 99, 112, 241, 59, 197, 241, 107, 186, 232, 87, 187, 230, 171, 62, 228, 234, 42, 51, 145, 146, 238, 242, 42, 71, 206, 13, 244, 66, 111, 195, 20, 203, 98, 148, 204, 242, 145, 183, 156, 29, 141, 54, 44, 220, 194, 35, 229, 16, 32, 204, 211, 49, 142, 112, 82, 202, 116, 241, 254, 146, 42, 217, 20, 189, 70, 228, 182, 171, 205, 104, 27, 99, 171, 28, 91, 244, 21, 30, 130, 240, 5, 72, 174, 124, 97, 197, 157, 248, 204, 203, 140, 171, 181, 152, 130, 169, 179, 41, 52, 173, 45, 43, 198, 1, 152, 72, 158, 249, 11, 41, 9, 160, 48, 78, 123, 132, 203, 140, 215, 13, 22, 201, 88, 255, 139, 154, 76, 20, 63, 134, 125, 108, 239, 208, 63, 59, 33, 117, 139, 225, 184, 0, 64, 153, 21, 131, 204, 111, 41, 84, 23, 144, 222, 245, 200, 12, 234, 11, 48, 10, 221, 20, 252, 38, 122, 40, 249, 66, 248, 197, 198, 209, 79, 20, 59, 66, 197, 215, 16, 18, 145, 228, 239, 124, 81, 67, 103, 49, 196, 58, 228, 195, 64, 199, 243, 184, 112, 173, 29, 196, 215, 77, 217, 85, 82, 149, 113, 76, 201, 93, 95, 148, 37, 95, 222, 233, 210, 150, 1, 182, 28, 132, 59, 148, 156, 129, 36, 230, 55, 199, 149, 36, 88, 50, 143, 204, 153, 32, 104, 29, 137, 19, 31, 178, 137, 117, 157, 20, 8, 128, 230, 250, 75, 44, 54, 128, 2, 241, 208, 153, 7, 214, 252, 57, 152, 75, 69, 57, 248, 179, 156, 145, 92, 165, 13, 116, 53, 33, 42, 183, 231, 77, 203, 170, 125, 20, 121, 48, 136, 194, 94, 139, 207, 148, 218, 248, 129, 231, 129, 191, 45, 239, 108, 60, 34, 82, 117, 186, 180, 199, 77, 169, 213, 238, 47, 37, 0, 40, 12, 110, 216, 175, 23, 59, 81, 117, 164, 24, 80, 241, 40, 126, 179, 230, 78, 145, 75, 102, 204, 12, 30, 146, 240, 222
];
for i in 0..expected_encrypted_note_log.len() {
assert_eq(log[i], expected_encrypted_note_log[i]);
for i in 0..encrypted_note_log_from_typescript.len() {
assert_eq(log[i], encrypted_note_log_from_typescript[i]);
}
assert_eq(expected_encrypted_note_log.len(), log.len());
assert_eq(encrypted_note_log_from_typescript.len(), log.len());
}
}
7 changes: 5 additions & 2 deletions noir-projects/aztec-nr/aztec/src/generators.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ use dep::protocol_types::point::Point;
global Ga1 = Point { x: 0x30426e64aee30e998c13c8ceecda3a77807dbead52bc2f3bf0eae851b4b710c1, y: 0x113156a068f603023240c96b4da5474667db3b8711c521c748212a15bc034ea6, is_infinite: false };
global Ga2 = Point { x: 0x2825c79cc6a5cbbeef7d6a8f1b6a12b312aa338440aefeb4396148c89147c049, y: 0x129bfd1da54b7062d6b544e7e36b90736350f6fba01228c41c72099509f5701e, is_infinite: false };
global Ga3 = Point { x: 0x0edb1e293c3ce91bfc04e3ceaa50d2c541fa9d091c72eb403efb1cfa2cb3357f, y: 0x1341d675fa030ece3113ad53ca34fd13b19b6e9762046734f414824c4d6ade35, is_infinite: false };
global G_slot = Point { x: 0x0edb1e293c3ce91bfc04e3ceaa50d2c541fa9d091c72eb403efb1cfa2cb3357f, y: 0x1341d675fa030ece3113ad53ca34fd13b19b6e9762046734f414824c4d6ade35, is_infinite: false };

mod test {
use crate::generators::{Ga1, Ga2, Ga3};
use crate::generators::{Ga1, Ga2, Ga3, G_slot};
use dep::protocol_types::point::Point;
use std::hash::derive_generators;

#[test]
fn test_generators() {
let generators: [Point; 3] = derive_generators("aztec_nr_generators".as_bytes(), 0);
let generators: [Point; 4] = derive_generators("aztec_nr_generators".as_bytes(), 0);
assert_eq(generators[0], Ga1);
assert_eq(generators[1], Ga2);
assert_eq(generators[2], Ga3);
// TODO(benesjan): update this
assert_eq(generators[3], G_slot);
}
}
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/history/public_storage.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ trait PublicStorageHistoricalRead {
impl PublicStorageHistoricalRead for Header {
fn public_storage_historical_read(self, storage_slot: Field, contract_address: AztecAddress) -> Field {
// 1) Compute the leaf slot by siloing the storage slot with the contract address
let public_value_leaf_slot = pedersen_hash(
let public_data_tree_index = pedersen_hash(
[contract_address.to_field(), storage_slot],
GENERATOR_INDEX__PUBLIC_LEAF_INDEX
);

// 2) Get the membership witness of the slot
let witness = get_public_data_witness(
self.global_variables.block_number as u32,
public_value_leaf_slot
public_data_tree_index
);

// 3) Extract the value from the witness leaf and check that the storage slot is correct
Expand All @@ -30,15 +30,15 @@ impl PublicStorageHistoricalRead for Header {
// Here we have two cases. Code based on same checks in `validate_public_data_reads` in `base_rollup_inputs`
// 1. The value is the same as the one in the witness
// 2. The value was never initialized and is zero
let is_less_than_slot = full_field_less_than(preimage.slot, public_value_leaf_slot);
let is_next_greater_than = full_field_less_than(public_value_leaf_slot, preimage.next_slot);
let is_less_than_slot = full_field_less_than(preimage.slot, public_data_tree_index);
let is_next_greater_than = full_field_less_than(public_data_tree_index, preimage.next_slot);
let is_max = ((preimage.next_index == 0) & (preimage.next_slot == 0));
let is_in_range = is_less_than_slot & (is_next_greater_than | is_max);

let value = if is_in_range {
0
} else {
assert_eq(preimage.slot, public_value_leaf_slot, "Public data slot doesn't match witness");
assert_eq(preimage.slot, public_data_tree_index, "Public data tree index doesn't match witness");
preimage.value
};

Expand Down
Loading

0 comments on commit cda6230

Please sign in to comment.