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

fix(evm): tx receipt proper marshalling #2101

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ for (1) ERC20 transfers with tokens that return false success values instead of
throwing an error and (2) ERC20 transfers with other operations that don't bring
about the expected resulting balance for the transfer recipient.
- [#2092](https://github.com/NibiruChain/nibiru/pull/2092) - feat(evm): add validation for wasm multi message execution
- [#2101](https://github.com/NibiruChain/nibiru/pull/2101) - fix(evm): tx receipt proper marshalling

#### Nibiru EVM | Before Audit 1 - 2024-10-18

Expand Down
36 changes: 33 additions & 3 deletions eth/rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package backend

import (
"encoding/json"
"fmt"
"math"
"math/big"
Expand Down Expand Up @@ -134,10 +135,39 @@
type TransactionReceipt struct {
gethcore.Receipt

ContractAddress *gethcommon.Address `json:"contractAddress,omitempty"`
ContractAddress *gethcommon.Address
From gethcommon.Address
To *gethcommon.Address
EffectiveGasPrice *big.Int
EffectiveGasPrice *hexutil.Big
}

// MarshalJSON is necessary because without it non gethcore.Receipt fields are omitted
func (r *TransactionReceipt) MarshalJSON() ([]byte, error) {
// Marshal / unmarshal gethcore.Receipt to produce map[string]interface{}
receiptJson, err := json.Marshal(r.Receipt)
if err != nil {
return nil, err
}

Check warning on line 150 in eth/rpc/backend/tx_info.go

View check run for this annotation

Codecov / codecov/patch

eth/rpc/backend/tx_info.go#L149-L150

Added lines #L149 - L150 were not covered by tests

var output map[string]interface{}
if err := json.Unmarshal(receiptJson, &output); err != nil {
return nil, err
}

Check warning on line 155 in eth/rpc/backend/tx_info.go

View check run for this annotation

Codecov / codecov/patch

eth/rpc/backend/tx_info.go#L154-L155

Added lines #L154 - L155 were not covered by tests

// Add extra (non gethcore.Receipt) fields:
if r.ContractAddress != nil && *r.ContractAddress != (gethcommon.Address{}) {
output["contractAddress"] = r.ContractAddress
}

Check warning on line 160 in eth/rpc/backend/tx_info.go

View check run for this annotation

Codecov / codecov/patch

eth/rpc/backend/tx_info.go#L159-L160

Added lines #L159 - L160 were not covered by tests
if r.From != (gethcommon.Address{}) {
output["from"] = r.From
}
if r.To != nil {
output["to"] = r.To
}
if r.EffectiveGasPrice != nil {
output["effectiveGasPrice"] = r.EffectiveGasPrice
}
return json.Marshal(output)
onikonychev marked this conversation as resolved.
Show resolved Hide resolved
}

// GetTransactionReceipt returns the transaction receipt identified by hash.
Expand Down Expand Up @@ -253,7 +283,7 @@
// tolerate the error for pruned node.
b.logger.Error("fetch basefee failed, node is pruned?", "height", res.Height, "error", err)
} else {
receipt.EffectiveGasPrice = dynamicTx.EffectiveGasPriceWeiPerGas(baseFeeWei)
receipt.EffectiveGasPrice = (*hexutil.Big)(dynamicTx.EffectiveGasPriceWeiPerGas(baseFeeWei))

Check warning on line 286 in eth/rpc/backend/tx_info.go

View check run for this annotation

Codecov / codecov/patch

eth/rpc/backend/tx_info.go#L286

Added line #L286 was not covered by tests
}
}
return &receipt, nil
Expand Down
4 changes: 2 additions & 2 deletions eth/rpc/backend/tx_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func (s *BackendSuite) TestReceiptMarshalJson() {
ContractAddress: nil,
From: evmtest.NewEthPrivAcc().EthAddr,
To: &toAddr,
EffectiveGasPrice: big.NewInt(1),
EffectiveGasPrice: (*hexutil.Big)(big.NewInt(1)),
}

jsonBz, err := json.Marshal(tr)
jsonBz, err := tr.MarshalJSON()
s.Require().NoError(err)

gethReceipt := new(gethcore.Receipt)
Expand Down
10 changes: 10 additions & 0 deletions evm-e2e/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
10 changes: 10 additions & 0 deletions evm-e2e/contracts/EventsEmitter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract EventsEmitter {
event TestEvent(address indexed sender, uint256 value);

function emitEvent(uint256 value) public {
emit TestEvent(msg.sender, value);
}
}
31 changes: 0 additions & 31 deletions evm-e2e/contracts/InfiniteLoopGasCompiled.json

This file was deleted.

32 changes: 0 additions & 32 deletions evm-e2e/contracts/ReceiveNibiCompiled.json

This file was deleted.

50 changes: 0 additions & 50 deletions evm-e2e/contracts/SendNibiCompiled.json

This file was deleted.

Loading
Loading