RustFund

First Flight #36
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: low
Valid

No Fund Goal Validation

Summary

The contract allows fund creation with a goal amount of zero, which could be misleading to contributors.

Vulnerability Details

The fund_create function doesn't validate that the goal amount is reasonable (greater than zero), allowing the creation of funds with meaningless fundraising goals.

pub fn fund_create(ctx: Context<FundCreate>, name: String, description: String, goal: u64) -> Result<()> {
let fund = &mut ctx.accounts.fund;
fund.name = name;
fund.description = description;
fund.goal = goal; // No validation that goal > 0
fund.deadline = 0;
fund.creator = ctx.accounts.creator.key();
fund.amount_raised = 0;
fund.dealine_set = false;
Ok(())
}

Impact

Funds with zero goals could confuse contributors and potentially be used to trick users by making it unclear when the funding target has been reached.

POC

Add to tests/rustfund.ts:

//audit LOW - No Fund Goal Validation
it("Can create a fund with zero goal", async () => {
const zeroGoalFundName = "Zero Goal Fund";
const [zeroGoalFundPDA] = await PublicKey.findProgramAddress(
[Buffer.from(zeroGoalFundName), creator.publicKey.toBuffer()],
program.programId
);
​
await program.methods
.fundCreate(zeroGoalFundName, description, new anchor.BN(0))
.accounts({
fund: zeroGoalFundPDA,
creator: creator.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
​
const fund = await program.account.fund.fetch(zeroGoalFundPDA);
console.log(`Created fund with goal amount: ${fund.goal.toString()}`);
});

Output:

========================================
šŸ› BUG REPORT [LOW]: No Fund Goal Validation
----------------------------------------
Description: The program allows creating funds with zero or invalid goal amounts
Evidence: Created fund with goal amount: 0
========================================

Tools Used

  • Anchor framework for testing

  • Manual code review

Recommendations

Add validation to ensure the goal is greater than zero:

pub fn fund_create(ctx: Context<FundCreate>, name: String, description: String, goal: u64) -> Result<()> {
// Validate goal is greater than zero
+ if goal == 0 {
+ return Err(ErrorCode::InvalidGoalAmount.into());
}
let fund = &mut ctx.accounts.fund;
fund.name = name;
fund.description = description;
fund.goal = goal;
fund.deadline = 0;
fund.creator = ctx.accounts.creator.key();
fund.amount_raised = 0;
fund.dealine_set = false;
Ok(())
}
Updates

Appeal created

bube Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

No minimal amount for the `goal` in `fund_create` is greater than 0

If the `goal` is 0, the campaign goal is achieved immediately and the creator can withdraw the contributors funds. The contributors select themself which campaign to support, therefore I think Low severity is appropriate here.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.