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

TOB-FUEL-12: Call receipt created with incorrect gas amount #559

Closed
xgreenx opened this issue Aug 28, 2023 · 1 comment
Closed

TOB-FUEL-12: Call receipt created with incorrect gas amount #559

xgreenx opened this issue Aug 28, 2023 · 1 comment
Labels
audit-report Issue from the audit report

Comments

@xgreenx
Copy link
Collaborator

xgreenx commented Aug 28, 2023

Description

While executing a call, the interpreter forwards the minimum of the context gas, cgas, and the amount of gas the call requests to be forwarded, amount_of_gas_to_forward. This is reflected in the system register’s context gas value but not in the receipt created for the call. The receipt incorrectly uses amount_of_gas_to_forward which will show the call had more gas available to it than in practice if cgas is less than amount_of_gas_to_forward.

Figure 12.1: The receipt creation of the prepare_call function

let forward_gas_amount = cmp::min(
    *self.registers.system_registers.cgas,
    self.params.amount_of_gas_to_forward,
);
// subtract gas
*self.registers.system_registers.cgas =
    arith::sub_word(*self.registers.system_registers.cgas, forward_gas_amount)?;
*frame.context_gas_mut() = *self.registers.system_registers.cgas;
*frame.global_gas_mut() = *self.registers.system_registers.ggas;
[...]
*self.registers.system_registers.cgas = forward_gas_amount;
let receipt = Receipt::call(
    id,
    *frame.to(),
    self.params.amount_of_coins_to_forward,
    *frame.asset_id(),
    self.params.amount_of_gas_to_forward,
    frame.a(),

Exploit Scenario

An alternative Fuel implementation which returns the correct panic code cannot reach consensus or sync with the existing Fuel implementation as the block headers are different.

Recommendations

Short term, use forward_gas_amount for the receipt’s gas field.
Long term, perform additional testing of the gas accounting of call frames and the receipts created by them.

@xgreenx xgreenx added the audit-report Issue from the audit report label Aug 28, 2023
@xgreenx
Copy link
Collaborator Author

xgreenx commented Aug 28, 2023

Fixed with #503

@xgreenx xgreenx closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Issue from the audit report
Projects
None yet
Development

No branches or pull requests

1 participant