There is a weakness in the createTradingAccount
function in the TradingAccountBranch
contract that allows invalid input to be received, causing the contract to revert
and fail to create a new trading account. This flaw occurs due to insufficient validation of the referralCode
length.
In the createTradingAccount
function in the TradingAccountBranch
contract, it was discovered that the referralCode
input was not validated properly regarding its length. This condition causes the contract to revert
when it receives a referralCode
with a length of more than 32 bytes or is empty.
This weakness may result in the contract being unable to create a new trading account with a particular referralCode
, which may ultimately compromise user experience and trust in the platform. In addition, Denial of Service (DoS) attacks can be carried out by sending invalid referralCode
input repeatedly.
Manual review
Foundry
it is recommended to improve the input validation in the createTradingAccount
function. Make sure the referralCode
length is validated correctly before continuing the function execution.
Fuzzing with Foundry:
forge test --match-path test/TradingAccountBranchTest.t.sol
[⠒] Compiling...
[⠢] Compiling 1 files with Solc 0.8.25
[⠆] Solc 0.8.25 finished in 2.03s
Compiler run successful!
proptest: Aborting shrinking after the PROPTEST_MAX_SHRINK_ITERS environment variable or ProptestConfig.max_shrink_iters iterations (set 0 t
o a large(r) value to shrink more; current configuration: 0 iterations)
Ran 5 tests for test/TradingAccountBranchTest.t.sol:TradingAccountBranchTest
[FAIL. Reason: revert: createTradingAccount failed; counterexample: calldata=0x4dd85ca700000000000000000000000000000000000000000000000000000
00000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002196 args=[0x0000000000000000000000000000000000000000000000000000000000002196, true]] testFuzzingCreateTradingAccount(bytes,bool) (runs: 0, μ: 0, ~: 0) [PASS] testFuzzingDepositMargin(uint128,address,uint256) (runs: 1001, μ: 10702, ~: 10702)
[PASS] testFuzzingGetAccountEquityUsd(uint128) (runs: 1001, μ: 9895, ~: 9895)
[PASS] testFuzzingGetAccountLeverage(uint128) (runs: 1001, μ: 9872, ~: 9872)
[PASS] testFuzzingWithdrawMargin(uint128,address,uint256) (runs: 1001, μ: 10745, ~: 10745)
Suite result: FAILED. 4 passed; 1 failed; 0 skipped; finished in 51.66ms (178.66ms CPU time)
Ran 1 test suite in 53.45ms (51.66ms CPU time): 4 tests passed, 1 failed, 0 skipped (5 total tests)
Failing tests:
Encountered 1 failing test in test/TradingAccountBranchTest.t.sol:TradingAccountBranchTest
[FAIL. Reason: revert: createTradingAccount failed; counterexample: calldata=0x4dd85ca700000000000000000000000000000000000000000000000000000
00000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002196 args=[0x0000000000000000000000000000000000000000000000000000000000002196, true]] testFuzzingCreateTradingAccount(bytes,bool) (runs: 0, μ: 0, ~: 0)
Encountered a total of 1 failing tests, 4 tests succeeded
Test with Foundry:
forge test --match-path test/TradingAccountBranchTest.t.sol
[⠒] Compiling...
[⠆] Compiling 1 files with Solc 0.8.25
[⠰] Solc 0.8.25 finished in 2.06s
Compiler run successful!
Ran 2 tests for test/TradingAccountBranchTest.t.sol:TradingAccountBranchTest
[FAIL. Reason: Unexpected revert reason for long referral code: Unknown != Referral code too long] testReferralCodeLength() (gas: 81009)
[FAIL. Reason: revert: Unexpected revert reason: Unknown] testValidReferralCode() (gas: 77494)
Suite result: FAILED. 0 passed; 2 failed; 0 skipped; finished in 2.28ms (630.40µs CPU time)
Ran 1 test suite in 22.95ms (2.28ms CPU time): 0 tests passed, 2 failed, 0 skipped (2 total tests)
Failing tests:
Encountered 2 failing tests in test/TradingAccountBranchTest.t.sol:TradingAccountBranchTest
[FAIL. Reason: Unexpected revert reason for long referral code: Unknown != Referral code too long] testReferralCodeLength() (gas: 81009)
[FAIL. Reason: revert: Unexpected revert reason: Unknown] testValidReferralCode() (gas: 77494)
Encountered a total of 2 failing tests, 0 tests succeeded
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.