Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from mohsenmottaghi/update_2023_03_05
Browse files Browse the repository at this point in the history
Ignore DELEGATECALL in EVM call trace
  • Loading branch information
rastislavcore committed Mar 9, 2023
2 parents 59ce1f3 + 17853a4 commit d4d121d
Show file tree
Hide file tree
Showing 27 changed files with 213 additions and 86 deletions.
32 changes: 32 additions & 0 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ func (w *Worker) getContractDescriptorInfo(cd bchain.AddressDescriptor, typeFrom

validContract = false
} else {
if typeFromContext != bchain.UnknownTokenType && contractInfo.Type == bchain.UnknownTokenType {
contractInfo.Type = typeFromContext
}
if err = w.db.StoreContractInfo(contractInfo); err != nil {
glog.Errorf("StoreContractInfo error %v, contract %v", err, cd)
}
Expand Down Expand Up @@ -1462,6 +1465,35 @@ func (w *Worker) balanceHistoryForTxid(addrDesc bchain.AddressDescriptor, txid s
}
}
}
// process internal transactions
if eth.ProcessInternalTransactions {
internalData, err := w.db.GetEthereumInternalData(txid)
if err != nil {
return nil, err
}
if internalData != nil {
for i := range internalData.Transfers {
f := &internalData.Transfers[i]
txAddrDesc, err := w.chainParser.GetAddrDescFromAddress(f.From)
if err != nil {
return nil, err
}
if bytes.Equal(addrDesc, txAddrDesc) {
(*big.Int)(bh.SentSat).Add((*big.Int)(bh.SentSat), &f.Value)
if f.From == f.To {
(*big.Int)(bh.SentToSelfSat).Add((*big.Int)(bh.SentToSelfSat), &f.Value)
}
}
txAddrDesc, err = w.chainParser.GetAddrDescFromAddress(f.To)
if err != nil {
return nil, err
}
if bytes.Equal(addrDesc, txAddrDesc) {
(*big.Int)(bh.ReceivedSat).Add((*big.Int)(bh.ReceivedSat), &f.Value)
}
}
}
}
}
for i := range bchainTx.Vin {
bchainVin := &bchainTx.Vin[i]
Expand Down
16 changes: 9 additions & 7 deletions bchain/coins/eth/dataparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func decamel(s string) string {
b.WriteByte(' ')
}
b.WriteRune(v)
splittable = unicode.IsLower(v) || unicode.IsNumber(v)
// special handling of ETH to be able to convert "addETHToContract" to "Add ETH To Contract"
splittable = unicode.IsLower(v) || unicode.IsNumber(v) || (i >= 2 && s[i-2:i+1] == "ETH")
}
}
return b.String()
Expand All @@ -98,7 +99,7 @@ func GetSignatureFromData(data string) uint32 {

const ErrorTy byte = 255

func processParam(data string, index int, t *abi.Type, processed []bool) ([]string, int, bool) {
func processParam(data string, index int, dataOffset int, t *abi.Type, processed []bool) ([]string, int, bool) {
var retval []string
d := index << 6
if d+64 > len(data) {
Expand Down Expand Up @@ -140,7 +141,7 @@ func processParam(data string, index int, t *abi.Type, processed []bool) ([]stri
for i := 0; i < t.Size; i++ {
var r []string
var ok bool
r, index, ok = processParam(data, index, t.Elem, processed)
r, index, ok = processParam(data, index, dataOffset, t.Elem, processed)
if !ok {
return nil, 0, false
}
Expand All @@ -156,7 +157,7 @@ func processParam(data string, index int, t *abi.Type, processed []bool) ([]stri
processed[index] = true
index++
offset <<= 1
d = int(offset)
d = int(offset) + dataOffset
dynIndex := d >> 6
if d+64 > len(data) || d < 0 {
return nil, 0, false
Expand Down Expand Up @@ -195,10 +196,11 @@ func processParam(data string, index int, t *abi.Type, processed []bool) ([]stri
}
}
} else {
newOffset := dataOffset + dynIndex<<6
for i := 0; i < count; i++ {
var r []string
var ok bool
r, dynIndex, ok = processParam(data, dynIndex, t.Elem, processed)
r, dynIndex, ok = processParam(data, dynIndex, newOffset, t.Elem, processed)
if !ok {
return nil, 0, false
}
Expand All @@ -222,7 +224,7 @@ func tryParseParams(data string, params []string, parsedParams []abi.Type) []bch
var ok bool
for i := range params {
t := &parsedParams[i]
values, index, ok = processParam(data, index, t, processed)
values, index, ok = processParam(data, index, 0, t, processed)
if !ok {
return nil
}
Expand All @@ -244,7 +246,7 @@ func ParseInputData(signatures *[]bchain.FourByteSignature, data string) *bchain
if len(data) <= 2 { // data is empty or 0x
return &bchain.EthereumParsedInputData{Name: "Transfer"}
}
if len(data) < 10 || (len(data)-10)%64 != 0 {
if len(data) < 10 {
return nil
}
parsed := bchain.EthereumParsedInputData{
Expand Down
67 changes: 61 additions & 6 deletions bchain/coins/eth/dataparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestParseInputData(t *testing.T) {
Parameters: []string{"address"},
},
{
Name: "addLiquidityETH",
Name: "addLiquidityETHToContract",
Parameters: []string{"address", "uint256", "uint256", "uint256", "address", "uint256"},
},
{
Expand All @@ -131,6 +131,10 @@ func TestParseInputData(t *testing.T) {
Name: "transmitAndSellTokenForEth",
Parameters: []string{"address", "uint256", "uint256", "uint256", "address", "(uint8,bytes32,bytes32)", "bytes"},
},
{
Name: "execute",
Parameters: []string{"bytes", "bytes[]", "uint256"},
},
}
tests := []struct {
name string
Expand Down Expand Up @@ -191,13 +195,13 @@ func TestParseInputData(t *testing.T) {
},
},
{
name: "addLiquidityETH",
name: "addLiquidityETHToContract",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f400000000000000000000000000000000000000000000000000000000623f56f8",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf305d719",
Name: "Add Liquidity ETH",
Function: "addLiquidityETH(address, uint256, uint256, uint256, address, uint256)",
Name: "Add Liquidity ETH To Contract",
Function: "addLiquidityETHToContract(address, uint256, uint256, uint256, address, uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "address",
Expand Down Expand Up @@ -227,15 +231,15 @@ func TestParseInputData(t *testing.T) {
},
},
{
name: "addLiquidityETH data don't match - too long",
name: "addLiquidityETHToContract data don't match - too long",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f400000000000000000000000000000000000000000000000000000000623f56f800000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
want: &bchain.EthereumParsedInputData{
MethodId: "0xf305d719",
},
},
{
name: "addLiquidityETH data don't match - too short",
name: "addLiquidityETHToContract data don't match - too short",
signatures: &signatures,
data: "0xf305d719000000000000000000000000b80e5aaa2131c07568128f68b8538ed3c8951234000000000000000000000000000000000000007e37be2022c0914b2680000000000000000000000000000000000000000000007e37be2022c0914b26800000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000009f64b014ca26f2def573246543dd1115b229e4f4",
want: &bchain.EthereumParsedInputData{
Expand Down Expand Up @@ -362,6 +366,57 @@ func TestParseInputData(t *testing.T) {
},
},
},
{
name: "execute",
signatures: &signatures,
data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063fd167b00000000000000000000000000000000000000000000000000000000000000010800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000002fa5e9a300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cda4e840411c00a614ad9205caec807c7458a0e3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
want: &bchain.EthereumParsedInputData{
MethodId: "0x3593564c",
Name: "Execute",
Function: "execute(bytes, bytes[], uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "bytes",
Values: []string{"0x08"},
},
{
Type: "bytes[]",
Values: []string{"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000002fa5e9a300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cda4e840411c00a614ad9205caec807c7458a0e3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"},
},
{
Type: "uint256",
Values: []string{"1677530747"},
},
},
},
},
{
name: "execute2",
signatures: &signatures,
data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063ffd82300000000000000000000000000000000000000000000000000000000000000020b080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000006f05b59d3b200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000491478480c282e75df8b5700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000f0f9d895aca5c8678f706fb8216fa22957685a13",
want: &bchain.EthereumParsedInputData{
MethodId: "0x3593564c",
Name: "Execute",
Function: "execute(bytes, bytes[], uint256)",
Params: []bchain.EthereumParsedInputParam{
{
Type: "bytes",
Values: []string{"0x0b08"},
},
{
Type: "bytes[]",
Values: []string{
"0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000006f05b59d3b20000",
"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000491478480c282e75df8b5700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000f0f9d895aca5c8678f706fb8216fa22957685a13",
},
},
{
Type: "uint256",
Values: []string{"1677711395"},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions bchain/coins/eth/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ func (b *EthereumRPC) processCallTrace(call *rpcCallTrace, d *bchain.EthereumInt
To: call.To,
})
contracts = append(contracts, bchain.ContractInfo{Contract: call.From, DestructedInBlock: blockHeight})
} else if call.Type == "DELEGATECALL" {
// ignore DELEGATECALL (geth v1.11 the changed tracer behavior)
// https://github.com/ethereum/go-ethereum/issues/26726
} else if err == nil && (value.BitLen() > 0 || b.ChainConfig.ProcessZeroInternalTransactions) {
d.Transfers = append(d.Transfers, bchain.EthereumInternalTransfer{
Value: *value,
Expand Down
46 changes: 35 additions & 11 deletions bchain/coins/firo/firoparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
OpLelantusMint = 0xc5
OpLelantusJMint = 0xc6
OpLelantusJoinSplit = 0xc7
OpLelantusJoinSplitPayload = 0xc9

MainnetMagic wire.BitcoinNet = 0xe3d9fef1
TestnetMagic wire.BitcoinNet = 0xcffcbeea
Expand Down Expand Up @@ -122,6 +123,8 @@ func (p *FiroParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor)
return []string{"LelantusJMint"}, false, nil
case OpLelantusJoinSplit:
return []string{"LelantusJoinSplit"}, false, nil
case OpLelantusJoinSplitPayload:
return []string{"LelantusJoinSplit"}, false, nil
}
}

Expand Down Expand Up @@ -170,36 +173,54 @@ func (p *FiroParser) ParseBlock(b []byte) (*bchain.Block, error) {
} else {
if isMTP(header) {
mtpHeader := MTPBlockHeader{}
mtpHashData := MTPHashData{}
mtpHashDataRoot := MTPHashDataRoot{}

// header
err = binary.Read(reader, binary.LittleEndian, &mtpHeader)
if err != nil {
return nil, err
}

// hash data
err = binary.Read(reader, binary.LittleEndian, &mtpHashData)
// hash data root
err = binary.Read(reader, binary.LittleEndian, &mtpHashDataRoot)
if err != nil {
return nil, err
}

// proof
for i := 0; i < MTPL*3; i++ {
var numberProofBlocks uint8
isAllZero := true
for i := 0; i < 16; i++ {
if mtpHashDataRoot.HashRootMTP[i] != 0 {
isAllZero = false
break
}
}


err = binary.Read(reader, binary.LittleEndian, &numberProofBlocks)
if !isAllZero {
// hash data
mtpHashData := MTPHashData{}
err = binary.Read(reader, binary.LittleEndian, &mtpHashData)
if err != nil {
return nil, err
}

for j := uint8(0); j < numberProofBlocks; j++ {
var mtpData [16]uint8
// proof
for i := 0; i < MTPL*3; i++ {
var numberProofBlocks uint8

err = binary.Read(reader, binary.LittleEndian, mtpData[:])
err = binary.Read(reader, binary.LittleEndian, &numberProofBlocks)
if err != nil {
return nil, err
}

for j := uint8(0); j < numberProofBlocks; j++ {
var mtpData [16]uint8

err = binary.Read(reader, binary.LittleEndian, mtpData[:])
if err != nil {
return nil, err
}
}
}
}
}
Expand Down Expand Up @@ -318,8 +339,11 @@ func isProgPow(h *wire.BlockHeader, isTestNet bool) bool {
return isTestNet && epoch >= SwitchToProgPowBlockHeaderTestnet || !isTestNet && epoch >= SwitchToProgPowBlockHeaderMainnet
}

type MTPHashData struct {
type MTPHashDataRoot struct {
HashRootMTP [16]uint8
}

type MTPHashData struct {
BlockMTP [128][128]uint64
}

Expand Down
6 changes: 3 additions & 3 deletions configs/coins/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"package_name": "backend-ethereum",
"package_revision": "satoshilabs-1",
"system_user": "ethereum",
"version": "1.11.1-76961066",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz",
"version": "1.11.2-73b01f40",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz",
"verification_type": "gpg",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz.asc",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz.asc",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/geth --syncmode full --txlookuplimit 0 --ipcdisable --cache 1024 --nat none --datadir {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend --port {{.Ports.BackendP2P}} --ws --ws.addr 127.0.0.1 --ws.port {{.Ports.BackendRPC}} --ws.origins \"*\" --ws.api \"eth,net,web3,debug,txpool\" --http --http.port {{.Ports.BackendHttp}} --http.addr 127.0.0.1 --http.corsdomain \"*\" --http.vhosts \"*\" --http.api \"eth,net,web3,debug,txpool\" --authrpc.port {{.Ports.BackendAuthRpc}} 2>>{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
Expand Down
6 changes: 3 additions & 3 deletions configs/coins/ethereum_archive.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"package_name": "backend-ethereum-archive",
"package_revision": "satoshilabs-1",
"system_user": "ethereum",
"version": "1.11.1-76961066",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz",
"version": "1.11.2-73b01f40",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz",
"verification_type": "gpg",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz.asc",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz.asc",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/geth --syncmode full --gcmode archive --txlookuplimit 0 --ipcdisable --cache 1024 --nat none --datadir {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend --port {{.Ports.BackendP2P}} --ws --ws.addr 127.0.0.1 --ws.port {{.Ports.BackendRPC}} --ws.origins \"*\" --ws.api \"eth,net,web3,debug,txpool\" --http --http.port {{.Ports.BackendHttp}} --http.addr 127.0.0.1 --http.corsdomain \"*\" --http.vhosts \"*\" --http.api \"eth,net,web3,debug,txpool\" --authrpc.port {{.Ports.BackendAuthRpc}} 2>>{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
Expand Down
6 changes: 3 additions & 3 deletions configs/coins/ethereum_testnet_goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"package_name": "backend-ethereum-testnet-goerli",
"package_revision": "satoshilabs-1",
"system_user": "ethereum",
"version": "1.11.1-76961066",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz",
"version": "1.11.2-73b01f40",
"binary_url": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz",
"verification_type": "gpg",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.1-76961066.tar.gz.asc",
"verification_source": "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.11.2-73b01f40.tar.gz.asc",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/geth --goerli --syncmode full --txlookuplimit 0 --ipcdisable --cache 1024 --nat none --datadir {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend --port {{.Ports.BackendP2P}} --ws --ws.addr 127.0.0.1 --ws.port {{.Ports.BackendRPC}} --ws.origins \"*\" --ws.api \"eth,net,web3,debug,txpool\" --http --http.port {{.Ports.BackendHttp}} -http.addr 127.0.0.1 --http.corsdomain \"*\" --http.vhosts \"*\" --http.api \"eth,net,web3,debug,txpool\" --authrpc.port {{.Ports.BackendAuthRpc}} 2>>{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
Expand Down
Loading

0 comments on commit d4d121d

Please sign in to comment.