Skip to content

Commit

Permalink
fix: tracers, add bor fee log in results
Browse files Browse the repository at this point in the history
  • Loading branch information
anshalshukla committed Aug 26, 2024
1 parent ab2db59 commit 68d8614
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 153 deletions.
27 changes: 13 additions & 14 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
gasRefund = st.refundGas(params.RefundQuotientEIP3529)
}

effectiveTip := uint256.NewInt(msg.GasPrice.Uint64())
effectiveTip := msg.GasPrice

if rules.IsLondon {
effectiveTip = cmath.BigMinUint256(cmath.BigIntToUint256Int(msg.GasTipCap), new(uint256.Int).Sub(cmath.BigIntToUint256Int(msg.GasFeeCap), cmath.BigIntToUint256Int(st.evm.Context.BaseFee)))
effectiveTip = cmath.BigMin(msg.GasTipCap, new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee))
}

// TODO(raneet10): Double check. We might want to inculcate this fix in a separate condition
Expand All @@ -518,27 +518,26 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
// st.state.AddBalance(st.evm.Context.Coinbase, fee)
// }

fee := new(uint256.Int).SetUint64(st.gasUsed())
fee.Mul(fee, effectiveTip)
amount := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)

var burnAmount *uint256.Int
var burnAmount *big.Int

var burntContractAddress common.Address

if rules.IsLondon {
burntContractAddress = common.HexToAddress(st.evm.ChainConfig().Bor.CalculateBurntContract(st.evm.Context.BlockNumber.Uint64()))
burnAmount = new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasUsed()), cmath.BigIntToUint256Int(st.evm.Context.BaseFee))
burnAmount = new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)

if !st.noFeeBurnAndTip {
st.state.AddBalance(burntContractAddress, burnAmount, tracing.BalanceChangeTransfer)
st.state.AddBalance(burntContractAddress, uint256.NewInt(burnAmount.Uint64()), tracing.BalanceChangeTransfer)
}
}

if !st.noFeeBurnAndTip {
st.state.AddBalance(st.evm.Context.Coinbase, fee, tracing.BalanceIncreaseRewardTransactionFee)
st.state.AddBalance(st.evm.Context.Coinbase, uint256.NewInt(amount.Uint64()), tracing.BalanceIncreaseRewardTransactionFee)

// add the coinbase to the witness iff the fee is greater than 0
if rules.IsEIP4762 && fee.Sign() != 0 {
if rules.IsEIP4762 && amount.Sign() != 0 {
st.evm.AccessEvents.BalanceGas(st.evm.Context.Coinbase, true)
}

Expand All @@ -553,11 +552,11 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
msg.From,
st.evm.Context.Coinbase,

fee.ToBig(),
amount,
input1.ToBig(),
input2.ToBig(),
output1.Sub(output1, fee.ToBig()),
output2.Add(output2, fee.ToBig()),
output1.Sub(output1, amount),
output2.Add(output2, amount),
)
}

Expand All @@ -567,9 +566,9 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
Err: vmerr,
ReturnData: ret,
SenderInitBalance: input1.ToBig(),
FeeBurnt: burnAmount.ToBig(),
FeeBurnt: burnAmount,
BurntContractAddress: burntContractAddress,
FeeTipped: fee.ToBig(),
FeeTipped: amount,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func TestInternals(t *testing.T) {
byte(vm.LOG0),
},
tracer: mkTracer("callTracer", json.RawMessage(`{ "withLog": true }`)),
want: fmt.Sprintf(`{"from":"%s","gas":"0x13880","gasUsed":"0x5b9e","to":"0x00000000000000000000000000000000deadbeef","input":"0x","logs":[{"address":"0x00000000000000000000000000000000deadbeef","topics":[],"data":"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","position":"0x0"}],"value":"0x0","type":"CALL"}`, originHex),
want: fmt.Sprintf(`{"from":"%s","gas":"0x13880","gasUsed":"0x5b9e","to":"0x00000000000000000000000000000000deadbeef","input":"0x","logs":[{"address":"0x00000000000000000000000000000000deadbeef","topics":[],"data":"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","position":"0x0"},{"address":"0x0000000000000000000000000000000000001010","topics":["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63","0x0000000000000000000000000000000000000000000000000000000000001010","0x00000000000000000000000071562b71999873db5b286df957af199ec94617f7","0x0000000000000000000000000000000000000000000000000000000000000000"],"data":"0x0000000000000000000000000000000000000000000000000000000000005b9e0000000000000000000000000000000000000000000000000001c6bf5263400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c6bf5262e4620000000000000000000000000000000000000000000000000000000000005b9e","position":"0x0"}],"value":"0x0","type":"CALL"}`, originHex),
},
{
// Leads to OOM on the prestate tracer
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/internal/tracetest/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestSupplySelfdestruct(t *testing.T) {
// 2. Test post Cancun
cancunBlock := big.NewInt(0)
gspec.Config.ShanghaiBlock = cancunBlock
gspec.Config.ShanghaiBlock = cancunBlock
gspec.Config.CancunBlock = cancunBlock

postCancunOutput, postCancunChain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,5 @@
"tracerConfig": {
"withLog": true
},
"result": {
"from": "0x4f5777744b500616697cb655dcb02ee6cd51deb5",
"gas": "0x33085",
"gasUsed": "0x1a9e5",
"to": "0x200edd17f30485a8735878661960cd7a9a95733f",
"input": "0xba51a6df0000000000000000000000000000000000000000000000000000000000000000",
"output": "0xba51a6df00000000000000000000000000000000000000000000000000000000",
"calls": [
{
"from": "0x200edd17f30485a8735878661960cd7a9a95733f",
"gas": "0x2c263",
"gasUsed": "0x1b0e4",
"to": "0x273930d21e01ee25e4c219b63259d214872220a2",
"input": "0xba51a6df0000000000000000000000000000000000000000000000000000000000000000",
"logs": [
{
"address": "0x200edd17f30485a8735878661960cd7a9a95733f",
"topics": [
"0xe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda"
],
"data": "0x0000000000000000000000004f5777744b500616697cb655dcb02ee6cd51deb5be96016bb57376da7a6d296e0a405ee1501778227dfa604df0a81cb1ae018598",
"position": "0x0"
},
{
"address": "0x200edd17f30485a8735878661960cd7a9a95733f",
"topics": [
"0xacbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da"
],
"data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"position": "0x0"
}
],
"value": "0x8ac7230489e80000",
"type": "CALLCODE"
}
],
"value": "0x8ac7230489e80000",
"type": "CALL"
}
"result": {"from":"0x4f5777744b500616697cb655dcb02ee6cd51deb5","gas":"0x33085","gasUsed":"0x1a9e5","to":"0x200edd17f30485a8735878661960cd7a9a95733f","input":"0xba51a6df0000000000000000000000000000000000000000000000000000000000000000","output":"0xba51a6df00000000000000000000000000000000000000000000000000000000","calls":[{"from":"0x200edd17f30485a8735878661960cd7a9a95733f","gas":"0x2c263","gasUsed":"0x1b0e4","to":"0x273930d21e01ee25e4c219b63259d214872220a2","input":"0xba51a6df0000000000000000000000000000000000000000000000000000000000000000","logs":[{"address":"0x200edd17f30485a8735878661960cd7a9a95733f","topics":["0xe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda"],"data":"0x0000000000000000000000004f5777744b500616697cb655dcb02ee6cd51deb5be96016bb57376da7a6d296e0a405ee1501778227dfa604df0a81cb1ae018598","position":"0x0"},{"address":"0x200edd17f30485a8735878661960cd7a9a95733f","topics":["0xacbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da"],"data":"0x0000000000000000000000000000000000000000000000000000000000000000","position":"0x0"}],"value":"0x8ac7230489e80000","type":"CALLCODE"}],"logs":[{"address":"0x0000000000000000000000000000000000001010","topics":["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63","0x0000000000000000000000000000000000000000000000000000000000001010","0x0000000000000000000000004f5777744b500616697cb655dcb02ee6cd51deb5","0x000000000000000000000000f8b483dba2c3b7176a3da549ad41a48bb3121069"],"data":"0x00000000000000000000000000000000000000000000000000119b54eb98e126000000000000000000000000000000000000000000000000b0983f1b83eec29000000000000000000000000000000000000000000000016969a0ba2c2d384d07000000000000000000000000000000000000000000000000b086a3c69855e16a00000000000000000000000000000000000000000000016969b2558118d12e2d","position":"0x1"}],"value":"0x8ac7230489e80000","type":"CALL"}
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@
"type": "CALL"
}
],
"logs": [
{
"address": "0x0000000000000000000000000000000000001010",
"topics": [
"0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63",
"0x0000000000000000000000000000000000000000000000000000000000001010",
"0x0000000000000000000000003de712784baf97260455ae25fb74f574ec9c1add",
"0x00000000000000000000000061c808d82a3ac53231750dadc13c777b59310bd9"
],
"data": "0x000000000000000000000000000000000000000000000000000b9e774e8d580000000000000000000000000000000000000000000000000023c8352f33854625000000000000000000000000000000000000000000000090a7af5d475598456100000000000000000000000000000000000000000000000023bc96b7e4f7ee25000000000000000000000000000000000000000000000090a7bafbbea4259d61",
"position": "0x8"
}
],
"value": "0x0",
"type": "CALL"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,34 @@
"type": "CALL"
}
],
"logs":[
"logs": [
{
"address": "0xf631e3b3aafa084bc51c714825aacf505d2059be",
"topics": ["0x1f28d876aff267c3302a63cd25ebcca53e6f60691049df42275b6d06ab455c67"],
"data":"0x55bc8431ce52389ac668a9b14a0943290cb7263732251186e960bc8b249b5f32000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000030d41000000000000000000000000000000000000000000000000000000000000000355524c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d455448584254292e726573756c742e58455448585842542e632e300000000000000000000000000000000000000000",
"position":"0x3"
"topics": [
"0x1f28d876aff267c3302a63cd25ebcca53e6f60691049df42275b6d06ab455c67"
],
"data": "0x55bc8431ce52389ac668a9b14a0943290cb7263732251186e960bc8b249b5f32000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000030d41000000000000000000000000000000000000000000000000000000000000000355524c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d455448584254292e726573756c742e58455448585842542e632e300000000000000000000000000000000000000000",
"position": "0x3"
}
],
"value": "0x0",
"type": "CALL"
}
],
"logs": [
{
"address": "0x0000000000000000000000000000000000001010",
"topics": [
"0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63",
"0x0000000000000000000000000000000000000000000000000000000000001010",
"0x0000000000000000000000000047a8033cc6d6ca2ed5044674fd421f44884de8",
"0x000000000000000000000000e48430c4e88a929bba0ee3dce284866a9937b609"
],
"data": "0x000000000000000000000000000000000000000000000000006a8fb3d104cc0000000000000000000000000000000000000000000000000044f5ced08fe37cf70000000000000000000000000000000000000000000000026758774d51d8677a000000000000000000000000000000000000000000000000448b3f1cbedeb0f700000000000000000000000000000000000000000000000267c3070122dd337a",
"position": "0x6"
}
],
"value": "0x0",
"type": "CREATE"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,19 @@
"type": "CALL"
}
],
"logs": [
{
"address": "0x0000000000000000000000000000000000001010",
"topics": [
"0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63",
"0x0000000000000000000000000000000000000000000000000000000000001010",
"0x000000000000000000000000be3ae5cb97c253dda67181c6e34e43f5c275e08b",
"0x000000000000000000000000ea674fdde714fd979de3edf0f56aa9716b898ec8"
],
"data": "0x00000000000000000000000000000000000000000000000000e25384e63aa60000000000000000000000000000000000000000000000000167d285b38143c04f00000000000000000000000000000000000000000000004ab3566739e7b2437100000000000000000000000000000000000000000000000166f0322e9b091a4f00000000000000000000000000000000000000000000004ab438babecdece971",
"position": "0x23"
}
],
"value": "0x0",
"type": "CALL"
}
Expand Down
Loading

0 comments on commit 68d8614

Please sign in to comment.