5

I have a smart contract on bsc network and I want to reduce my gas used.

I use chi gas token based on this code:

modifier discountCHI {
    uint256 gasStart = gasleft();
    _;
    uint256 gasSpent = 21000 + gasStart — gasleft() + 16 *
                       msg.data.length;
    chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41947); }

This code will save 50% of my gas used. I want to know why 50% and can I use more chi token to reduce more gas used?

1 Answer 1

4
+100

Gas refund cap is a limitation of the Ethereum protocol.

Since London update the 1/2 gas cost refund cap was changed to 1/5 max refund.

go-ethereum/params/protocol_params.go -

// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
RefundQuotient        uint64 = 2
RefundQuotientEIP3529 uint64 = 5

go-ethereum/core/state_transition.go -

if !rules.IsLondon {
    // Before EIP-3529: refunds were capped to gasUsed / 2
    st.refundGas(params.RefundQuotient)
} else {
    // After EIP-3529: refunds are capped to gasUsed / 5
    st.refundGas(params.RefundQuotientEIP3529)
}

explained in EIP-3529 -

Remove gas refunds for SELFDESTRUCT, and reduce gas refunds for SSTORE to a lower level where the refunds are still substantial, but they are no longer high enough for current “exploits” of the refund mechanism to be viable.

This means you can't burn more CHI to get further refund.

1
  • 2
    limitation by go-ethereum to be specific it is limitation by Ethereum protocol. There are various other node software applications outside geth. Commented Jun 1, 2022 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.