Skip to content

Commit

Permalink
Merge branch 'develop' into test-remove-usdt-mentions-from-e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Mar 11, 2024
2 parents 1e6977b + 414e5fe commit cf52225
Show file tree
Hide file tree
Showing 99 changed files with 619 additions and 536 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ RUN make install
# Run Stage
FROM alpine:3.18

ENV COSMOVISOR_CHECKSUM="626dfc58c266b85f84a7ed8e2fe0e2346c15be98cfb9f9b88576ba899ed78cdc"
ENV COSMOVISOR_VERSION="v1.5.0"
# Copy Start Script Helpers
COPY contrib/docker-scripts/* /scripts/

# Install runtime dependencies
RUN apk --no-cache add git jq bash curl python3 libusb-dev linux-headers make build-base wget py3-pip qemu-img qemu-system-x86_64 && \
RUN apk --no-cache add git jq bash curl nano vim tmux python3 libusb-dev linux-headers make build-base bind-tools psmisc coreutils wget py3-pip qemu-img qemu-system-x86_64 && \
pip install requests && \
chmod a+x -R /scripts && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.31-r0/glibc-2.31-r0.apk && \
apk add --force-overwrite --allow-untrusted glibc-2.31-r0.apk
apk add --force-overwrite --allow-untrusted glibc-2.31-r0.apk && \
curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz && \
mkdir -p /usr/local/gcloud && \
tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz && \
/usr/local/gcloud/google-cloud-sdk/install.sh --quiet && \
ln -s /usr/local/gcloud/google-cloud-sdk/bin/gcloud /usr/bin/gcloud && \
python /scripts/install_cosmovisor.py

# Copy the binaries from the build stage
COPY --from=builder /go/bin/zetaclientd /usr/local/bin/zetaclientd
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1840](https://github.com/zeta-chain/node/pull/1840) - fix code coverage test failures ignored in CI
* [1851](https://github.com/zeta-chain/node/pull/1851) - rename usdt to erc20 in e2e tests
* [1872](https://github.com/zeta-chain/node/pull/1872) - remove usage of RPC in unit test

### Fixes

Expand All @@ -39,6 +40,10 @@

* [1814](https://github.com/zeta-chain/node/pull/1814) - fix code coverage ignore for protobuf generated files

### CI

* [1867](https://github.com/zeta-chain/node/pull/1867) - default restore_type for full node docker-compose to snapshot instead of statesync for reliability.

## Version: v14

- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet
Expand Down
170 changes: 68 additions & 102 deletions common/ethereum/proof_test.go
Original file line number Diff line number Diff line change
@@ -1,125 +1,91 @@
package ethereum

import (
"context"
"math/big"
"encoding/json"
"fmt"
"os"
"testing"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/stretchr/testify/require"
)

func TestProofGeneration(t *testing.T) {
RPC_URL := "https://rpc.ankr.com/eth_goerli"
client, err := ethclient.Dial(RPC_URL)
if err != nil {
t.Fatal(err)
}
bn := int64(9509129)
block, err := client.BlockByNumber(context.Background(), big.NewInt(bn))
if err != nil {
t.Fatal(err)
}

headerRLP, _ := rlp.EncodeToBytes(block.Header())
t.Logf("block header size %d\n", len(headerRLP))

var header types.Header
rlp.DecodeBytes(headerRLP, &header)

t.Logf("block %d\n", block.Number())
t.Logf(" tx root %x\n", header.TxHash)
const (
headerPath = "./testdata/header.json"
receiptPrefixPath = "./testdata/receipt_"
receiptCount = 81
)

//ttt := new(trie.Trie)
tr := NewTrie(block.Transactions())
t.Logf(" sha2 %x\n", tr.Hash())
if tr.Hash() != header.TxHash {
t.Fatal("tx root mismatch")
} else {
t.Logf(" tx root hash & block tx root match\n")
func TestProofGeneration(t *testing.T) {
header, err := readHeader()
require.NoError(t, err)

var receipts types.Receipts
for i := 0; i < receiptCount; i++ {
receipt, err := readReceipt(i)
require.NoError(t, err)
receipts = append(receipts, &receipt)
}

var indexBuf []byte
for i := 0; i < len(block.Transactions()); i++ {
// generate a trie from the receipts and compare the root hash with the one in the header
receiptTree := NewTrie(receipts)
require.EqualValues(t, header.ReceiptHash.Hex(), header.ReceiptHash.Hex())

indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
for i, receipt := range receipts {
// generate a proof for each receipt and verify it
proof, err := receiptTree.GenerateProof(i)
require.NoError(t, err)

proof := NewProof()
tr.Prove(indexBuf, 0, proof)
t.Logf("proof len %d\n", len(proof.Keys))
value, err := proof.Verify(block.Header().TxHash, i)
//value, err := trie.VerifyProof(tr.trie.Hash(), indexBuf, proof)
t.Logf("pass? %v\n", err == nil)
//t.Logf("value %x\n", value)
verified, err := proof.Verify(header.ReceiptHash, i)
require.NoError(t, err)

var txx types.Transaction
txx.UnmarshalBinary(value)
t.Logf(" tx %+v\n", txx.To().Hex())
t.Logf(" tx hash %+v\n", txx.Hash().Hex())
if txx.Hash() != block.Transactions()[i].Hash() {
t.Fatal("tx hash mismatch")
} else {
t.Logf(" tx hash & block tx hash match\n")
// recover the receipt from the proof and compare it with the original receipt
// NOTE: eth receipts only hashes the following fields
// data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
var verifiedReceipt types.Receipt
err = verifiedReceipt.UnmarshalBinary(verified)
require.NoError(t, err)
require.EqualValues(t, receipt.Status, verifiedReceipt.Status)
require.EqualValues(t, receipt.CumulativeGasUsed, verifiedReceipt.CumulativeGasUsed)
require.EqualValues(t, receipt.Bloom.Bytes(), verifiedReceipt.Bloom.Bytes())
require.EqualValues(t, len(receipt.Logs), len(verifiedReceipt.Logs))
for i, log := range receipt.Logs {
require.EqualValues(t, log.Address, verifiedReceipt.Logs[i].Address)
require.EqualValues(t, log.Topics, verifiedReceipt.Logs[i].Topics)
require.EqualValues(t, log.Data, verifiedReceipt.Logs[i].Data)
}
signer := types.NewLondonSigner(txx.ChainId())
sender, err := types.Sender(signer, &txx)
t.Logf(" tx from %s\n", sender.Hex())
}

//for k, v := range proof.Proof {
// key, _ := base64.StdEncoding.DecodeString(k)
// t.Logf("k: %x, v: %x\n", key, v)
//}

{
var receipts types.Receipts
for _, tx := range block.Transactions() {
receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
if err != nil {
t.Fatal(err)
}
receipts = append(receipts, receipt)
time.Sleep(200 * time.Millisecond)
}

receiptTree := NewTrie(receipts)
t.Logf(" block receipt root %x\n", block.Header().ReceiptHash)
t.Logf(" receipt tree root %x\n", receiptTree.Hash())
if receiptTree.Hash() != block.Header().ReceiptHash {
t.Fatal("receipt root mismatch")
} else {
t.Logf(" receipt root hash & block receipt root match\n")
}

i := 1
proof := NewProof()
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
err = receiptTree.Prove(indexBuf, 0, proof)
if err != nil {
t.Fatal(err)
}
}

// NOTE: eth receipts only hashes the following fields
// data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
value, err := trie.VerifyProof(block.Header().ReceiptHash, indexBuf, proof)
t.Logf("pass? %v\n", err == nil)
t.Logf("value %x\n", value)
value, err = proof.Verify(block.Header().ReceiptHash, i)
if err != nil {
t.Fatal(err)
}
// readHeader reads a header from a file.
// TODO: centralize test data
// https://github.com/zeta-chain/node/issues/1874
func readHeader() (header types.Header, err error) {
file, err := os.Open(headerPath)
if err != nil {
return header, err
}
defer file.Close()

var receipt types.Receipt
receipt.UnmarshalBinary(value)
decoder := json.NewDecoder(file)
err = decoder.Decode(&header)
return header, err
}

t.Logf(" receipt %+v\n", receipt)
t.Logf(" receipt tx hash %+v\n", receipt.TxHash.Hex())
// readReceipt reads a receipt from a file.
// TODO: centralize test data
// https://github.com/zeta-chain/node/issues/1874
func readReceipt(index int) (receipt types.Receipt, err error) {
filePath := fmt.Sprintf("%s%d.json", receiptPrefixPath, index)

for _, log := range receipt.Logs {
t.Logf(" log %+v\n", log)
}
file, err := os.Open(filePath)
if err != nil {
return receipt, err
}
defer file.Close()

decoder := json.NewDecoder(file)
err = decoder.Decode(&receipt)
return receipt, err
}
1 change: 1 addition & 0 deletions common/ethereum/testdata/header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parentHash":"0x69c3f269c0e96530feb9c3ec01ab8c87c77a8c489148d34bdd3ce00d78f00b3c","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","miner":"0xd9a5179f091d85051d3c982785efd1455cec8699","stateRoot":"0xfbc81b7cf76ec579a74fea7d01c93f89e2c5bc3689732697682144c045756594","transactionsRoot":"0xe98dcafb82038e90d0403f9717a45eafda1c3d33a9ec898394016e2d3c310310","receiptsRoot":"0xb55bea9aa993839f093399911d1cf806cb1ec2be0cbd71a3bb8528aa9ef2fc53","logsBloom":"0x106010c449c041421308460893b00352001100308434001001d41128601245a04194424000c10f094a2088b1000400000000008530060ea102a00018002c020214518016002320528254601c08c801960c81c00440c400083c62442c4014c244b0c822088200241080a65025a0022f48a422044300500040608100d15c0003042c48210880e4884034232904881042000239c0084100884009147000455c00251e88442402a0294a40220070000908c0100124c43108801269203162c6020500800bc12b900250a13d0404211657001005003119008800046044a4002841654902fc20000004200200d13b02a00460ad84402400122e8008c214420404d05110","difficulty":"0x0","number":"0x4c4b40","gasLimit":"0x1c9c380","gasUsed":"0xea329c","timestamp":"0x6592aed4","extraData":"0xd883010d05846765746888676f312e32312e34856c696e7578","mixHash":"0xfce8b8cf88b975164b8911c51d144db1a5093d60779cb6f64493f30f9062e19b","nonce":"0x0000000000000000","baseFeePerGas":"0xc11611","hash":"0xb4272db0d4b614f464dc067dcf3ca01bd2087070dcf6edbe240571642b2c1825"}
1 change: 1 addition & 0 deletions common/ethereum/testdata/receipt_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"root":"0x","status":"0x1","cumulativeGasUsed":"0x5208","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs":[],"transactionHash":"0xe5a58e3d4460acf272945bc15bd91bad5b626b3f8ef33a36630cbce97d86b172","contractAddress":"0x0000000000000000000000000000000000000000","gasUsed":"0x5208","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","blockNumber":"0x4c4b40","transactionIndex":"0x0"}
1 change: 1 addition & 0 deletions common/ethereum/testdata/receipt_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"root":"0x","status":"0x1","cumulativeGasUsed":"0xa410","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs":[],"transactionHash":"0x2fd214d899e3b8e3ac957ab69927461f0c0a3afe9fc3b79a73a71a3f18c97e35","contractAddress":"0x0000000000000000000000000000000000000000","gasUsed":"0x5208","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","blockNumber":"0x4c4b40","transactionIndex":"0x1"}
1 change: 1 addition & 0 deletions common/ethereum/testdata/receipt_10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"0x2","root":"0x","status":"0x1","cumulativeGasUsed":"0x35da2a","logsBloom":"0x000010040000000000000000000000100000000000100000008000080000000000000000000000000000080000000000000000000002000000000000000000001000000200000000000000080000018000000000008000000000000040004000004000000200001080804001000028000000004000000000000000100000000000080000000000000001000008000000000000000000000000000000000000000c00000000a0000000000000000000000000000000008000000000200000000000000003000000000000000000000000000010000000000400000000000020010040000000000000000000000000000000000000000400000000000400000000","logs":[{"address":"0x08394e7e653472694ecd4527656b2881e5701a14","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000000000000002540be400","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x1e","removed":false},{"address":"0x63355a2ff725b11b6d82071c9fd710c0dcc71900","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000000000000002540be400","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x1f","removed":false},{"address":"0x1cd40deb4196d219097499031922ff690f9ea813","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x20","removed":false},{"address":"0x5b41a5c0df16551f5edeaa2b2ede2135f1a824df","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x21","removed":false},{"address":"0xd7b45cbc28ba9ba8653665d5fb37167a2afe35d9","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x22","removed":false},{"address":"0x01fa8deeddea8e4e465f158d93e162438d61c9eb","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x23","removed":false},{"address":"0x11dc5c441971bb3b2e933e0256e8a6bc6c41a91a","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x24","removed":false},{"address":"0xbe1d0db61e7562d88ef1fab7436d02b6d00ce728","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x25","removed":false},{"address":"0xd75edf81cd2109d4264624dbf34bd4dee36f18b9","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x26","removed":false},{"address":"0xc870a3dc444bf970da13979e9cfac1a01c198eac","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x00000000000000000000000000000000000000000000021e19e0c9bab2400000","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x27","removed":false},{"address":"0x837ad475f0177bcb6cf426a725d5d52dfb577ee7","topics":["0x624601b6b2c889f8d24f3b93ec6db534d4c0f2cb51c0087f2d5739679393fa51","0x0000000000000000000000003a549672d9a4de8a096dcf75d947a4fd0c607cc0"],"data":"0x","blockNumber":"0x4c4b40","transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","transactionIndex":"0xa","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","logIndex":"0x28","removed":false}],"transactionHash":"0xb24efa8d61c60ec11386273038d5db7ac691c650507ec4521c5e8cb24d5bc183","contractAddress":"0x0000000000000000000000000000000000000000","gasUsed":"0x680ac","blockHash":"0x72247ea9191db039158939f7ba958e638a32df4f61a43edcae60cb7a686a2d55","blockNumber":"0x4c4b40","transactionIndex":"0xa"}
Loading

0 comments on commit cf52225

Please sign in to comment.