Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Dec 7, 2024
1 parent 3609555 commit f6c3c47
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 158 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/cheatcodes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
C: CallInterface<M>,
{
let target = call_interface.get_contract_address();
let inputs = cheatcodes::get_private_context_inputs(get_block_number());
let inputs = cheatcodes::get_private_context_inputs(get_block_number() - 1);
let chain_id = inputs.tx_context.chain_id;
let version = inputs.tx_context.version;
let args_hash = hash_args(call_interface.get_args());
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/aztec/src/initializer.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::{
pub fn mark_as_initialized_public(context: &mut PublicContext) {
let init_nullifier =
compute_unsiloed_contract_initialization_nullifier((*context).this_address());
std::println("INIT_NULLIFIER");
std::println(init_nullifier);
context.push_nullifier(init_nullifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ contract Auth {
#[initializer]
fn constructor(admin: AztecAddress) {
assert(!admin.is_zero(), "invalid admin");
std::println("CONTRACT ADDRESS");
std::println(context.this_address());
storage.admin.initialize(admin);
}

Expand Down
326 changes: 208 additions & 118 deletions noir-projects/noir-contracts/contracts/auth_contract/src/test/main.nr

Large diffs are not rendered by default.

48 changes: 18 additions & 30 deletions noir-projects/noir-contracts/contracts/counter_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ contract Counter {

// docs:end:get_counter
// docs:start:test_imports
use dep::aztec::note::lifecycle::destroy_note;
use dep::aztec::note::note_getter::{MAX_NOTES_PER_PAGE, view_notes};
use dep::aztec::note::note_viewer_options::NoteViewerOptions;
use dep::aztec::note::lifecycle::destroy_note;

use dep::aztec::protocol_types::debug_log::debug_log_format;
use dep::aztec::protocol_types::storage::map::derive_storage_slot_in_map;
use dep::aztec::test::helpers::{cheatcodes, test_environment::TestEnvironment};
use dep::aztec::protocol_types::debug_log::debug_log_format;

// docs:end:test_imports
// docs:start:txe_test_increment
Expand Down Expand Up @@ -147,7 +147,6 @@ contract Counter {
}
// docs:end:txe_test_increment


#[test]
unconstrained fn increment_test_abc() {
// Setup env, generate keys
Expand Down Expand Up @@ -225,7 +224,7 @@ contract Counter {
let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
}

#[test]
#[test]
unconstrained fn increment_test() {
// Setup env, generate keys
let mut env = TestEnvironment::new();
Expand Down Expand Up @@ -265,49 +264,38 @@ contract Counter {
Counter::at(contract_address).increment_two(owner, outgoing_viewer).call(&mut env.private());

let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
assert(
notes.len() == 3
);
assert(notes.len() == 3);
assert(get_counter(owner) == 7);

env.advance_block_by(1);
let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
assert(get_counter(owner) == 7);
assert(
notes.len() == 3
);
assert(notes.len() == 3);

Counter::at(contract_address).increment_three(owner, outgoing_viewer).call(&mut env.private());
Counter::at(contract_address).increment_three(owner, outgoing_viewer).call(
&mut env.private(),
);
let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
assert(get_counter(owner) == 7);
assert(
notes.len() == 4
);
assert(notes.len() == 4);

env.advance_block_by(1);

let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
std::println("COUNT");
std::println((get_counter(owner)));

assert(notes.len() == 4);
assert(get_counter(owner) == 7);
assert(
notes.len() == 4
);

Counter::at(contract_address).decrement_three(owner, outgoing_viewer).call(&mut env.private());
assert(
notes.len() == 4
Counter::at(contract_address).decrement_three(owner, outgoing_viewer).call(
&mut env.private(),
);
std::println("COUNT");
std::println((get_counter(owner)));

// assert(get_counter(owner) == 8);
let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
assert(get_counter(owner) == 11);
assert(notes.len() == 5);

env.advance_block_by(1);
std::println("COUNT");
std::println((get_counter(owner)));
// assert(get_counter(owner) == 6);
let notes: BoundedVec<ValueNote, MAX_NOTES_PER_PAGE> = view_notes(owner_slot, options);
assert(get_counter(owner) == 6);
assert(notes.len() == 4);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unconstrained fn test_check_block_number() {
let router_contract_address = router_contract.to_address();
let router = Router::at(router_contract_address);

env.advance_block_by(9);
env.advance_block_by(8);

// First we sanity-check that current block number is as expected
let current_block_number = env.block_number();
Expand All @@ -28,7 +28,7 @@ unconstrained fn test_fail_check_block_number() {
let router_contract_address = router_contract.to_address();
let router = Router::at(router_contract_address);

env.advance_block_by(9);
env.advance_block_by(8);

// First we sanity-check that current block number is as expected
let current_block_number = env.block_number();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ unconstrained fn burn_private_on_behalf_of_other() {
let (env, token_contract_address, owner, recipient, mint_amount) =
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
let burn_amount = mint_amount / 10;
env.advance_block_by(1);

// Burn on behalf of other
let burn_call_interface =
Expand All @@ -30,6 +31,8 @@ unconstrained fn burn_private_on_behalf_of_other() {
);
// Impersonate recipient to perform the call
env.impersonate(recipient);
env.advance_block_by(1);

// Burn tokens
burn_call_interface.call(&mut env.private());
utils::check_private_balance(token_contract_address, owner, mint_amount - burn_amount);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ export class TXE implements TypedOracle {
new Fr(blockNumber + 6969),
...this.noteCache.getAllNullifiers(),
...this.manuallyCreatedNullifiers,
...this.siloedNullifiersFromPublic,
];
txEffect.publicDataWrites = this.publicDataWrites;

Expand Down Expand Up @@ -867,7 +868,7 @@ export class TXE implements TypedOracle {

const simulator = new PublicTxSimulator(
db,
new TXEWorldStateDB(db, new TXEPublicContractDataSource(this)),
new TXEWorldStateDB(db, new TXEPublicContractDataSource(this), this),
new NoopTelemetryClient(),
globalVariables,
/*realAvmProvingRequests=*/ false,
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class TXEService {
startStorageSlot: ForeignCallSingle,
values: ForeignCallArray,
) {
console.log('CALLING STORAGE WRITE');
const startStorageSlotFr = fromSingle(startStorageSlot);
const valuesFr = fromArray(values);
const contractAddressFr = addressFromSingle(contractAddress);
Expand Down Expand Up @@ -319,6 +320,7 @@ export class TXEService {
}

async storageWrite(startStorageSlot: ForeignCallSingle, values: ForeignCallArray) {
console.log('CALLING STORAGE WRITE');
const newValues = await this.typedOracle.storageWrite(fromSingle(startStorageSlot), fromArray(values));
return toForeignCallResult([toArray(newValues)]);
}
Expand Down Expand Up @@ -601,6 +603,7 @@ export class TXEService {
}

async avmOpcodeStorageWrite(slot: ForeignCallSingle, value: ForeignCallSingle) {
console.log('CALLING STORAGE WRITE');
await this.typedOracle.storageWrite(fromSingle(slot), [fromSingle(value)]);
return toForeignCallResult([]);
}
Expand Down
15 changes: 9 additions & 6 deletions yarn-project/txe/src/util/txe_world_state_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
Fr,
PublicDataTreeLeaf,
type PublicDataTreeLeafPreimage,
PublicDataWrite,
} from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
import { WorldStateDB } from '@aztec/simulator';
import { TXE } from '../oracle/txe_oracle.js';

export class TXEWorldStateDB extends WorldStateDB {
constructor(private merkleDb: MerkleTreeWriteOperations, dataSource: ContractDataSource) {
constructor(private merkleDb: MerkleTreeWriteOperations, dataSource: ContractDataSource, private txe: TXE) {
super(merkleDb, dataSource);
}

Expand All @@ -31,11 +33,12 @@ export class TXEWorldStateDB extends WorldStateDB {
}

override async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<bigint> {
await this.merkleDb.batchInsert(
MerkleTreeId.PUBLIC_DATA_TREE,
[new PublicDataTreeLeaf(computePublicDataTreeLeafSlot(contract, slot), newValue).toBuffer()],
0,
);
await this.txe.addPublicDataWrites([new PublicDataWrite(computePublicDataTreeLeafSlot(contract, slot), newValue)]);
// await this.merkleDb.batchInsert(
// MerkleTreeId.PUBLIC_DATA_TREE,
// [new PublicDataTreeLeaf().toBuffer()],
// 0,
// );
return newValue.toBigInt();
}

Expand Down

0 comments on commit f6c3c47

Please sign in to comment.