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

chore: prep for switching AVM to checkpointed native trees - TS test cleanup and refactors #12023

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

dbanks12
Copy link
Collaborator

@dbanks12 dbanks12 commented Feb 15, 2025

This PR is mostly setup for switching the AVM to use checkpointed native trees. Originally I had that in the same branch, but there were enough of these prerequisite changes to pull them out.

Orchestrator testing

prover-client's TestContext no longer mocks AVM simulation.

Context: while trying to transition the AVM to use native checkpointed trees, I ran into issues with the orchestrator public functions tests because the public processor will no longer update the trees for public functions. So, I think we should stop mocking the AVM simulation for these tests and let the AVM do its tree updates. We can then do two types of tests:

  1. A quick test that doesn't actually deploy/run any real contract functions and instead tests the orchestrator with a mocked/garbage TX that has 1 revertible enqueued call. The AVM will fail to retrieve it's bytecode, but the TX can still be included. orchestrator_public_functions.test.ts now does this.
  2. A real test that creates TXs that actually do a bunch of real token operations via non-revertible and revertible enqueued calls. orchestrator_multi_public_functions.test.ts now does this.

AVM & PublicProcessor testing

  • PublicTxSimulationTester lets you createTx separately from simulateTx (useful for testing PublicProcessor)
  • Add PublicTxSimulator test for avm bulk test
  • Add a PublicProcessor test of the token contract (construct, mint, many transfers)
  • Consolidate some duplicate helper functions in simulator/src/avm and simulator/src/public
  • Simplify process of registering/deploying contracts via avm *Tester classes, and optional contract address nullifier insertion
  • Contract Updates test now use the tester's register*() function instead of manually constructing contract classes and instances
  • Remove unused function from avm test contract

Misc

  • Making contract classes for tests is now deterministic (no more random public keys)
  • Use new/proper sha256 in benchmarking test contract

@dbanks12 dbanks12 marked this pull request as ready for review February 18, 2025 17:34
@dbanks12 dbanks12 requested a review from fcarreiro as a code owner February 18, 2025 17:34
@dbanks12 dbanks12 changed the title chore: avm TS test cleanup and refactors chore: prep for switching AVM to checkpointed native trees - TS test cleanup and refactors Feb 18, 2025
@dbanks12 dbanks12 requested a review from sirasistant February 18, 2025 19:49
@@ -58,9 +40,10 @@ describe('AVM WitGen & Circuit – check circuit', () => {
},
TIMEOUT,
);
// FIXME(dbanks12): fails with "Lookup PERM_MAIN_ALU failed."
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was accidentally removed in a previous PR

std::hash::sha256(data)
sha256::sha256_var(data, data.len() as u64)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created this fn last week and used the old stdlib sha

Comment on lines -403 to -408
#[public]
fn assert_timestamp(expected_timestamp: u64) {
let timestamp = context.timestamp();
assert(timestamp == expected_timestamp, "timestamp does not match");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment on lines 58 to 62
const tx = await mockTx(1234, {
numberOfNonRevertiblePublicCallRequests: 2,
numberOfRevertiblePublicCallRequests: 1,
});
tx.data.constants.historicalHeader = context.getBlockHeader(0);
tx.data.constants.vkTreeRoot = getVKTreeRoot();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed with @MirandaWood that this change should be okay

@@ -13,7 +13,6 @@ import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace

export async function mockGetBytecode(worldStateDB: WorldStateDB, bytecode: Buffer) {
const commitment = await computePublicBytecodeCommitment(bytecode);
(worldStateDB as jest.Mocked<WorldStateDB>).getBytecode.mockResolvedValue(bytecode);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't used

Comment on lines -86 to -110

export function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
assert(!!artifact, `Function ${functionName} not found in AvmTestContractArtifact`);
const params = artifact.parameters;
return FunctionSelector.fromNameAndParameters(artifact.name, params);
}

export function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
assert(
!!artifact?.bytecode,
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
);
return artifact;
}

export function getAvmTestContractBytecode(functionName: string): Buffer {
const artifact = getAvmTestContractArtifact(functionName);
return artifact.bytecode;
}

export function getAvmTestContractPublicDispatchBytecode(): Buffer {
return getAvmTestContractBytecode(PUBLIC_DISPATCH_FN_NAME);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were duplicated from avm/fixtures

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant