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

Commit

Permalink
test: revert test changes, wait for anvil update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Feb 10, 2024
1 parent 5c6d0fe commit 5eb8861
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 175 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: alpha-6_eip4844

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c12e2d75fff02dcd1b0f1edaa1781a30a1d4b4e1
6e2771c54e62e73715cfbe2e7d4fc5a2fb54cf5c
23 changes: 1 addition & 22 deletions bindings/gen_taiko_token.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *Syncer) onBlockProposed(
}

// Check whether the transactions list is valid.
hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.BlockId, txListBytes)
hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.BlockId, txListBytes, event.Meta.BlobUsed)
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}
Expand Down
31 changes: 28 additions & 3 deletions driver/txlist_fetcher/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package txlistdecoder
import (
"context"
"crypto/sha256"
"errors"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/pkg/rpc"
)

const (
var (
blobCommitmentVersionKZG uint8 = 0x01 // Version byte for the point evaluation precompile.
errBlobInvalid = errors.New("invalid blob encoding")
)

type BlobFetcher struct {
Expand Down Expand Up @@ -52,17 +55,39 @@ func (d *BlobFetcher) Fetch(
if KZGToVersionedHash(
kzg4844.Commitment(common.FromHex(sidecar.KzgCommitment)),
) == common.BytesToHash(meta.BlobHash[:]) {
return common.Hex2Bytes(sidecar.Blob), nil
return DecodeBlob(common.FromHex(sidecar.Blob))
}
}

return nil, errSidecarNotFound
}

// KZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844
// KZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844.
func KZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
h := sha256.Sum256(kzg[:])
h[0] = blobCommitmentVersionKZG

return h
}

// DecodeBlob decode blob data.
func DecodeBlob(blob []byte) ([]byte, error) {
if len(blob) != params.BlobTxFieldElementsPerBlob*32 {
return nil, errBlobInvalid
}
log.Info("OK")
var data []byte
for i, j := 0, 0; i < params.BlobTxFieldElementsPerBlob; i++ {
data = append(data, blob[j:j+31]...)
j += 32
}

i := len(data) - 1
for ; i >= 0; i-- {
if data[i] != 0x00 {
break
}
}
data = data[:i+1]
return data, nil
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/ethereum/go-ethereum v1.13.11
github.com/go-resty/resty/v2 v2.7.0
github.com/holiman/uint256 v1.2.4
github.com/joho/godotenv v1.5.1
github.com/labstack/echo/v4 v4.11.1
github.com/modern-go/reflect2 v1.0.2
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPw
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
Expand Down
1 change: 0 additions & 1 deletion integration_test/test_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export TREASURY=0x1670010000000000000000000000000000010001
# show the integration test environment variables.
echo "RUN_TESTS=true
TAIKO_MONO_DIR=$TAIKO_MONO_DIR
L1_BEACON_HTTP_ENDPOINT=$L1_BEACON_HTTP_ENDPOINT
L1_NODE_HTTP_ENDPOINT=$L1_NODE_HTTP_ENDPOINT
L1_NODE_WS_ENDPOINT=$L1_NODE_WS_ENDPOINT
L2_EXECUTION_ENGINE_HTTP_ENDPOINT=$L2_EXECUTION_ENGINE_HTTP_ENDPOINT
Expand Down
6 changes: 0 additions & 6 deletions internal/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
consensus/beacondata
consensus/genesis.ssz
consensus/validatordata
execution/geth
execution/geth.ipc
execution/genesis.json
taikogeth/taiko-geth
31 changes: 0 additions & 31 deletions internal/docker/common.sh

This file was deleted.

21 changes: 8 additions & 13 deletions internal/docker/docker_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# check until L1 chain is ready
L1_PROBE_URL=http://localhost:$(docker port geth | grep '0.0.0.0' | awk -F ':' 'NR==1 {print $2}')
L1_PROBE_URL=http://localhost:$(docker port l1_node | grep '0.0.0.0' | awk -F ':' '{print $2}')
until cast chain-id --rpc-url "$L1_PROBE_URL" 2> /dev/null; do
sleep 1
done
Expand All @@ -15,25 +15,20 @@ until cast chain-id --rpc-url "$L2_PROBE_URL" 2> /dev/null; do
done


L1_BEACON_PORT=$(docker port beacon-chain | grep '0.0.0.0' | awk -F ':' '{print $2}')
export L1_BEACON_HTTP_ENDPOINT=http://localhost:$L1_BEACON_PORT
export L1_NODE_HTTP_ENDPOINT=http://localhost:$(docker port geth | grep '0.0.0.0' | awk -F ':' 'NR==1 {print $2}')
export L1_NODE_WS_ENDPOINT=ws://localhost:$(docker port geth | grep '0.0.0.0' | awk -F ':' 'NR==2 {print $2}')
L1_NODE_PORT=$(docker port l1_node | grep '0.0.0.0' | awk -F ':' '{print $2}')
export L1_NODE_HTTP_ENDPOINT=http://localhost:$L1_NODE_PORT
export L1_NODE_WS_ENDPOINT=ws://localhost:$L1_NODE_PORT

export L2_EXECUTION_ENGINE_HTTP_ENDPOINT=http://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==1 {print $2}')
export L2_EXECUTION_ENGINE_WS_ENDPOINT=ws://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==2 {print $2}')
export L2_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:$(docker port l2_node | grep "0.0.0.0" | awk -F ':' 'NR==3 {print $2}')
export JWT_SECRET=$DIR/taikogeth/jwt.hex
export JWT_SECRET=$DIR/nodes/jwt.hex

echo -e "L1_NODE PORTS: \n$(docker port l1_node)"
echo -e "L2_NODE PORTS: \n$(docker port l2_node)"

echo
echo -e "L1_NODE PORTS: \n$(docker port geth)"
echo "L1_NODE_HTTP_ENDPOINT: $L1_NODE_HTTP_ENDPOINT"
echo "L1_NODE_WS_ENDPOINT: $L1_NODE_WS_ENDPOINT"
echo
echo -e "L1_BEACON PORTS: \n$(docker port beacon-chain)"
echo "L1_BEACON_HTTP_ENDPOINT: $L1_BEACON_HTTP_ENDPOINT"
echo
echo -e "L2_NODE PORTS: \n$(docker port l2_node)"
echo "L2_EXECUTION_ENGINE_HTTP_ENDPOINT: $L2_EXECUTION_ENGINE_HTTP_ENDPOINT"
echo "L2_EXECUTION_ENGINE_WS_ENDPOINT: $L2_EXECUTION_ENGINE_WS_ENDPOINT"
echo "L2_EXECUTION_ENGINE_AUTH_ENDPOINT: $L2_EXECUTION_ENGINE_AUTH_ENDPOINT"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.9"
services:
l1_node:
container_name: l1_node
image: ghcr.dockerproxy.com/foundry-rs/foundry:latest
image: ghcr.dockerproxy.com/foundry-rs/foundry:nightly-4a643801d0b3855934cdec778e33e79c79971783
restart: unless-stopped
pull_policy: always
ports:
Expand All @@ -12,16 +12,14 @@ services:
- anvil
- --host
- "0.0.0.0"
- --hardfork
- "cancun"

l2_execution_engine:
container_name: l2_node
image: gcr.dockerproxy.com/evmchain/taiko-geth:taiko
restart: unless-stopped
pull_policy: always
volumes:
- ./taikogeth:/host
- .:/host
ports:
- "8545"
- "8546"
Expand All @@ -33,7 +31,7 @@ services:
- --syncmode
- full
- --datadir
- /host/taiko-geth
- /data/taiko-geth
- --networkid
- "167001"
- --metrics
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c49690b5a9bc72c7b451b48c5fee2b542e66559d840a133d090769abc56e39e7
c49690b5a9bc72c7b451b48c5fee2b542e66559d840a133d090769abc56e39e7
8 changes: 2 additions & 6 deletions internal/docker/start.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/bin/bash

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source scripts/common.sh

source "$DIR"/common.sh
DOCKER_SERVICE_LIST=("l1_node" "l2_execution_engine")

# start docker compose service list
echo "start docker compose service: ${DOCKER_SERVICE_LIST[*]}"

# Init docker
compose_up "${DOCKER_INIT_LIST[@]}"

# Start docker containers.
compose_up "${DOCKER_SERVICE_LIST[@]}"

# show all the running containers
Expand Down
14 changes: 3 additions & 11 deletions internal/docker/stop.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#!/bin/bash

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR"/common.sh
source scripts/common.sh

echo "stop docker compose service: ${DOCKER_INIT_LIST[*]}"
compose_down "${DOCKER_INIT_LIST[@]}"
DOCKER_SERVICE_LIST=("l1_node" "l2_execution_engine")

echo "stop docker compose service: ${DOCKER_SERVICE_LIST[*]}"
compose_down "${DOCKER_SERVICE_LIST[@]}"

# Delete exited containers.
docker rm $(docker ps -aqf "status=exited") 2>/dev/null

rm -rf "$DIR"/consensus/beacondata "$DIR"/consensus/validatordata "$DIR"/consensus/genesis.ssz
rm -rf "$DIR"/execution/geth
rm -rf "$DIR"/taikogeth/taiko-geth
compose_down "${DOCKER_SERVICE_LIST[@]}"
4 changes: 0 additions & 4 deletions internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/internal/utils"
"github.com/taikoxyz/taiko-client/pkg/jwt"
"github.com/taikoxyz/taiko-client/pkg/rpc"
"github.com/taikoxyz/taiko-client/prover/server"
Expand All @@ -37,9 +36,6 @@ func (s *ClientTestSuite) SetupTest() {
glogger := log.NewGlogHandler(log.NewTerminalHandlerWithLevel(os.Stdout, log.LevelInfo, true))
log.SetDefault(log.NewLogger(glogger))

// Load env.
utils.LoadEnv()

testAddrPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

Expand Down
21 changes: 0 additions & 21 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@ package utils

import (
"crypto/rand"
"fmt"
"math/big"
"os"
"strings"

"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/log"
"github.com/joho/godotenv"
"github.com/modern-go/reflect2"
)

func LoadEnv() {
// load test environment variables.
currentPath, err := os.Getwd()
if err != nil {
log.Warn("get current path failed", "err", err)
}
path := strings.Split(currentPath, "/taiko-client")
if len(path) == 0 {
log.Warn("not a taiko-client repo")
}
err = godotenv.Load(fmt.Sprintf("%s/taiko-client/.env", path[0]))
if err != nil {
log.Warn("failed to load env", "current path", currentPath, "err", err)
}
}

func RandUint64(max *big.Int) uint64 {
if max == nil {
max = new(big.Int)
Expand Down
6 changes: 1 addition & 5 deletions pkg/rpc/tx_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"

"github.com/taikoxyz/taiko-client/internal/utils"
)

func TestBlockTx(t *testing.T) {
t.SkipNow()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Load env.
utils.LoadEnv()

url := os.Getenv("L1_NODE_WS_ENDPOINT")
l1Client, err := NewEthClient(ctx, url, time.Second*20)
assert.NoError(t, err)
Expand Down
11 changes: 8 additions & 3 deletions pkg/txlistvalidator/tx_list_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ func NewTxListValidator(
func (v *TxListValidator) ValidateTxList(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
) (hint InvalidTxListReason, txIdx int, err error) {
if len(txListBytes) == 0 {
return HintOK, 0, nil
}

hint, txIdx = v.isTxListValid(blockID, txListBytes)
hint, txIdx = v.isTxListValid(blockID, txListBytes, blobUsed)

return hint, txIdx, nil
}

// isTxListValid checks whether the transaction list is valid.
func (v *TxListValidator) isTxListValid(blockID *big.Int, txListBytes []byte) (hint InvalidTxListReason, txIdx int) {
if len(txListBytes) > int(v.maxBytesPerTxList) {
func (v *TxListValidator) isTxListValid(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
) (hint InvalidTxListReason, txIdx int) {
if !blobUsed && (len(txListBytes) > int(v.maxBytesPerTxList)) {
log.Info("Transactions list binary too large", "length", len(txListBytes), "blockID", blockID)
return HintNone, 0
}
Expand Down
15 changes: 1 addition & 14 deletions pkg/txlistvalidator/tx_list_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ var (
}
)

func TestValidateTxList(t *testing.T) {
v := NewTxListValidator(
maxBlocksGasLimit,
maxBlockNumTxs,
maxTxlistBytes,
chainID,
)

// Binary is not unpackable
_, _, err := v.ValidateTxList(common.Big0, randBytes(5))
require.NotNil(t, err)
}

func TestIsTxListValid(t *testing.T) {
v := NewTxListValidator(
maxBlocksGasLimit,
Expand Down Expand Up @@ -97,7 +84,7 @@ func TestIsTxListValid(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reason, txIdx := v.isTxListValid(tt.blockID, tt.txListBytes)
reason, txIdx := v.isTxListValid(tt.blockID, tt.txListBytes, false)
require.Equal(t, tt.wantReason, reason)
require.Equal(t, tt.wantTxIdx, txIdx)
})
Expand Down
Loading

0 comments on commit 5eb8861

Please sign in to comment.