-
Notifications
You must be signed in to change notification settings - Fork 310
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
refactor: make get_notes fail if returning no notes #4988 #5320
Changes from 13 commits
1f033aa
d959504
3402cb3
c7b8176
0c50892
7ad5ad4
b1bf1dd
adb29ea
16a7de1
f75b7db
109aee5
2353c11
81a62bc
f746893
48c56c6
a8c9971
1326bd4
6939c8f
446ca47
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 |
---|---|---|
|
@@ -79,10 +79,10 @@ describe('e2e_pending_note_hashes_contract', () => { | |
owner, | ||
deployedContract.methods.insert_note.selector, | ||
deployedContract.methods.get_then_nullify_note.selector, | ||
deployedContract.methods.get_note_zero_balance.selector, | ||
) | ||
.send() | ||
.wait(); | ||
await expect(deployedContract.methods.get_note_zero_balance(owner).send().wait()).rejects.toThrow(); | ||
|
||
await expectNoteHashesSquashedExcept(0); | ||
await expectNullifiersSquashedExcept(0); | ||
|
@@ -154,10 +154,10 @@ describe('e2e_pending_note_hashes_contract', () => { | |
owner, | ||
deployedContract.methods.insert_note.selector, | ||
deployedContract.methods.get_then_nullify_note.selector, | ||
deployedContract.methods.get_note_zero_balance.selector, | ||
) | ||
.send() | ||
.wait(); | ||
await expect(deployedContract.methods.get_note_zero_balance(owner).send().wait()).rejects.toThrow(); | ||
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. |
||
|
||
// second TX creates 1 note, but it is squashed! | ||
await expectNoteHashesSquashedExcept(0); | ||
|
@@ -186,7 +186,6 @@ describe('e2e_pending_note_hashes_contract', () => { | |
owner, | ||
deployedContract.methods.dummy.selector, | ||
deployedContract.methods.get_then_nullify_note.selector, | ||
deployedContract.methods.get_note_zero_balance.selector, | ||
) | ||
.send() | ||
.wait(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ describe('e2e_static_calls', () => { | |
|
||
describe('parent calls child', () => { | ||
it('performs legal private to private static calls', async () => { | ||
await childContract.methods.privateSetValue(42n, wallet.getCompleteAddress().address).send().wait(); | ||
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. Would add a comment here for why you needed to do this change. |
||
await parentContract.methods | ||
.privateStaticCall(childContract.address, childContract.methods.privateGetValue.selector, [ | ||
42n, | ||
|
@@ -32,6 +33,7 @@ describe('e2e_static_calls', () => { | |
}, 100_000); | ||
|
||
it('performs legal (nested) private to private static calls', async () => { | ||
await childContract.methods.privateSetValue(42n, wallet.getCompleteAddress().address).send().wait(); | ||
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. Would add a comment here for why you needed to do this change. |
||
await parentContract.methods | ||
.privateStaticCallNested(childContract.address, childContract.methods.privateGetValue.selector, [ | ||
42n, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -918,27 +918,15 @@ describe('Private Execution test suite', () => { | |
|
||
const getThenNullifyArtifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'get_then_nullify_note'); | ||
|
||
const getZeroArtifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'get_note_zero_balance'); | ||
|
||
const insertFnSelector = FunctionSelector.fromNameAndParameters(insertArtifact.name, insertArtifact.parameters); | ||
const getThenNullifyFnSelector = FunctionSelector.fromNameAndParameters( | ||
getThenNullifyArtifact.name, | ||
getThenNullifyArtifact.parameters, | ||
); | ||
const getZeroFnSelector = FunctionSelector.fromNameAndParameters( | ||
getZeroArtifact.name, | ||
getZeroArtifact.parameters, | ||
); | ||
|
||
oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); | ||
|
||
const args = [ | ||
amountToTransfer, | ||
owner, | ||
insertFnSelector.toField(), | ||
getThenNullifyFnSelector.toField(), | ||
getZeroFnSelector.toField(), | ||
]; | ||
const args = [amountToTransfer, owner, insertFnSelector.toField(), getThenNullifyFnSelector.toField()]; | ||
const result = await runSimulator({ | ||
args: args, | ||
artifact: artifact, | ||
|
@@ -947,7 +935,6 @@ describe('Private Execution test suite', () => { | |
|
||
const execInsert = result.nestedExecutions[0]; | ||
const execGetThenNullify = result.nestedExecutions[1]; | ||
const getNotesAfterNullify = result.nestedExecutions[2]; | ||
|
||
const storageSlot = computeSlotForMapping(new Fr(1n), owner); | ||
const noteTypeId = new Fr(869710811710178111116101n); // ValueNote | ||
|
@@ -991,10 +978,6 @@ describe('Private Execution test suite', () => { | |
siloedNullifierSecretKey.high, | ||
]); | ||
expect(nullifier.value).toEqual(expectedNullifier); | ||
|
||
// check that the last get_notes call return no note | ||
const afterNullifyingNoteValue = getNotesAfterNullify.callStackItem.publicInputs.returnValues[0].value; | ||
expect(afterNullifyingNoteValue).toEqual(0n); | ||
}); | ||
|
||
it('cant read a commitment that is inserted later in same call', async () => { | ||
|
@@ -1007,48 +990,13 @@ describe('Private Execution test suite', () => { | |
const artifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'test_bad_get_then_insert_flat'); | ||
|
||
const args = [amountToTransfer, owner]; | ||
const result = await runSimulator({ | ||
args: args, | ||
artifact: artifact, | ||
contractAddress, | ||
}); | ||
|
||
const storageSlot = computeSlotForMapping(new Fr(1n), owner); | ||
const noteTypeId = new Fr(869710811710178111116101n); // ValueNote | ||
|
||
expect(result.newNotes).toHaveLength(1); | ||
const noteAndSlot = result.newNotes[0]; | ||
expect(noteAndSlot.storageSlot).toEqual(storageSlot); | ||
expect(noteAndSlot.noteTypeId).toEqual(noteTypeId); | ||
|
||
expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); | ||
|
||
const newNoteHashes = sideEffectArrayToValueArray( | ||
nonEmptySideEffects(result.callStackItem.publicInputs.newNoteHashes), | ||
); | ||
expect(newNoteHashes).toHaveLength(1); | ||
|
||
const noteHash = newNoteHashes[0]; | ||
expect(noteHash).toEqual( | ||
await acirSimulator.computeInnerNoteHash( | ||
await expect( | ||
runSimulator({ | ||
args: args, | ||
artifact: artifact, | ||
contractAddress, | ||
storageSlot, | ||
noteAndSlot.noteTypeId, | ||
noteAndSlot.note, | ||
), | ||
); | ||
|
||
// read requests should be empty | ||
const readRequest = result.callStackItem.publicInputs.noteHashReadRequests[0].value; | ||
expect(readRequest).toEqual(Fr.ZERO); | ||
|
||
// should get note value 0 because it actually gets a fake note since the real one hasn't been inserted yet! | ||
const gotNoteValue = result.callStackItem.publicInputs.returnValues[0]; | ||
expect(gotNoteValue).toEqual(Fr.ZERO); | ||
|
||
// there should be no nullifiers | ||
const nullifier = result.callStackItem.publicInputs.newNullifiers[0].value; | ||
expect(nullifier).toEqual(Fr.ZERO); | ||
}), | ||
).rejects.toThrow(); | ||
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. Would check the error. |
||
}); | ||
}); | ||
|
||
|
@@ -1069,6 +1017,17 @@ describe('Private Execution test suite', () => { | |
}); | ||
}); | ||
|
||
describe('Get notes', () => { | ||
it('fails if returning no notes', async () => { | ||
const artifact = getFunctionArtifact(TestContractArtifact, 'call_get_notes'); | ||
|
||
const args = [2n, true]; | ||
oracle.getNotes.mockResolvedValue([]); | ||
|
||
await expect(runSimulator({ artifact, args })).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('Context oracles', () => { | ||
it("Should be able to get and return the contract's portal contract address", async () => { | ||
const portalContractAddress = EthAddress.random(); | ||
|
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 it would be better to check the message here to ensure we don't throw for some other reason.