Skip to content

Gas cap for debit/credit#58

Merged
gastonponti merged 12 commits intomainfrom
gastonponti/system-txs-gas-cap
Aug 15, 2025
Merged

Gas cap for debit/credit#58
gastonponti merged 12 commits intomainfrom
gastonponti/system-txs-gas-cap

Conversation

@gastonponti
Copy link
Contributor

@gastonponti gastonponti commented Aug 12, 2025

[Depends on #60]

Implementation of the gas cap for debit/credit with a cip64 tx

Another possible solution was to reimplement the SystemCallEvm and change the transact_system_call to receive the gas_limit (or even create a new one), but I wanted to avoid changing more files from upstream if the we had a different solution that it's also clean

Also:

  • cleaner cip64 related variables
  • Change the feeCurrencyContext to use the intrinsic gas as a u64 and not a U256 (everything was using it as a u64)

Fixes https://github.com/celo-org/celo-blockchain-planning/issues/1201

Copy link
Contributor

@karlb karlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantics look fine. Just a bunch of stylistic suggestions. I'll give it a second read later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a saturating_sub here? An underflow is an error that we ignore this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, that has to be validated before. In this instance you already know that the effective_gas_price is at least the base_fee.
I'll double check if that's addressed before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, nice. This made me found a possible bug. As I said, that validation is performed before. But for every type except the cip64.
So I have to add that validation, but in this place it would be safe to use it like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#60
This PR should cover that validatio

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can find a tx-related place to put this information instead of the block env. I'll see if I find something to suggest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as a new field in the CeloTransaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to do it. As the tx is not mutable in the context, I had to clone and set it a few times, but I think it keeps everything cleaner

@gastonponti gastonponti force-pushed the gastonponti/system-txs-gas-cap branch from 93e5102 to 7cc9257 Compare August 14, 2025 20:20
Comment on lines +341 to +348
// Store CIP64 transaction information by modifying the transaction
let mut tx = evm.ctx().tx().clone();
tx.cip64_tx_info = Some(Cip64Info {
actual_intrinsic_gas_used: gas_used,
logs_pre: logs,
logs_post: Vec::new(),
});
evm.ctx().set_tx(tx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently the tx is not meant to be mutated or we would have a tx_mut_ref in the ContextTr. Not ideal, but I still like it better than putting it into the block context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same. It's not forcing everything to be mutable at least, so we know that is only happening for this. But I agree that is cleaner than having info of the executed tx (only for one type) in the block_env

@gastonponti gastonponti merged commit 74e2388 into main Aug 15, 2025
12 checks passed
@gastonponti gastonponti deleted the gastonponti/system-txs-gas-cap branch August 15, 2025 15:20
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.

3 participants

Comments