Skip to content

Commit

Permalink
Merge branch 'feature/firehose-tracer-at-latest-release-tag' into rel…
Browse files Browse the repository at this point in the history
…ease/firehose
  • Loading branch information
maoueh committed Feb 4, 2025
2 parents 5c7be09 + 42eff8a commit e7eda18
Show file tree
Hide file tree
Showing 127 changed files with 10,189 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/forge-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Run Forge build
run: |
forge --version
forge build --sizes --evm-version=cancun
forge build --evm-version=cancun
id: build

- name: Run Forge tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
NUM_SPLIT=20
make test-group-${{matrix.part}} NUM_SPLIT=20
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}.profile.out
Expand All @@ -59,7 +59,7 @@ jobs:

# Download all coverage reports from the 'tests' job
- name: Download coverage reports
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Set GOPATH
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ coverage.out
example/cosmwasm/echo/target
example/cosmwasm/cw20/target
example/cosmwasm/cw721/target
example/cosmwasm/cw1155/target

# Solidity contracts artifacts
contracts/artifacts
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog
## v6.0.3
sei-chain
* [#2057](https://github.com/sei-protocol/sei-chain/pull/2057) Avoid panic tx error message in debug trace
* [#2056](https://github.com/sei-protocol/sei-chain/pull/2056) Properly encode ERC1155 translated batch event data
* [#2051](https://github.com/sei-protocol/sei-chain/pull/2051) Add IBC support for 0x addresses
* [#2027](https://github.com/sei-protocol/sei-chain/pull/2027) Fix eth_subscribe with geth open ended range
* [#2043](https://github.com/sei-protocol/sei-chain/pull/2043) Query owner on ERC-721 and ERC-1155 pointers
* [#2044](https://github.com/sei-protocol/sei-chain/pull/2044) Support JS tracers
* [#2031](https://github.com/sei-protocol/sei-chain/pull/2031) Add custom query handling for unbonding balances
* [#1755](https://github.com/sei-protocol/sei-chain/pull/1755) Pointer contracts: support for ERC1155 and CW1155 contracts

## v6.0.2
sei-chain
* [#2018](https://github.com/sei-protocol/sei-chain/pull/2018) Remove TxHashes from EVM module
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sei \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

# go 1.23+ needs a workaround to link memsize (see https://github.com/fjl/memsize).
# NOTE: this is a terribly ugly and unstable way of comparing version numbers,
# but that's what you get when you do anything nontrivial in a Makefile.
ifeq ($(firstword $(sort go1.23 $(shell go env GOVERSION))), go1.23)
ldflags += -checklinkname=0
endif
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
Expand Down
2 changes: 1 addition & 1 deletion aclmapping/evm/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestMsgEVMTransaction() {
ctx, err := suite.preprocessor.AnteHandle(handlerCtx, tx.GetTx(), false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { return ctx, nil })
suite.Require().Nil(err)
cms.ResetEvents()
suite.App.EvmKeeper.SetDynamicBaseFeePerGas(ctx, sdk.ZeroDec())
suite.App.EvmKeeper.SetCurrBaseFeePerGas(ctx, sdk.ZeroDec())
_, err = suite.msgServer.EVMTransaction(sdk.WrapSDKContext(ctx), tc.msg)
suite.Require().Nil(err)

Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func New(
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
app.TransferKeeper = ibctransferkeeper.NewKeeperWithAddressHandler(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
Expand All @@ -511,6 +511,7 @@ func New(
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
evmkeeper.NewEvmAddressHandler(&app.EvmKeeper),
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
Expand Down Expand Up @@ -567,6 +568,7 @@ func New(
app.TransferKeeper,
app.AccessControlKeeper,
&app.EvmKeeper,
app.StakingKeeper,
),
wasmOpts...,
)
Expand Down
145 changes: 145 additions & 0 deletions app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"math/big"
"strings"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/cw1155"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
evmtracers "github.com/sei-protocol/sei-chain/x/evm/tracers"
"github.com/sei-protocol/sei-chain/x/evm/tracing"
Expand All @@ -27,6 +29,10 @@ var ERC20TransferTopic = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952
var ERC721TransferTopic = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
var ERC721ApprovalTopic = common.HexToHash("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")
var ERC721ApproveAllTopic = common.HexToHash("0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31")
var ERC1155TransferSingleTopic = common.HexToHash("0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62")
var ERC1155TransferBatchTopic = common.HexToHash("0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb")
var ERC1155ApprovalForAllTopic = common.HexToHash("0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31")
var ERC1155URITopic = common.HexToHash("0x6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b")
var EmptyHash = common.HexToHash("0x0")
var TrueHash = common.HexToHash("0x1")

Expand Down Expand Up @@ -94,6 +100,16 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
}
continue
}
// check if there is a ERC1155 pointer to contract Addr
pointerAddr, _, exists = app.EvmKeeper.GetERC1155CW1155Pointer(wasmToEvmEventCtx, contractAddr)
if exists {
log, eligible := app.translateCW1155Event(wasmToEvmEventCtx, wasmEvent, pointerAddr, contractAddr)
if eligible {
log.Index = uint(len(logs))
logs = append(logs, log)
}
continue
}
}
if len(logs) == 0 {
return
Expand Down Expand Up @@ -357,6 +373,103 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
return nil, false
}

func (app *App) translateCW1155Event(ctx sdk.Context, wasmEvent abci.Event, pointerAddr common.Address, contractAddr string) (*ethtypes.Log, bool) {
action, found := GetAttributeValue(wasmEvent, "action")
if !found {
return nil, false
}
var topics []common.Hash
switch action {
case "transfer_single", "mint_single", "burn_single":
fromHash := EmptyHash
toHash := EmptyHash
if action != "mint_single" {
fromHash = app.GetEvmAddressAttribute(ctx, wasmEvent, "owner")
}
if action != "burn_single" {
toHash = app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient")
}
topics = []common.Hash{
ERC1155TransferSingleTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
fromHash,
toHash,
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}
tokenAmount, found := GetAmountAttribute(wasmEvent)
if !found {
return nil, false
}
dataHash1 := common.BigToHash(tokenID).Bytes()
dataHash2 := common.BigToHash(tokenAmount).Bytes()
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: append(dataHash1, dataHash2...),
}, true
case "transfer_batch", "mint_batch", "burn_batch":
fromHash := EmptyHash
toHash := EmptyHash
if action != "mint_batch" {
fromHash = app.GetEvmAddressAttribute(ctx, wasmEvent, "owner")
}
if action != "burn_batch" {
toHash = app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient")
}
topics = []common.Hash{
ERC1155TransferBatchTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
fromHash,
toHash,
}
tokenIDs, found := GetTokenIDsAttribute(wasmEvent)
if !found {
return nil, false
}
tokenAmounts, found := GetAmountsAttribute(wasmEvent)
if !found {
return nil, false
}
dataArgs := cw1155.GetParsedABI().Events["TransferBatch"].Inputs.NonIndexed()
value, err := dataArgs.Pack(tokenIDs, tokenAmounts)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("failed to parse TransferBatch event data due to %s", err))
return nil, false
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: value,
}, true
case "approve_all":
topics = []common.Hash{
ERC1155ApprovalForAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: TrueHash.Bytes(),
}, true
case "revoke_all":
topics = []common.Hash{
ERC1155ApprovalForAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: EmptyHash.Bytes(),
}, true
}
return nil, false
}

func (app *App) GetEvmAddressAttribute(ctx sdk.Context, event abci.Event, attribute string) common.Hash {
addrStr, found := GetAttributeValue(event, attribute)
if found {
Expand Down Expand Up @@ -398,6 +511,22 @@ func GetAmountAttribute(event abci.Event) (*big.Int, bool) {
return nil, false
}

func GetAmountsAttribute(event abci.Event) ([]*big.Int, bool) {
results := []*big.Int{}
amounts, found := GetAttributeValue(event, "amounts")
if !found {
return results, false
}
for _, amt := range strings.Split(amounts, ",") {
amtInt, ok := sdk.NewIntFromString(amt)
if !ok {
return results, false
}
results = append(results, amtInt.BigInt())
}
return results, true
}

func GetTokenIDAttribute(event abci.Event) *big.Int {
tokenID, found := GetAttributeValue(event, "token_id")
if !found {
Expand All @@ -409,3 +538,19 @@ func GetTokenIDAttribute(event abci.Event) *big.Int {
}
return tokenIDInt.BigInt()
}

func GetTokenIDsAttribute(event abci.Event) ([]*big.Int, bool) {
results := []*big.Int{}
tokenIDs, found := GetAttributeValue(event, "token_ids")
if !found {
return results, false
}
for _, tid := range strings.Split(tokenIDs, ",") {
tidInt, ok := sdk.NewIntFromString(tid)
if !ok {
return results, false
}
results = append(results, tidInt.BigInt())
}
return results, true
}
Loading

0 comments on commit e7eda18

Please sign in to comment.