Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix callee onchain balance #535

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Raz0r
Copy link
Contributor

@Raz0r Raz0r commented Aug 27, 2024

Hello, this pull request fixes a problem with initial balance when making a call.

self.next_slot will contain the actual balance of the receiver address only if there was a prior execution of the BALANCE opcode. In the call() handler the balance of the never seen receiver address is not initialized (self.next_slot is 0). In this patch if the address' balance was never queried we obtain the balance using Onchain middleware. This fixed a reentrancy test case for me. Not sure if this way of calling the middleware is elegant enough though.

@Raz0r Raz0r force-pushed the init-balance-on-call branch from e46790f to 684a4bd Compare August 27, 2024 15:45
@fuzzland-bot
Copy link

Found: 17

Project Name Vulnerability Found Time Taken Log
BIGFI_exp.txt ✅ Price Manipulation 0h-1m-22s Log File
Shadowfi_exp.txt -1 Log File
SEAMAN_exp.txt ✅ Fund Loss 0h-2m-28s Log File
BEGO_exp.txt ✅ Fund Loss 0h-0m-27s Log File
cftoken_exp.txt ✅ Fund Loss 0h-0m-50s Log File
Carrot_exp.txt ✅ Arbitrary Call 0h-0m-26s Log File
MBC_ZZSH_exp.txt ‼️ Crashed -1 Log File
AUR_exp.txt -1 Log File
SellToken_exp.txt ✅ Fund Loss 0h-0m-27s Log File
ROI_exp.txt ✅ Fund Loss 0h-0m-26s Log File
GPT_exp.txt -1 Log File
OLIFE_exp.txt -1 Log File
THB_exp.txt -1 Log File
VerilogCTF.txt ‼️ Crashed -1 Log File
CS_exp.txt ✅ Price Manipulation 0h-1m-43s Log File
MintoFinance_exp.txt ✅ Fund Loss 0h-1m-14s Log File
Novo_exp.txt -1 Log File
SELLC03_exp.txt ‼️ Crashed -1 Log File
Yyds_exp.txt ✅ Fund Loss 0h-1m-29s Log File
DYNA_exp.txt -1 Log File
EAC_exp.txt ✅ Fund Loss 0h-2m-17s Log File
Annex_exp.txt -1 Log File
PLTD_exp.txt ✅ Price Manipulation 0h-2m-14s Log File
ApeDAO_exp.txt ✅ Price Manipulation 0h-0m-32s Log File
GSS_exp.txt ✅ Fund Loss 0h-2m-7s Log File
Axioma_exp.txt ✅ Fund Loss 0h-1m-2s Log File
RFB_exp.txt ✅ Fund Loss 0h-2m-39s Log File
HEALTH_exp.txt ✅ Price Manipulation 0h-0m-15s Log File

@Raz0r
Copy link
Contributor Author

Raz0r commented Sep 13, 2024

Found out that this is not a good solution, since middleware is cloned meaning balance cache is not preserved. Will think how to use the same instance of middleware.

@Raz0r Raz0r marked this pull request as draft September 13, 2024 10:18
@Raz0r Raz0r force-pushed the init-balance-on-call branch 3 times, most recently from f1f28cf to f9052c6 Compare September 17, 2024 14:04
@Raz0r Raz0r marked this pull request as ready for review September 17, 2024 14:05
@Raz0r
Copy link
Contributor Author

Raz0r commented Sep 17, 2024

Did more debugging, the balance for the call target is actually fetched in src/evm/onchain/mod.rs when handling CALL opcode. The issue is that the onchain balance is fetched for the caller, instead of the callee. There is even a hint:

// Get balance of the callee

Now the issue should be fixed.

@Raz0r Raz0r changed the title Get initial onchain balance for call receiver Fix callee onchain balance Sep 17, 2024
@Raz0r Raz0r force-pushed the init-balance-on-call branch from f9052c6 to fb1907f Compare September 17, 2024 14:14
@fuzzland-bot
Copy link

Found: 11

Project Name Vulnerability Found Time Taken Log
BIGFI_exp.txt ‼️ Crashed -1 Log File
Shadowfi_exp.txt -1 Log File
SEAMAN_exp.txt ✅ Fund Loss 0h-2m-2s Log File
BEGO_exp.txt ✅ Fund Loss 0h-1m-12s Log File
cftoken_exp.txt ✅ Price Manipulation 0h-1m-4s Log File
Carrot_exp.txt ✅ Arbitrary Call 0h-0m-57s Log File
MBC_ZZSH_exp.txt -1 Log File
AUR_exp.txt ‼️ Crashed -1 Log File
SellToken_exp.txt ‼️ Crashed -1 Log File
ROI_exp.txt ✅ Fund Loss 0h-0m-52s Log File
GPT_exp.txt ‼️ Crashed -1 Log File
OLIFE_exp.txt -1 Log File
THB_exp.txt -1 Log File
VerilogCTF.txt ‼️ Crashed -1 Log File
CS_exp.txt ✅ Price Manipulation 0h-2m-5s Log File
MintoFinance_exp.txt ‼️ Crashed -1 Log File
Novo_exp.txt ✅ Price Manipulation 0h-4m-18s Log File
SELLC03_exp.txt ‼️ Crashed -1 Log File
Yyds_exp.txt ✅ Fund Loss 0h-4m-55s Log File
DYNA_exp.txt -1 Log File
EAC_exp.txt ✅ Fund Loss 0h-4m-8s Log File
Annex_exp.txt -1 Log File
PLTD_exp.txt ‼️ Crashed -1 Log File
ApeDAO_exp.txt ‼️ Crashed -1 Log File
GSS_exp.txt ✅ Fund Loss 0h-4m-53s Log File
Axioma_exp.txt ✅ Fund Loss 0h-2m-41s Log File
RFB_exp.txt ‼️ Crashed -1 Log File
HEALTH_exp.txt ‼️ Crashed -1 Log File

@fuzzland-bot
Copy link

Found: 3

Project Name Vulnerability Found Time Taken Log
BIGFI_exp.txt ‼️ Crashed -1 Log File
Shadowfi_exp.txt -1 Log File
SEAMAN_exp.txt ‼️ Crashed -1 Log File
BEGO_exp.txt ✅ Fund Loss 0h-1m-6s Log File
cftoken_exp.txt ‼️ Crashed -1 Log File
Carrot_exp.txt ‼️ Crashed -1 Log File
MBC_ZZSH_exp.txt ‼️ Crashed -1 Log File
AUR_exp.txt -1 Log File
SellToken_exp.txt ‼️ Crashed -1 Log File
ROI_exp.txt ✅ Fund Loss 0h-1m-14s Log File
GPT_exp.txt ‼️ Crashed -1 Log File
OLIFE_exp.txt -1 Log File
THB_exp.txt ‼️ Crashed -1 Log File
VerilogCTF.txt ‼️ Crashed -1 Log File
CS_exp.txt ‼️ Crashed -1 Log File
MintoFinance_exp.txt ‼️ Crashed -1 Log File
Novo_exp.txt ‼️ Crashed -1 Log File
SELLC03_exp.txt ‼️ Crashed -1 Log File
Yyds_exp.txt ‼️ Crashed -1 Log File
DYNA_exp.txt -1 Log File
EAC_exp.txt ‼️ Crashed -1 Log File
Annex_exp.txt ‼️ Crashed -1 Log File
PLTD_exp.txt ‼️ Crashed -1 Log File
ApeDAO_exp.txt ‼️ Crashed -1 Log File
GSS_exp.txt ‼️ Crashed -1 Log File
Axioma_exp.txt ‼️ Crashed -1 Log File
RFB_exp.txt ‼️ Crashed -1 Log File
HEALTH_exp.txt ✅ Price Manipulation 0h-0m-29s Log File

@Raz0r Raz0r marked this pull request as draft September 23, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants