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

Incorrect GasRefund in debug_traceCall with custom tracer #25650

Closed
quickchase opened this issue Aug 31, 2022 · 1 comment · Fixed by #25661
Closed

Incorrect GasRefund in debug_traceCall with custom tracer #25650

quickchase opened this issue Aug 31, 2022 · 1 comment · Fixed by #25661

Comments

@quickchase
Copy link

quickchase commented Aug 31, 2022

System information

Geth version: 1.10.23
OS & Version: Linux

Expected behaviour

GasRefund should be greater than 0

Actual behaviour

{"jsonrpc":"2.0","id":"1","result":{"refund":0,"gasUsed":140031}}

Steps to reproduce the behaviour

Using the following request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "debug_traceCall",
    "params": [
        {
            "from": "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
            "data": "0xe449022e0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000033f473f10467f04eaa00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000060594a405d53811d3bc4766596efd80fd545a270",
            "value": "0xDE0B6B3A7640000",
            "to": "0x1111111254fb6c44bac0bed2854e76f90643097d"
        },
        "latest",
        {
            "tracer": "{\n    accumulatedGasRefund: 0,\n\n    fault: function (log, db, err) {\n    },\n\n    step: function (log, db) {\n        // SSTORE\n        if (log.op.toNumber() !== 0x55) {\n            return\n        }\n\n        this.accumulatedGasRefund = log.getRefund()\n    },\n\n    result: function (ctx, db) {\n        var gasUsed = ctx.gasUsed + ctx.intrinsicGas\n\n        var maxGasRefund = Math.trunc(gasUsed / 5)\n\n        var resultGasRefund = Math.min(this.accumulatedGasRefund, maxGasRefund)\n\n        return {\n  refund: resultGasRefund,gasUsed: ctx.gasUsed + ctx.intrinsicGas - resultGasRefund,\n        };\n    }\n\n}\n"
        }
    ]
}
@holiman
Copy link
Contributor

holiman commented Sep 1, 2022

{
    accumulatedGasRefund: 0,

    fault: function (log, db, err) {
    },

    step: function (log, db) {
        // SSTORE
        if (log.op.toNumber() !== 0x55) {
            return
        }
        this.accumulatedGasRefund = log.getRefund()
    },

    result: function (ctx, db) {
        var gasUsed = ctx.gasUsed + ctx.intrinsicGas
        var maxGasRefund = Math.trunc(gasUsed / 5)
        var resultGasRefund = Math.min(this.accumulatedGasRefund, maxGasRefund)
        return {
  			refund: resultGasRefund,
			gasUsed: ctx.gasUsed + ctx.intrinsicGas - resultGasRefund,
        };
    }
}

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

Successfully merging a pull request may close this issue.

4 participants