-
Notifications
You must be signed in to change notification settings - Fork 312
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
Rk/clean collect logs #1026
Merged
Merged
Rk/clean collect logs #1026
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
212 changes: 212 additions & 0 deletions
212
yarn-project/acir-simulator/src/client/execution_result.test.ts
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 |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import { PrivateCallStackItem } from '@aztec/circuits.js'; | ||
import { FunctionL2Logs } from '@aztec/types'; | ||
|
||
import { ExecutionResult, collectEncryptedLogs, collectUnencryptedLogs } from './execution_result.js'; | ||
|
||
function emptyExecutionResult(): ExecutionResult { | ||
return { | ||
acir: Buffer.from(''), | ||
vk: Buffer.from(''), | ||
partialWitness: new Map(), | ||
callStackItem: PrivateCallStackItem.empty(), | ||
readRequestPartialWitnesses: [], | ||
preimages: { | ||
newNotes: [], | ||
nullifiedNotes: [], | ||
}, | ||
returnValues: [], | ||
nestedExecutions: [], | ||
enqueuedPublicFunctionCalls: [], | ||
encryptedLogs: FunctionL2Logs.empty(), | ||
unencryptedLogs: FunctionL2Logs.empty(), | ||
}; | ||
} | ||
|
||
describe('Execution Result test suite - collect encrypted logs', () => { | ||
function emptyExecutionResultWithEncryptedLogs(encryptedLogs = FunctionL2Logs.empty()): ExecutionResult { | ||
const executionResult = emptyExecutionResult(); | ||
executionResult.encryptedLogs = encryptedLogs; | ||
return executionResult; | ||
} | ||
|
||
it('collect encrypted logs with nested fn calls', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA (log1) | ||
|---------->fnB (log2) | ||
|---------->fnC (log3) -> fnD (log4) | ||
|---------->fnE (log5) | ||
|-------->fnF (log6) | ||
|-------->fnG (log7) | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnE, fnG, fnF, fnC, fnD, fnB] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResultWithEncryptedLogs( | ||
new FunctionL2Logs([Buffer.from('Log 1')]), | ||
); | ||
const fnB = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 2')])); | ||
const fnC = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 3')])); | ||
const fnD = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 4')])); | ||
const fnE = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 5')])); | ||
const fnF = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 6')])); | ||
const fnG = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 7')])); | ||
|
||
fnE.nestedExecutions.push(fnF, fnG); | ||
|
||
fnC.nestedExecutions.push(fnD); | ||
|
||
executionResult.nestedExecutions.push(fnB, fnC, fnE); | ||
|
||
const encryptedLogs = collectEncryptedLogs(executionResult); | ||
expect(encryptedLogs).toEqual([ | ||
new FunctionL2Logs([Buffer.from('Log 1')]), | ||
new FunctionL2Logs([Buffer.from('Log 5')]), | ||
new FunctionL2Logs([Buffer.from('Log 7')]), | ||
new FunctionL2Logs([Buffer.from('Log 6')]), | ||
new FunctionL2Logs([Buffer.from('Log 3')]), | ||
new FunctionL2Logs([Buffer.from('Log 4')]), | ||
new FunctionL2Logs([Buffer.from('Log 2')]), | ||
]); | ||
}); | ||
|
||
it('collect encrypted logs with multiple logs each function call', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA (log1, log2) | ||
|---------->fnB (log3, log4) | ||
|---------->fnC (log5) -> fnD (log6) | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnC, fnD, fnB] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResultWithEncryptedLogs( | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2')]), | ||
); | ||
const fnB = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 3'), Buffer.from('Log 4')])); | ||
const fnC = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 5')])); | ||
const fnD = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 6')])); | ||
fnC.nestedExecutions.push(fnD); | ||
executionResult.nestedExecutions.push(fnB, fnC); | ||
const encryptedLogs = collectEncryptedLogs(executionResult); | ||
expect(encryptedLogs).toEqual([ | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2')]), | ||
new FunctionL2Logs([Buffer.from('Log 5')]), | ||
new FunctionL2Logs([Buffer.from('Log 6')]), | ||
new FunctionL2Logs([Buffer.from('Log 3'), Buffer.from('Log 4')]), | ||
]); | ||
}); | ||
|
||
it('collect encrypted logs with nested functions where some have no logs', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA () | ||
|----------> fnB (log1) -> fnC () | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnB, fnC] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResult(); | ||
const fnB = emptyExecutionResultWithEncryptedLogs(new FunctionL2Logs([Buffer.from('Log 1')])); | ||
const fnC = emptyExecutionResult(); | ||
fnB.nestedExecutions.push(fnC); | ||
executionResult.nestedExecutions.push(fnB); | ||
const encryptedLogs = collectEncryptedLogs(executionResult); | ||
expect(encryptedLogs).toEqual([ | ||
FunctionL2Logs.empty(), | ||
new FunctionL2Logs([Buffer.from('Log 1')]), | ||
FunctionL2Logs.empty(), | ||
]); | ||
}); | ||
|
||
it('collect encrypted logs with no logs in any nested calls', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA () | ||
|----------> fnB () -> fnC () | ||
|----------> fnD () -> fnE () | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnD, fnE, fnB, fnC] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResult(); | ||
const fnB = emptyExecutionResult(); | ||
const fnC = emptyExecutionResult(); | ||
const fnD = emptyExecutionResult(); | ||
const fnE = emptyExecutionResult(); | ||
|
||
fnB.nestedExecutions.push(fnC); | ||
fnD.nestedExecutions.push(fnE); | ||
|
||
executionResult.nestedExecutions.push(fnB, fnD); | ||
|
||
const encryptedLogs = collectEncryptedLogs(executionResult); | ||
expect(encryptedLogs).toEqual([ | ||
FunctionL2Logs.empty(), | ||
FunctionL2Logs.empty(), | ||
FunctionL2Logs.empty(), | ||
FunctionL2Logs.empty(), | ||
FunctionL2Logs.empty(), | ||
]); | ||
}); | ||
}); | ||
|
||
describe('collect unencrypted logs', () => { | ||
// collection of unencrypted logs work similar to encrypted logs, so lets write other kinds of test cases: | ||
|
||
function emptyExecutionResultWithUnencryptedLogs(unencryptedLogs = FunctionL2Logs.empty()): ExecutionResult { | ||
const executionResult = emptyExecutionResult(); | ||
executionResult.unencryptedLogs = unencryptedLogs; | ||
return executionResult; | ||
} | ||
|
||
it('collect unencrypted logs even when no logs and no recursion', () => { | ||
// fnA() | ||
const executionResult: ExecutionResult = emptyExecutionResult(); | ||
const unencryptedLogs = collectUnencryptedLogs(executionResult); | ||
expect(unencryptedLogs).toEqual([FunctionL2Logs.empty()]); | ||
}); | ||
|
||
it('collect unencrypted logs with no logs in some nested calls', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA () | ||
|----------> fnB () -> fnC (log1, log2, log3) | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnC, fnB] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResult(); | ||
const fnB = emptyExecutionResult(); | ||
const fnC = emptyExecutionResultWithUnencryptedLogs( | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2'), Buffer.from('Log 3')]), | ||
); | ||
|
||
executionResult.nestedExecutions.push(fnB, fnC); | ||
|
||
const unencryptedLogs = collectUnencryptedLogs(executionResult); | ||
expect(unencryptedLogs).toEqual([ | ||
FunctionL2Logs.empty(), | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2'), Buffer.from('Log 3')]), | ||
FunctionL2Logs.empty(), | ||
]); | ||
}); | ||
|
||
it('collect unencrypted logs with multiple logs in each function call leaves', () => { | ||
/* | ||
Create the following executionResult object: | ||
fnA() | ||
|->fnB | ||
|->fnC(log1, log2, log3) | ||
|->fnD(log4, log5, log6) | ||
Circuits and ACVM process in a DFS + stack like format: [fnA, fnB, fnD, fnC] | ||
*/ | ||
const executionResult: ExecutionResult = emptyExecutionResult(); | ||
const fnB = emptyExecutionResult(); | ||
const fnC = emptyExecutionResultWithUnencryptedLogs( | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2'), Buffer.from('Log 3')]), | ||
); | ||
const fnD = emptyExecutionResultWithUnencryptedLogs( | ||
new FunctionL2Logs([Buffer.from('Log 4'), Buffer.from('Log 5'), Buffer.from('Log 6')]), | ||
); | ||
fnB.nestedExecutions.push(fnC, fnD); | ||
executionResult.nestedExecutions.push(fnB); | ||
const unencryptedLogs = collectUnencryptedLogs(executionResult); | ||
expect(unencryptedLogs).toEqual([ | ||
FunctionL2Logs.empty(), | ||
FunctionL2Logs.empty(), | ||
new FunctionL2Logs([Buffer.from('Log 4'), Buffer.from('Log 5'), Buffer.from('Log 6')]), | ||
new FunctionL2Logs([Buffer.from('Log 1'), Buffer.from('Log 2'), Buffer.from('Log 3')]), | ||
]); | ||
}); | ||
}); |
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
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.
I would rephrase the name of this test as fnA and fnB do not emit logs. Maybe sthg like:
'collect unencrypted logs with multiple logs in each function call leaves'