Skip to content
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: Ensure claimer is owner of the note in claim contract #5135

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ contract Claim {
}

#[aztec(private)]
fn claim(proof_note: ValueNote) {
// 1) Check that the note corresponds to the target contract
fn claim(proof_note: ValueNote, recipient: AztecAddress) {
// 1) Check that the note corresponds to the target contract and belongs to the sender
let target_address = storage.target_contract.read_private();
assert(
target_address == proof_note.header.contract_address, "Note does not correspond to the target contract"
);
assert_eq(proof_note.owner, context.msg_sender(), "Note does not belong to the sender");

// 2) Prove that the note hash exists in the note hash tree
prove_note_inclusion(proof_note, context);
Expand All @@ -53,6 +54,6 @@ contract Claim {

// 4) Finally we mint the reward token to the sender of the transaction
let reward_token = Token::at(storage.reward_token.read_private());
reward_token.mint_public(&mut context, context.msg_sender(), proof_note.value);
reward_token.mint_public(&mut context, recipient, proof_note.value);
}
}
20 changes: 16 additions & 4 deletions yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ describe('e2e_crowdfunding_and_claim', () => {

// 3) We claim the reward token via the Claim contract
{
await claimContract.withWallet(donorWallets[0]).methods.claim(valueNote).send().wait();
await claimContract
.withWallet(donorWallets[0])
.methods.claim(valueNote, donorWallets[0].getAddress())
.send()
.wait();
}

// Since the RWT is minted 1:1 with the DNT, the balance of the reward token should be equal to the donation amount
Expand All @@ -261,7 +265,9 @@ describe('e2e_crowdfunding_and_claim', () => {

it('cannot claim twice', async () => {
// The first claim was executed in the previous test
await expect(claimContract.withWallet(donorWallets[0]).methods.claim(valueNote).send().wait()).rejects.toThrow();
await expect(
claimContract.withWallet(donorWallets[0]).methods.claim(valueNote, donorWallets[0].getAddress()).send().wait(),
).rejects.toThrow();
});

it('cannot claim with a non-existent note', async () => {
Expand All @@ -270,7 +276,11 @@ describe('e2e_crowdfunding_and_claim', () => {
nonExistentNote.randomness = Fr.random();

await expect(
claimContract.withWallet(donorWallets[0]).methods.claim(nonExistentNote).send().wait(),
claimContract
.withWallet(donorWallets[0])
.methods.claim(nonExistentNote, donorWallets[0].getAddress())
.send()
.wait(),
).rejects.toThrow();
});

Expand All @@ -293,7 +303,9 @@ describe('e2e_crowdfunding_and_claim', () => {
await inclusionsProofsContract.methods.test_note_inclusion(owner, false, 0n, true).send().wait();

// 4) Finally, check that the claim process fails
await expect(claimContract.withWallet(donorWallets[0]).methods.claim(note).send().wait()).rejects.toThrow();
await expect(
claimContract.withWallet(donorWallets[0]).methods.claim(note, donorWallets[0].getAddress()).send().wait(),
).rejects.toThrow();
});

it('cannot donate after a deadline', async () => {
Expand Down
Loading