Root Cause는 이체 후 sync() 함수를 실행하지 않고 pancake pair에게 세금 수수료를 이중으로 보상하는 결함 때문이다.
첫 번째 공격의 flow는 총 7번으로 진행된다.
Borrowing 1.4k WBNB with flash loan
Swapping 1k WBNB for 10.5k BRA
Transferring 10.5K $BRA to pancake pair (0x8f4ba1832611f0c364de7114bbff92ba676adf0e)
Invoking the skim() function, which further invokes the transfer() function of BRA contract to double collect the tax fee. The fee rate is 3%
Repeating step 4 for about 100 times. Before step 4, the BRA balance of the pair contract is 8.6K; while after step 4, the number reached 217.2k. Note that the 208.6k BRA was considered as the attacker's input for swapping
Swapping back 1.675 WBNB
Repaying 1.4K WBNB to the flash loan, and transferring the remaining 675 WBNB to attacker(0x67a909f2953fb1138bea4b60894b51291d2d0795)
The attacker then carried out a second attack transaction from which he stole funds worth 144 $WBNB tokens.
The exploiter finally transferred 819 $WBNB in total earnings to Attacker EOA address.
하나씩 같이 살펴보자.
일단 구분하기 쉽게 중요한 address를 색으로 나타내겠다
Attacker,ACA1, ACA2, Token
Step1
flashloan을 통해 1,4K WBNB을 빌렸다.
Step2
1k WBNB를 10.5k BRA로 바꿈
Step3
PancakeSwap pool에 BRA Token을 저장했다.
Step4
skim() 함수를 호출하여 BRA Contract의 transfer() 함수를 추가로 호출하여 세금을 이중으로 징수한다.
수수료는 3%이다.
Step5
한 번 skim()을 두 번 실행하면 8.6k이지만 약 100번 반복하면 217.2k로 증가한다. 그래서 208.6k BRA를 획득했다.