-
Notifications
You must be signed in to change notification settings - Fork 307
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: Simulate enqueued public functions and locate failing constraints on them #1853
Merged
+600
−103
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a509429
feat: first working version of simulate pub
sirasistant 408c83c
feat: allow parsing nested public exec errors
sirasistant 1ff4bd8
feat: sim errors with fn and noir call stacks
sirasistant 3d14c40
Merge branch 'master' into arv/simulate_public
sirasistant 8233a82
fix: cleanup
sirasistant 7c09e7a
Merge branch 'arv/simulate_public' of github.com:AztecProtocol/aztec-…
sirasistant 7eda8a4
test: fix test
sirasistant aba3018
fix: avoid simulations modifying state and txs
sirasistant 4894747
fix: clone inside processor to avoid the mutation
sirasistant e706da1
Merge branch 'master' into arv/simulate_public
sirasistant 213e465
refactor: improve printing of simulation errors
sirasistant 7e9fad9
Merge branch 'arv/simulate_public' of github.com:AztecProtocol/aztec-…
sirasistant 21e7a0b
feat: initial approach of transactional merkle db
sirasistant 87b53b2
feat: option skip public sim & refactor trees txs
sirasistant ff46ce9
Merge branch 'master' into arv/simulate_public
sirasistant 204386f
docs: added comment pointing to the created issue
sirasistant c90822a
Merge branch 'master' into arv/simulate_public
sirasistant 98f2690
refactor: improvements after peer review
sirasistant c11a01f
Merge branch 'master' into arv/simulate_public
sirasistant e0db983
fix: improve enrichment
sirasistant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,20 @@ import { | |
CircuitsWasm, | ||
EthAddress, | ||
Fr, | ||
GlobalVariables, | ||
HistoricBlockData, | ||
L1_TO_L2_MSG_TREE_HEIGHT, | ||
PRIVATE_DATA_TREE_HEIGHT, | ||
} from '@aztec/circuits.js'; | ||
import { AztecAddress } from '@aztec/foundation/aztec-address'; | ||
import { createDebugLogger } from '@aztec/foundation/log'; | ||
import { InMemoryTxPool, P2P, createP2PClient } from '@aztec/p2p'; | ||
import { SequencerClient } from '@aztec/sequencer-client'; | ||
import { | ||
GlobalVariableBuilder, | ||
PublicProcessorFactory, | ||
SequencerClient, | ||
getGlobalVariableBuilder, | ||
} from '@aztec/sequencer-client'; | ||
import { | ||
AztecNode, | ||
ContractData, | ||
|
@@ -61,6 +67,8 @@ export class AztecNodeService implements AztecNode { | |
protected sequencer: SequencerClient, | ||
protected chainId: number, | ||
protected version: number, | ||
protected globalVariableBuilder: GlobalVariableBuilder, | ||
protected merkleTreesDb: levelup.LevelUp, | ||
private log = createDebugLogger('aztec:node'), | ||
) {} | ||
|
||
|
@@ -81,9 +89,10 @@ export class AztecNodeService implements AztecNode { | |
const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver); | ||
|
||
// now create the merkle trees and the world state syncher | ||
const merkleTreeDB = await MerkleTrees.new(levelup(createMemDown()), await CircuitsWasm.get()); | ||
const merkleTreesDb = levelup(createMemDown()); | ||
const merkleTrees = await MerkleTrees.new(merkleTreesDb, await CircuitsWasm.get()); | ||
const worldStateConfig: WorldStateConfig = getWorldStateConfig(); | ||
const worldStateSynchroniser = new ServerWorldStateSynchroniser(merkleTreeDB, archiver, worldStateConfig); | ||
const worldStateSynchroniser = new ServerWorldStateSynchroniser(merkleTrees, archiver, worldStateConfig); | ||
|
||
// start both and wait for them to sync from the block source | ||
await Promise.all([p2pClient.start(), worldStateSynchroniser.start()]); | ||
|
@@ -108,6 +117,8 @@ export class AztecNodeService implements AztecNode { | |
sequencer, | ||
config.chainId, | ||
config.version, | ||
getGlobalVariableBuilder(config), | ||
merkleTreesDb, | ||
); | ||
} | ||
|
||
|
@@ -367,6 +378,37 @@ export class AztecNodeService implements AztecNode { | |
); | ||
} | ||
|
||
/** | ||
* Simulates the public part of a transaction with the current state. | ||
* @param tx - The transaction to simulate. | ||
**/ | ||
public async simulatePublicCalls(tx: Tx) { | ||
this.log.info(`Simulating tx ${await tx.getTxHash()}`); | ||
const blockNumber = (await this.blockSource.getBlockNumber()) + 1; | ||
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(new Fr(blockNumber)); | ||
const prevGlobalVariables = (await this.blockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty(); | ||
|
||
// Instantiate merkle trees so uncommited updates by this simulation are local to it. | ||
// TODO we should be able to remove this after https://github.com/AztecProtocol/aztec-packages/issues/1869 | ||
// So simulation of public functions doesn't affect the merkle trees. | ||
const merkleTrees = new MerkleTrees(this.merkleTreesDb, this.log); | ||
await merkleTrees.init(await CircuitsWasm.get(), { | ||
globalVariables: prevGlobalVariables, | ||
}); | ||
|
||
const publicProcessorFactory = new PublicProcessorFactory( | ||
merkleTrees.asLatest(), | ||
this.contractDataSource, | ||
this.l1ToL2MessageSource, | ||
); | ||
const processor = await publicProcessorFactory.create(prevGlobalVariables, newGlobalVariables); | ||
const [, failedTxs] = await processor.process([tx]); | ||
if (failedTxs.length) { | ||
throw failedTxs[0].error; | ||
} | ||
this.log.info(`Simulated tx ${await tx.getTxHash()} succeeds`); | ||
Comment on lines
+405
to
+409
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should extend this (in another PR!) so we report to the user the effects of a successful execution. Logs emitted is the easiest one, but we can also report back the call return value or any storage updates. Or the full trace even. |
||
} | ||
|
||
/** | ||
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched | ||
* @returns An instance of a committed MerkleTreeOperations | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a disposable MerkleTrees instance from DB is needed due to #1869