Hawk High

First Flight #39
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Batch fund transfer based on share could lead to dust funds

Summary

When transferring funds based on shares, there may be residual "dust" funds that are not handled correctly.

Impact

Small amounts of funds may be sent to actors, leading to confusion and minimal loss of funds.

Proof of Concept

Let's assume:

  • bursary = 1e18 (USDC)

  • TEACHER_WAGE = 35 (35%)

  • PRINCIPAL_WAGE = 5 (5%)

  • PRECISION = 100

  • totalTeachers = 3

Calculations:

  1. Calculate total teacher pay:

totalTeacherPay = (bursary * TEACHER_WAGE) / PRECISION
totalTeacherPay = 3500000000000000000000 [3.5e21]
  1. Calculate payPerTeacher:

payPerTeacher = totalTeacherPay / totalTeachers
payPerTeacher = 1166666666666666666666 [1.166e21]
  1. Calculate principalPay:

principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION
principalPay = 500000000000000000000 [5e20]
  1. Calculate remaining bursary after wages transfered:

bursaryAfterUpgrade = bursary - principalPay - (payPerTeacher * totalTeachers)
bursaryAfterUpgrade = 6000000000000000000002 [6e21]
  1. Calculate total pay after upgrade:

bursaryAfterUpgrade = bursaryAfterUpgrade + principalPay + (payPerTeacher * totalTeachers)
bursaryAfterUpgrade = 10000000000000000000002 [1e22]
  1. Calculate Dust:

dust = bursaryAfterUpgrade - bursary
dust = 2

function test_audit_calculation_wages_send_dust() public pure {
// Setup calculation values
uint256 BURSARY = 10000000000000000000000; // 30e21
uint256 TEACHER_WAGE = 35;
uint256 PRINCIPAL_WAGE = 5;
uint256 PRECISION = 100;
uint256 NUMBER_OF_TEACHERS = 3;
// Compute teacher and principal wages
uint256 totalTeacherPay = (BURSARY * TEACHER_WAGE) / PRECISION;
uint256 payPerTeacher = totalTeacherPay / NUMBER_OF_TEACHERS;
uint256 principalPay = (BURSARY * PRINCIPAL_WAGE) / PRECISION;
console2.log("Bursary: ", BURSARY);
console2.log("Principal pay: ", principalPay);
console2.log("Total teacher pay: ", totalTeacherPay);
console2.log("Pay per teacher: ", payPerTeacher);
// Get the bursary after paying the principal and teachers
uint256 bursaryAfterPay = BURSARY - principalPay - (payPerTeacher * NUMBER_OF_TEACHERS);
console2.log("Bursary after pay: ", bursaryAfterPay);
// Sum the principal and teacher wages with the bursary after pay
uint256 totalPay = principalPay + totalTeacherPay + bursaryAfterPay;
console2.log("Total pay after upgrade: ", totalPay);
assert(totalPay > BURSARY);
uint256 dust = totalPay - BURSARY;
console2.log("Dust: ", dust);
}

Tools Used

Manual review.

Recommendations

Ensure the last transfer handles all residual funds to avoid dust.

Updates

Lead Judging Commences

yeahchibyke Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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