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

feat: optimize evm.charge_gas #1261

Closed
Tracked by #1263
ClementWalter opened this issue Jul 12, 2024 · 0 comments · Fixed by #1323
Closed
Tracked by #1263

feat: optimize evm.charge_gas #1261

ClementWalter opened this issue Jul 12, 2024 · 0 comments · Fixed by #1323
Assignees

Comments

@ClementWalter
Copy link
Member

ClementWalter commented Jul 12, 2024

Feature Request

Based on the analysis from #1256 , I think (to be tested) that charge_gas could be cheaper by doing

func charge_gas{range_check_ptr}(self: model.EVM*, amount: felt) -> model.EVM* {
    let gas_left = self.gas_left - amount;
    let enough_gas = is_nn(gas_left);

    if (enough_gas != 0) {
        return new model.EVM(
            message=self.message,
            return_data_len=self.return_data_len,
            return_data=self.return_data,
            program_counter=self.program_counter,
            stopped=self.stopped,
            gas_left=gas_left,
            gas_refund=self.gas_refund,
            reverted=self.reverted,
        );
    }
    let (revert_reason_len, revert_reason) = Errors.outOfGas(self.gas_left, amount);
    return new model.EVM(
        message=self.message,
        return_data_len=revert_reason_len,
        return_data=revert_reason,
        program_counter=self.program_counter,
        stopped=TRUE,
        gas_left=0,
        gas_refund=self.gas_refund,
        reverted=Errors.EXCEPTIONAL_HALT,
    );
}

The is_nn should also be inline to avoid the extra call steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants