-
Notifications
You must be signed in to change notification settings - Fork 322
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(avm): plumb start side effect counter in circuit #7007
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,8 +67,10 @@ inline const uint32_t PCPI_NEW_NULLIFIERS_OFFSET = | |
inline const uint32_t PCPI_NEW_L2_TO_L1_MSGS_OFFSET = | ||
PCPI_NEW_NULLIFIERS_OFFSET + (MAX_NEW_NULLIFIERS_PER_CALL * NULLIFIER_LENGTH); | ||
|
||
inline const uint32_t PCPI_NEW_UNENCRYPTED_LOGS_OFFSET /*2 item gap*/ = | ||
PCPI_NEW_L2_TO_L1_MSGS_OFFSET + (MAX_NEW_L2_TO_L1_MSGS_PER_CALL * L2_TO_L1_MESSAGE_LENGTH) + 2; | ||
inline const uint32_t PCPI_START_SIDE_EFFECT_COUNTER_OFFSET = | ||
PCPI_NEW_L2_TO_L1_MSGS_OFFSET + (MAX_NEW_L2_TO_L1_MSGS_PER_CALL * L2_TO_L1_MESSAGE_LENGTH); | ||
|
||
inline const uint32_t PCPI_NEW_UNENCRYPTED_LOGS_OFFSET = PCPI_START_SIDE_EFFECT_COUNTER_OFFSET + /*1 item gap*/ 1; | ||
Comment on lines
-70
to
+73
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. This offset thing is so bad 😅 we need to figure out a proper way to do this 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. agreed |
||
|
||
// END INDEXES in the PUBLIC_CIRCUIT_PUBLIC_INPUTS | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import { Fr } from '@aztec/circuits.js'; | ||
import { makePublicKernelCircuitPublicInputs } from '@aztec/circuits.js/testing'; | ||
|
||
import { lastSideEffectCounter } from './utils.js'; | ||
import { AbstractPhaseManager } from './abstract_phase_manager.js'; | ||
|
||
describe('sequencer utils', () => { | ||
describe('lastSideEffectCounter', () => { | ||
describe('AbstractPhaseManager utils', () => { | ||
describe('getMaxSideEffectCounter', () => { | ||
it('correctly identifies the highest side effect counter in a transaction', () => { | ||
const inputs = makePublicKernelCircuitPublicInputs(); | ||
|
||
const startingCounter = lastSideEffectCounter(inputs); | ||
const startingCounter = AbstractPhaseManager.getMaxSideEffectCounter(inputs); | ||
|
||
inputs.endNonRevertibleData.newNoteHashes.at(-1)!.counter = startingCounter + 1; | ||
expect(lastSideEffectCounter(inputs)).toBe(startingCounter + 1); | ||
expect(AbstractPhaseManager.getMaxSideEffectCounter(inputs)).toBe(startingCounter + 1); | ||
|
||
inputs.endNonRevertibleData.publicCallStack.at(-1)!.startSideEffectCounter = new Fr(startingCounter + 2); | ||
expect(lastSideEffectCounter(inputs)).toBe(startingCounter + 2); | ||
expect(AbstractPhaseManager.getMaxSideEffectCounter(inputs)).toBe(startingCounter + 2); | ||
|
||
inputs.end.newNoteHashes.at(-1)!.counter = startingCounter + 3; | ||
expect(lastSideEffectCounter(inputs)).toBe(startingCounter + 3); | ||
expect(AbstractPhaseManager.getMaxSideEffectCounter(inputs)).toBe(startingCounter + 3); | ||
|
||
inputs.end.newNullifiers.at(-1)!.counter = startingCounter + 4; | ||
expect(lastSideEffectCounter(inputs)).toBe(startingCounter + 4); | ||
expect(AbstractPhaseManager.getMaxSideEffectCounter(inputs)).toBe(startingCounter + 4); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ import { type MerkleTreeOperations } from '@aztec/world-state'; | |
|
||
import { HintsBuilder } from './hints_builder.js'; | ||
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js'; | ||
import { lastSideEffectCounter } from './utils.js'; | ||
|
||
export const PhaseIsRevertible: Record<PublicKernelType, boolean> = { | ||
[PublicKernelType.NON_PUBLIC]: false, | ||
|
@@ -263,19 +262,15 @@ export abstract class AbstractPhaseManager { | |
while (executionStack.length) { | ||
const current = executionStack.pop()!; | ||
const isExecutionRequest = !isPublicExecutionResult(current); | ||
const sideEffectCounter = lastSideEffectCounter(kernelPublicOutput) + 1; | ||
const availableGas = this.getAvailableGas(tx, kernelPublicOutput); | ||
const pendingNullifiers = this.getSiloedPendingNullifiers(kernelPublicOutput); | ||
|
||
const result = isExecutionRequest | ||
? await this.publicExecutor.simulate( | ||
current, | ||
this.globalVariables, | ||
availableGas, | ||
/*availableGas=*/ this.getAvailableGas(tx, kernelPublicOutput), | ||
tx.data.constants.txContext, | ||
pendingNullifiers, | ||
/*pendingNullifiers=*/ this.getSiloedPendingNullifiers(kernelPublicOutput), | ||
transactionFee, | ||
sideEffectCounter, | ||
/*startSideEffectCounter=*/ AbstractPhaseManager.getMaxSideEffectCounter(kernelPublicOutput) + 1, | ||
) | ||
: current; | ||
|
||
|
@@ -493,6 +488,44 @@ export abstract class AbstractPhaseManager { | |
return await Promise.all(nested.map(n => this.getPublicCallStackItem(n))); | ||
} | ||
|
||
/** | ||
* Looks at the side effects of a transaction and returns the highest counter | ||
* @param tx - A transaction | ||
* @returns The highest side effect counter in the transaction so far | ||
*/ | ||
static getMaxSideEffectCounter(inputs: PublicKernelCircuitPublicInputs): number { | ||
const sideEffectCounters = [ | ||
...inputs.endNonRevertibleData.newNoteHashes, | ||
...inputs.endNonRevertibleData.newNullifiers, | ||
...inputs.endNonRevertibleData.noteEncryptedLogsHashes, | ||
...inputs.endNonRevertibleData.encryptedLogsHashes, | ||
...inputs.endNonRevertibleData.unencryptedLogsHashes, | ||
...inputs.endNonRevertibleData.publicCallStack, | ||
...inputs.endNonRevertibleData.publicDataUpdateRequests, | ||
...inputs.end.newNoteHashes, | ||
...inputs.end.newNullifiers, | ||
...inputs.end.noteEncryptedLogsHashes, | ||
...inputs.end.encryptedLogsHashes, | ||
...inputs.end.unencryptedLogsHashes, | ||
...inputs.end.publicCallStack, | ||
...inputs.end.publicDataUpdateRequests, | ||
]; | ||
|
||
let max = 0; | ||
for (const sideEffect of sideEffectCounters) { | ||
if ('startSideEffectCounter' in sideEffect) { | ||
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. Is there a more robust way to perform this filtering by not using a string? 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. Yeah this is old code. This is actually testing that |
||
// look at both start and end counters because for enqueued public calls start > 0 while end === 0 | ||
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber()); | ||
} else if ('counter' in sideEffect) { | ||
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. Same here |
||
max = Math.max(max, sideEffect.counter); | ||
} else { | ||
throw new Error('Unknown side effect type'); | ||
} | ||
} | ||
|
||
return max; | ||
} | ||
|
||
protected getBytecodeHash(_result: PublicExecutionResult) { | ||
// TODO: Determine how to calculate bytecode hash. Circuits just check it isn't zero for now. | ||
// See https://github.com/AztecProtocol/aztec3-packages/issues/378 | ||
|
This file was deleted.
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.
Ordering of member initializations does not match ordering of constructor args
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.
Actually it complained when I changed it! We'll see.