Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: txe native world state #11226

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ noir-projects-with-cache:
FROM +bootstrap
ENV CI=1
ENV USE_CACHE=1
LET artifact=noir-projects-ci-tests-$(./noir-projects/bootstrap.sh hash)
LET artifact=noir-projects-ci-tests-$(./noir-projects/bootstrap.sh hash)-$(ci3/cache_content_hash yarn-project/txe)
IF ci3/test_should_run $artifact
# could be changed to bootstrap once txe solution found
WAIT
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ mod test {
unconstrained fn fetching_a_valid_but_different_header_should_fail() {
let mut env = TestEnvironment::new();

env.advance_block_to(3);
env.advance_block_by(4);

// We get our current header for the last archive values.
let current_header = env.private().historical_header;

let target_block_number = 2;
let target_block_number = 3;
let bad_header = get_block_header_at_internal(target_block_number - 1);

// We pass in a different block number than the header received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
let voting_contract = env.deploy_self("EasyPrivateVoting").with_public_void_initializer(
initializer_call_interface,
);

env.advance_block_by(1);
(&mut env, voting_contract.to_address(), admin)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ unconstrained fn access_control() {
// Set a new admin
NFT::at(nft_contract_address).set_admin(recipient).call(&mut env.public());

env.advance_block_by(1);

// Check it worked
let admin = NFT::at(nft_contract_address).get_admin().view(&mut env.public());
assert(admin == recipient.to_field());
Expand All @@ -24,13 +26,17 @@ unconstrained fn access_control() {
// Set admin as minter
NFT::at(nft_contract_address).set_minter(recipient, true).call(&mut env.public());

env.advance_block_by(1);

// Check it worked
let is_minter = is_minter_call_interface.view(&mut env.public());
assert(is_minter == true);

// Revoke minter as admin
NFT::at(nft_contract_address).set_minter(recipient, false).call(&mut env.public());

env.advance_block_by(1);

// Check it worked
let is_minter = is_minter_call_interface.view(&mut env.public());
assert(is_minter == false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ unconstrained fn mint_success() {
let token_id = 10000;
NFT::at(nft_contract_address).mint(owner, token_id).call(&mut env.public());

env.advance_block_by(1);

utils::assert_owns_public_nft(env, nft_contract_address, owner, token_id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ unconstrained fn transfer_in_public() {
&mut env.public(),
);

env.advance_block_by(1);

utils::assert_owns_public_nft(env, nft_contract_address, recipient, token_id);
}

Expand All @@ -26,6 +28,8 @@ unconstrained fn transfer_in_public_to_self() {
// Transfer the NFT
NFT::at(nft_contract_address).transfer_in_public(user, user, token_id, 0).call(&mut env.public());

env.advance_block_by(1);

// Check the user stayed the public owner
utils::assert_owns_public_nft(env, nft_contract_address, user, token_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub unconstrained fn setup_and_mint(
let minted_token_id = 615;

NFT::at(nft_contract_address).mint(owner, minted_token_id).call(&mut env.public());
env.advance_block_by(1);

(env, nft_contract_address, owner, recipient, minted_token_id)
}
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
19 changes: 9 additions & 10 deletions yarn-project/txe/src/node/txe_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
type L2Tips,
type LogFilter,
type MerkleTreeId,
type MerkleTreeReadOperations,
type MerkleTreeWriteOperations,
type NullifierMembershipWitness,
type ProverConfig,
type PublicDataWitness,
Expand Down Expand Up @@ -44,7 +46,7 @@ import {
import { type L1ContractAddresses } from '@aztec/ethereum';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { MerkleTreeSnapshotOperationsFacade, type MerkleTrees } from '@aztec/world-state';
import { type NativeWorldStateService } from '@aztec/world-state';

export class TXENode implements AztecNode {
#logsByTags = new Map<string, TxScopedL2Log[]>();
Expand All @@ -59,7 +61,8 @@ export class TXENode implements AztecNode {
private blockNumber: number,
private version: number,
private chainId: number,
private trees: MerkleTrees,
private nativeWorldStateService: NativeWorldStateService,
private baseFork: MerkleTreeWriteOperations,
) {}

/**
Expand Down Expand Up @@ -272,14 +275,10 @@ export class TXENode implements AztecNode {
// We should likely migrate this so that the trees are owned by the node.

// TODO: blockNumber is being passed as undefined, figure out why
if (blockNumber === 'latest' || blockNumber === undefined) {
blockNumber = await this.getBlockNumber();
}

const db =
blockNumber === (await this.getBlockNumber())
? await this.trees.getLatest()
: new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber);
const db: MerkleTreeReadOperations =
blockNumber === (await this.getBlockNumber()) || blockNumber === 'latest' || blockNumber === undefined
? this.baseFork
: this.nativeWorldStateService.getSnapshot(blockNumber);

return await db.findLeafIndices(
treeId,
Expand Down
Loading
Loading