-
Notifications
You must be signed in to change notification settings - Fork 284
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: share state manager and side effect tracer for all enqueued calls in tx #9565
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
75e6b4b
to
15de5d9
Compare
15de5d9
to
f3891e6
Compare
26df580
to
46bd46f
Compare
|
||
fn validate_counters(self, previous_kernel: PublicKernelCircuitPublicInputs) { | ||
assert_eq( | ||
self.enqueued_call.data.start_side_effect_counter, | ||
previous_kernel.end_side_effect_counter + 1, | ||
"enqueued call must start from the end counter of the previous call", | ||
); | ||
} | ||
|
||
// Validates that the start gas injected into the vm circuit matches the remaining gas. |
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.
This constraint was failing because when an enqueued call had no side effects, it would start with start == prev.end
. I was trying to figure out the proper way to modify this constraint or modify the AVM/tracing when I realized.... We're going to delete this anyway since side effect counters shouldn't be a critical part of the protocol with everything in the AVM.
global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 100_000_000; | ||
global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 12_000_000; |
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.
There is no reason the teardown limit should be higher than the enqueued call limit
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.
It maybe doesn't make sense to change this here, but I did so while debugging a test failure and thought... why change it back?
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.
then maybe you can move the line past MAX_L2_GAS_PER_ENQUEUED_CALL and do
global DEFAULT_TEARDOWN_GAS_LIMIT = MAX_L2_GAS_PER_ENQUEUED_CALL;
?
@@ -56,93 +54,5 @@ describe('prover/orchestrator/public-functions', () => { | |||
expect(block.number).toEqual(context.blockNumber); | |||
}, | |||
); | |||
|
|||
it('nested public calls', async () => { |
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.
test doesn't make sense any more because we aren't generating proofs per nested public call
describe('AVM simulator: transpiled Noir contracts', () => { | ||
it('bulk testing', async () => { |
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.
Made some debugging easier so i didn't have to run the bb-prover tests. This is probably good to have here anyway.
@@ -1 +1,2 @@ | |||
export * from './avm_simulator.js'; | |||
export * from './journal/index.js'; |
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.
I think the journal needs to be renamed StateManager and moved to the src/public/ folder. Will do so in a follow-up PR.
// TODO(5818): make private once no longer accessed in executor | ||
public readonly publicStorage: PublicStorage, | ||
public readonly trace: PublicSideEffectTraceInterface, |
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.
Made public for now.... Otherwise I need to keep adding passthrough functions to the trace. Eventually, the only place outside the AVM where the trace will be accessed will be in the enqueued calls processor where the trace instance is first constructed. At that point we should be able to make this private again since the instance is directly accessible there.
5b22d9f
to
58bb2b7
Compare
@@ -219,11 +220,36 @@ export class TXE implements TypedOracle { | |||
return this.txeDatabase.addAuthWitness(authWitness.requestHash, authWitness.witness); | |||
} | |||
|
|||
async addNullifiers(contractAddress: AztecAddress, nullifiers: Fr[]) { | |||
async addPublicDataWrites(writes: PublicDataUpdateRequest[]) { |
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.
public executor no longer commits to worldStateDB, so we need to manually perform tree insertions for public data writes here
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.
TY David! LGTM, provided the current TXE test suite passes (which it does!)
Seems like we don't have to build the CombinedConstantData
in its entirety now, is this going to stay that way? If it is, I'll leave just the GlobalVariables
struct in executePublicFunction
in an upcoming refactor PR, should clean it up quite nicely.
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.
Hmm I think it will stay that way, at least for the TXE's interface to the executor
84c628a
to
8227f99
Compare
8227f99
to
c5f6d3a
Compare
c5f6d3a
to
9bf1802
Compare
9bf1802
to
c4b624d
Compare
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.
LGTM! 🚀
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.
I think this is a good step forwards.
I still don't have a lot of clarity on how things will end up looking so I think the best (for me) is to see where we land and then once we think we have the final version, I can judge it better :)
@@ -265,17 +331,28 @@ export class EnqueuedCallsProcessor { | |||
); | |||
throw enqueuedCallResult.revertReason; | |||
} | |||
await txStateManager.mergeStateForEnqueuedCall( |
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.
Note to self: I'm wondering why we can't have a generic accept/reject and we need a special one for enqueued call?
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.
Because this merge function traces the enqueued call under the hood, adding it to hints & vector that ultimately becomes public inputs
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.
Right now, this is how we handle all "merges of forked state". We merge the forked state, and we trace the thing that caused the fork. It's not pretty....
Maybe the merge and trace should be separate functions? So we first do mergeForkedState which is always the same no matter what. And then we call a tailored trace function?
global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 100_000_000; | ||
global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 12_000_000; |
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.
then maybe you can move the line past MAX_L2_GAS_PER_ENQUEUED_CALL and do
global DEFAULT_TEARDOWN_GAS_LIMIT = MAX_L2_GAS_PER_ENQUEUED_CALL;
?
Resolving comments in #9785 |
I could, but I think that the max-per-enqueued call might go away and be replaced by a limit for the whole TX (minus teardown) |
This PR is a bit of a mashup of things as I made sense of what needs to happen to start tracking side effects and state changes at the transaction level.
Refactor of
PublicExecutionResult
,PublicExecutor
,EnqueuedCallSimulator
&EnqueuedCallsProcessor
. A lot of this PR is prep for removal of the public kernel and generation of TX-level AVM public inputs & hints.AvmStateManager
(needs rename) up to theEnqueuedCallsProcessor
and uses it for state checkpointing/forking & rollbacks instead ofWorldStateDB
. This will let us track side effects at the transaction level and eventually generate AVM circuit hints & public inputs at the transaction level.PublicExecutor.simulate()
. The only consumers ofPublicExecutor.simulate()
are the TXE and theEnqueuedCallSimulator
. The TXE needs side effects, but theEnqueuedCallSimulator
shouldn't (although it does until the public kernel is deleted). I provided a minimal return type for each case.EnqueuedCallSimulator
doesn't receive side effects in the return type fromPublicExecutor.simulate()
and instead makes a call to thetrace
to retrieveVMCircuitPublicInputs
. Eventually that call to thetrace
will happen in theEnqueuedCallsProcessor
just once for the entire transaction.PublicProcessor
tests intoEnqueudCallsProcessor
tests as they don't really belong at that high a level.Followup work:
AvmStateManager
->PublicStateManager
, rename file accordingly, & move tosimulator/src/public
AVMPublicInputs
are introduced, pull the calls tostateManager.trace.toVMCircuitPublicInputs()
up to theEnqueuedCallsProcessor
& modify that function to return the newAVMPublicInputs
PublicFunctionCallResult
and the oldPublicSideEffectTrace
(to be fully replaced by thePublicEnqueuedCallSideEffectTrace
which will need a rename). This will require disconnecting the AVM circuit completely until it supports the tx-levelAVMPublicInputs
.