diff --git a/.github/workflows/ok-to-test.yml b/.github/workflows/ok-to-test.yml deleted file mode 100644 index 8c36b929fc..0000000000 --- a/.github/workflows/ok-to-test.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -name: Ok To Test - -on: - issue_comment: - types: [created] - -jobs: - ok-to-test: - runs-on: ubuntu-latest - if: ${{ github.event.issue.pull_request }} - steps: - - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 - env: - TOKEN: ${{ steps.generate_token.outputs.token }} - with: - token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - reaction-token: ${{ secrets.GITHUB_TOKEN }} - issue-type: pull-request - commands: ok-to-test - named-args: true - permission: write diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 145b1532d4..92e4a827dd 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -9,12 +9,9 @@ on: - update-external-dependencies - 'release/**' pull_request: - repository_dispatch: - types: [ok-to-test-command] jobs: - trusted-test-e2e: - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + test-e2e: strategy: fail-fast: false matrix: @@ -33,12 +30,6 @@ jobs: env: GOARCH: ${{ matrix.goarch }} - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build Docker run: make build-docker @@ -49,74 +40,3 @@ jobs: - name: Test run: make test-e2e-group-${{ matrix.e2e-group }} working-directory: test - - from-fork-test-e2e: - if: - github.event_name == 'repository_dispatch' && - github.event.client_payload.slash_command.sha != '' && - contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha) - strategy: - matrix: - go-version: [ 1.18.x ] - goarch: [ "amd64" ] - e2e-group: [ 1, 2, 3, 4, 5, 6, 7 ] - runs-on: ubuntu-latest - steps: - - name: Fork based /ok-to-test checkout - uses: actions/checkout@v3 - with: - ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge' - - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - env: - GOARCH: ${{ matrix.goarch }} - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build Docker - run: make build-docker - - - name: Compile SCs - run: make compile-scs - working-directory: test - - - name: Test - run: make test-e2e-group-${{ matrix.e2e-group }} - working-directory: test - - # Update check run - - uses: actions/github-script@v5 - id: update-check-run - if: ${{ always() }} - env: - number: ${{ github.event.client_payload.pull_request.number }} - job: ${{ github.job }} - # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run - conclusion: ${{ job.status }} - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { data: pull } = await github.rest.pulls.get({ - ...context.repo, - pull_number: process.env.number - }); - const ref = pull.head.sha; - const { data: checks } = await github.rest.checks.listForRef({ - ...context.repo, - ref - }); - const check = checks.check_runs.filter(c => c.name === process.env.job); - const { data: result } = await github.rest.checks.update({ - ...context.repo, - check_run_id: check[0].id, - status: 'completed', - conclusion: process.env.conclusion - }); - return result; diff --git a/.github/workflows/test-from-prover.yml b/.github/workflows/test-from-prover.yml deleted file mode 100644 index 5502d4162c..0000000000 --- a/.github/workflows/test-from-prover.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Test from zkevm-prover call -on: - workflow_call: - inputs: - prover_image: - required: true - type: string - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true - -jobs: - test-from-prover: - runs-on: [self-hosted, linux, X64, hc] - - strategy: - matrix: - go-version: [ 1.18.x ] - goarch: [ "amd64" ] - e2e-group: [ 2 ] - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - repository: 0xPolygonHermez/zkevm-node - - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - env: - GOARCH: ${{ matrix.goarch }} - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build Docker - run: make build-docker - - - name: Compile SCs - run: make compile-scs - working-directory: test - - - name: Test - run: make test-full-non-e2e - working-directory: test diff --git a/.github/workflows/test-full-non-e2e.yml b/.github/workflows/test-full-non-e2e.yml index 71bfe903f5..dea6f514ff 100644 --- a/.github/workflows/test-full-non-e2e.yml +++ b/.github/workflows/test-full-non-e2e.yml @@ -9,12 +9,9 @@ on: - update-external-dependencies - 'release/**' pull_request: - repository_dispatch: - types: [ok-to-test-command] jobs: - trusted-test-full-non-e2e: - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + test-full-non-e2e: strategy: matrix: go-version: [ 1.18.x ] @@ -31,54 +28,6 @@ jobs: env: GOARCH: ${{ matrix.goarch }} - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Compile SCs - run: make compile-scs - working-directory: test - - - name: Test - env: - ZKPROVER_URI: 127.0.0.1 - run: make test-full-non-e2e - working-directory: test - - from-fork-test-full-non-e2e: - if: - github.event_name == 'repository_dispatch' && - github.event.client_payload.slash_command.sha != '' && - contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha) - strategy: - matrix: - go-version: [ 1.18.x ] - goarch: [ "amd64" ] - runs-on: ubuntu-latest - steps: - - name: Fork based /ok-to-test checkout - uses: actions/checkout@v3 - with: - ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge' - - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - env: - GOARCH: ${{ matrix.goarch }} - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build Docker - run: make build-docker - - name: Compile SCs run: make compile-scs working-directory: test @@ -88,32 +37,3 @@ jobs: ZKPROVER_URI: 127.0.0.1 run: make test-full-non-e2e working-directory: test - - # Update check run - - uses: actions/github-script@v5 - id: update-check-run - if: ${{ always() }} - env: - number: ${{ github.event.client_payload.pull_request.number }} - job: ${{ github.job }} - conclusion: ${{ job.status }} - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { data: pull } = await github.rest.pulls.get({ - ...context.repo, - pull_number: process.env.number - }); - const ref = pull.head.sha; - const { data: checks } = await github.rest.checks.listForRef({ - ...context.repo, - ref - }); - const check = checks.check_runs.filter(c => c.name === process.env.job); - const { data: result } = await github.rest.checks.update({ - ...context.repo, - check_run_id: check[0].id, - status: 'completed', - conclusion: process.env.conclusion - }); - return result; diff --git a/docs/ci/actions.md b/docs/ci/actions.md index c35569ffb1..821c6edcea 100644 --- a/docs/ci/actions.md +++ b/docs/ci/actions.md @@ -23,7 +23,6 @@ PR opened and pushing changes to PRs. Pushes docker images to docker hub, the images pushed are: * `hermeznetwork/zkevm-node:develop` -* `hermeznetwork/zkprover-mock:develop` ### When is executed @@ -33,7 +32,6 @@ Changes pushed to the `develop` branch. Pushes docker images to docker hub, the images pushed are: * `hermeznetwork/zkevm-node:latest` -* `hermeznetwork/zkprover-mock:latest` ### When is executed diff --git a/test/Makefile b/test/Makefile index 5c3925de5b..c96bc9cb18 100644 --- a/test/Makefile +++ b/test/Makefile @@ -15,7 +15,6 @@ DOCKERCOMPOSEEXPLORERL2 := zkevm-explorer-l2 DOCKERCOMPOSEEXPLORERL2DB := zkevm-explorer-l2-db DOCKERCOMPOSEEXPLORERRPC := zkevm-explorer-json-rpc DOCKERCOMPOSEZKPROVER := zkevm-prover -DOCKERCOMPOSEZKPROVERMOCK := zkprover-mock DOCKERCOMPOSEPERMISSIONLESSDB := zkevm-permissionless-db DOCKERCOMPOSEPERMISSIONLESSNODE := zkevm-permissionless-node DOCKERCOMPOSEPERMISSIONLESSZKPROVER := zkevm-permissionless-prover @@ -41,7 +40,6 @@ RUNEXPLORERL2 := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORERL2) RUNEXPLORERL2DB := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORERL2DB) RUNEXPLORERJSONRPC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORERRPC) RUNZKPROVER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEZKPROVER) -RUNZKPROVERMOCK := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEZKPROVERMOCK) RUNPERMISSIONLESSDB := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEPERMISSIONLESSDB) RUNPERMISSIONLESSNODE := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEPERMISSIONLESSNODE) @@ -71,7 +69,6 @@ STOPEXPLORERL2 := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORERL2) && $(DOCKERCO STOPEXPLORERL2DB := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORERL2DB) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEEXPLORERL2DB) STOPEXPLORERJSONRPC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORERRPC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEEXPLORERRPC) STOPZKPROVER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEZKPROVER) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEZKPROVER) -STOPZKPROVERMOCK := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEZKPROVERMOCK) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEZKPROVERMOCK) STOPPERMISSIONLESSDB := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEPERMISSIONLESSDB) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEPERMISSIONLESSDB) STOPPERMISSIONLESSNODE := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEPERMISSIONLESSNODE) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEPERMISSIONLESSNODE) @@ -89,9 +86,7 @@ test-full-non-e2e: stop ## Runs non-e2e tests checking race conditions $(RUNPOOLDB) $(RUNEVENTDB) $(RUNZKPROVER) - sleep 5 - $(RUNZKPROVERMOCK) - sleep 2 + sleep 7 $(RUNL1NETWORK) sleep 15 docker logs $(DOCKERCOMPOSEZKPROVER) @@ -259,14 +254,6 @@ run-zkprover: ## Runs zkprover stop-zkprover: ## Stops zkprover $(STOPZKPROVER) -.PHONY: run-zkprover-mock -run-zkprover-mock: ## Runs zkprover-mock - $(RUNZKPROVERMOCK) - -.PHONY: stop-zkprover-mock -stop-zkprover-mock: ## Stops zkprover-mock - $(STOPZKPROVERMOCK) - .PHONY: run-l1-explorer run-l1-explorer: ## Runs L1 blockscan explorer $(RUNEXPLORERL1DB) diff --git a/test/operations/wait.go b/test/operations/wait.go index 332929d97e..45fa56d0c4 100644 --- a/test/operations/wait.go +++ b/test/operations/wait.go @@ -30,7 +30,7 @@ const ( // DefaultInterval is a time interval DefaultInterval = 2 * time.Millisecond // DefaultDeadline is a time interval - DefaultDeadline = 30 * time.Second + DefaultDeadline = 2 * time.Minute // DefaultTxMinedDeadline is a time interval DefaultTxMinedDeadline = 5 * time.Second ) diff --git a/tools/zkevmprovermock/Dockerfile b/tools/zkevmprovermock/Dockerfile deleted file mode 100644 index a8e3140dbf..0000000000 --- a/tools/zkevmprovermock/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM golang:1.18-alpine AS build - -ENV CGO_ENABLED=0 -WORKDIR /app -COPY . . -RUN apk add --no-cache build-base && \ - go build -ldflags '-extldflags "-static"' -o ./zkprover-mock ./tools/zkevmprovermock/cmd/... - -FROM alpine:3.16.0 -COPY --from=build /app/zkprover-mock /app/zkprover-mock -CMD ["/bin/sh", "-c", "/app/zkprover-mock server"] diff --git a/tools/zkevmprovermock/cmd/client.go b/tools/zkevmprovermock/cmd/client.go deleted file mode 100644 index d9763f30b5..0000000000 --- a/tools/zkevmprovermock/cmd/client.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/urfave/cli/v2" -) - -func runClient(cliCtx *cli.Context) error { - log.Info("Running zkEVM Prover Client mock...") - - return nil -} diff --git a/tools/zkevmprovermock/cmd/main.go b/tools/zkevmprovermock/cmd/main.go deleted file mode 100644 index f314242d85..0000000000 --- a/tools/zkevmprovermock/cmd/main.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - - "github.com/urfave/cli/v2" -) - -const ( - defaultStateDBPort = 50061 - defaultExecutorPort = 50071 - defaultTestVectorPath = "../../test/vectors/src/merkle-tree/" -) - -func main() { - app := cli.NewApp() - serverFlags := []cli.Flag{ - &cli.UintFlag{ - Name: "statedb-port", - Usage: "StateDB server port", - Required: false, - Value: defaultStateDBPort, - }, - &cli.UintFlag{ - Name: "executor-port", - Usage: "Executor server port", - Required: false, - Value: defaultExecutorPort, - }, - &cli.StringFlag{ - Name: "test-vector-path", - Usage: "Test vector path", - Required: false, - Value: defaultTestVectorPath, - }, - &cli.StringFlag{ - Name: "host", - Usage: "Server host", - Required: false, - Value: "0.0.0.0", - }, - } - clientFlags := []cli.Flag{ - &cli.StringFlag{ - Name: "state-db-serveruri", - Usage: "StateDB server URI", - Required: false, - Value: fmt.Sprintf("127.0.0.1:%d", defaultStateDBPort), - }, - &cli.StringFlag{ - Name: "executor-serveruri", - Usage: "Executor server URI", - Required: false, - Value: fmt.Sprintf("127.0.0.1:%d", defaultExecutorPort), - }, - } - app.Commands = []*cli.Command{ - { - Name: "server", - Usage: "Run zkEVM Prover mock server", - Action: runServer, - Flags: serverFlags, - }, - { - Name: "client", - Usage: "Run zkEVM Prover mock client", - Action: runClient, - Flags: clientFlags, - }, - } - err := app.Run(os.Args) - if err != nil { - log.Fatal(err) - } -} diff --git a/tools/zkevmprovermock/cmd/server.go b/tools/zkevmprovermock/cmd/server.go deleted file mode 100644 index f4fd60d6c6..0000000000 --- a/tools/zkevmprovermock/cmd/server.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/0xPolygonHermez/zkevm-node/log" - stateDBPpb "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" - executorPb "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor/pb" - "github.com/0xPolygonHermez/zkevm-node/test/operations" - "github.com/0xPolygonHermez/zkevm-node/tools/zkevmprovermock/server" - "github.com/0xPolygonHermez/zkevm-node/tools/zkevmprovermock/testvector" - "github.com/spf13/afero" - "github.com/urfave/cli/v2" - "google.golang.org/grpc" -) - -func runServer(cliCtx *cli.Context) error { - log.Info("Running zkEVM Prover Server mock...") - - s := grpc.NewServer() - - aferoFs := afero.NewOsFs() - - tvContainer, err := testvector.NewContainer(cliCtx.String("test-vector-path"), aferoFs) - if err != nil { - log.Fatalf("Could not create test vector container: %v", err) - } - - stateDBAddress := fmt.Sprintf("%s:%d", cliCtx.String("host"), cliCtx.Uint("statedb-port")) - stateDBSrv := server.NewStateDBMock(stateDBAddress, tvContainer) - - stateDBPpb.RegisterStateDBServiceServer(s, stateDBSrv) - go stateDBSrv.Start() - - executorAddress := fmt.Sprintf("%s:%d", cliCtx.String("host"), cliCtx.Uint("executor-port")) - executorSrv := server.NewExecutorMock(executorAddress, tvContainer) - - executorPb.RegisterExecutorServiceServer(s, executorSrv) - go executorSrv.Start() - - operations.WaitSignal(func() { - stateDBSrv.Stop() - executorSrv.Stop() - }) - return nil -} diff --git a/tools/zkevmprovermock/server/executor.go b/tools/zkevmprovermock/server/executor.go deleted file mode 100644 index f629eef55a..0000000000 --- a/tools/zkevmprovermock/server/executor.go +++ /dev/null @@ -1,411 +0,0 @@ -package server - -import ( - "context" - "fmt" - "math/big" - "net" - "strconv" - "strings" - - "github.com/0xPolygonHermez/zkevm-node/encoding" - "github.com/0xPolygonHermez/zkevm-node/hex" - "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor/pb" - "github.com/0xPolygonHermez/zkevm-node/tools/zkevmprovermock/testvector" - "github.com/ethereum/go-ethereum/common" - "google.golang.org/grpc" -) - -const ( - bits64 = 64 - bits32 = 32 -) - -// ExecutorMock represents and Executor mock server -type ExecutorMock struct { - // address is the address on which the gRPC server will listen, eg. 0.0.0.0:50071 - address string - - tvContainer *testvector.Container - - // srv is an insance of the gRPC server. - srv *grpc.Server - - // embedding an instance of pb.UnimplementedExecutorServiceServer will allow us - // to implement all the required method interfaces. - pb.UnimplementedExecutorServiceServer -} - -// NewExecutorMock is the ExecutorMock constructor. -func NewExecutorMock(address string, tvContainer *testvector.Container) *ExecutorMock { - return &ExecutorMock{ - address: address, - tvContainer: tvContainer, - } -} - -// Start sets up the stateDB server to process requests. -func (server *ExecutorMock) Start() { - lis, err := net.Listen("tcp", server.address) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - - server.srv = grpc.NewServer() - pb.RegisterExecutorServiceServer(server.srv, server) - - log.Infof("Executor mock server: listening at %s", server.address) - if err := server.srv.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } -} - -// Stop stops the server. -func (server *ExecutorMock) Stop() { - log.Info("Executor mock server: stopping...") - server.srv.Stop() -} - -// ProcessBatch implements the ProcessBatch gRPC method. -func (server *ExecutorMock) ProcessBatch(ctx context.Context, request *pb.ProcessBatchRequest) (*pb.ProcessBatchResponse, error) { - processBatchResponse, err := server.tvContainer.FindProcessBatchResponse(hex.EncodeToString(request.BatchL2Data)) - if err != nil { - return nil, err - } - - cumulativeGasUSed, err := strconv.ParseUint(processBatchResponse.CumulativeGasUsed, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", processBatchResponse.CumulativeGasUsed, err) - } - - responses := []*pb.ProcessTransactionResponse{} - for _, response := range processBatchResponse.Responses { - newResponse, err := translateResponse(response) - if err != nil { - return nil, err - } - responses = append(responses, newResponse) - } - - if strings.HasPrefix(processBatchResponse.NewStateRoot, "0x") { // nolint - processBatchResponse.NewStateRoot = processBatchResponse.NewStateRoot[2:] - } - if strings.HasPrefix(processBatchResponse.NewLocalExitRoot, "0x") { // nolint - processBatchResponse.NewLocalExitRoot = processBatchResponse.NewLocalExitRoot[2:] - } - - return &pb.ProcessBatchResponse{ - CumulativeGasUsed: cumulativeGasUSed, - Responses: responses, - NewStateRoot: common.Hex2Bytes(processBatchResponse.NewStateRoot), - NewLocalExitRoot: common.Hex2Bytes(processBatchResponse.NewLocalExitRoot), - CntKeccakHashes: processBatchResponse.CntKeccakHashes, - CntPoseidonHashes: processBatchResponse.CntPoseidonHashes, - CntPoseidonPaddings: processBatchResponse.CntPoseidonPaddings, - CntMemAligns: processBatchResponse.CntMemAligns, - CntArithmetics: processBatchResponse.CntArithmetics, - CntBinaries: processBatchResponse.CntBinaries, - CntSteps: processBatchResponse.CntSteps, - }, nil -} - -func translateResponse(response *testvector.ProcessTransactionResponse) (*pb.ProcessTransactionResponse, error) { - var err error - - var gasLeft uint64 - if response.GasLeft != "" { - gasLeft, err = strconv.ParseUint(response.GasLeft, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", response.GasLeft, err) - } - } - - var gasUsed uint64 - if response.GasUsed != "" { - gasUsed, err = strconv.ParseUint(response.GasUsed, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", response.GasUsed, err) - } - } - - var gasRefunded uint64 - if response.GasRefunded != "" { - gasRefunded, err = strconv.ParseUint(response.GasRefunded, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", response.GasRefunded, err) - } - } - - logs, err := translateLogs(response.Logs) - if err != nil { - return nil, err - } - - callTrace, err := translateCallTrace(response.CallTrace) - if err != nil { - return nil, err - } - - if strings.HasPrefix(response.TxHash, "0x") { // nolint - response.TxHash = response.TxHash[2:] - } - if strings.HasPrefix(response.StateRoot, "0x") { // nolint - response.StateRoot = response.StateRoot[2:] - } - - return &pb.ProcessTransactionResponse{ - TxHash: common.Hex2Bytes(response.TxHash), - Type: response.Type, - GasLeft: gasLeft, - GasUsed: gasUsed, - GasRefunded: gasRefunded, - StateRoot: common.Hex2Bytes(response.StateRoot), - Logs: logs, - CallTrace: callTrace, - }, nil -} - -func translateLogs(inputLogs []*testvector.Log) ([]*pb.Log, error) { - logs := []*pb.Log{} - - for _, log := range inputLogs { - topics := [][]byte{} - - for _, topic := range log.Topics { - newTopic, err := hex.DecodeString(topic) - if err != nil { - return nil, err - } - topics = append(topics, newTopic) - } - - data := []byte{} - var err error - if len(log.Data) > 0 { - data, err = hex.DecodeString(log.Data[0]) - if err != nil { - return nil, err - } - } - - if strings.HasPrefix(log.TxHash, "0x") { // nolint - log.TxHash = log.TxHash[2:] - } - if strings.HasPrefix(log.BatchHash, "0x") { // nolint - log.BatchHash = log.BatchHash[2:] - } - - newLog := &pb.Log{ - Address: log.Address, - Topics: topics, - Data: data, - BatchNumber: log.BatchNumber, - TxHash: common.Hex2Bytes(log.TxHash), - TxIndex: log.TxIndex, - BatchHash: common.Hex2Bytes(log.BatchHash), - Index: log.Index, - } - - logs = append(logs, newLog) - } - return logs, nil -} - -func translateCallTrace(callTrace *testvector.CallTrace) (*pb.CallTrace, error) { - ctx, err := translateTransactionContext(callTrace.Context) - if err != nil { - return nil, err - } - - steps, err := translateTransactionSteps(callTrace.Steps) - if err != nil { - return nil, err - } - - return &pb.CallTrace{ - Context: ctx, - Steps: steps, - }, nil -} - -func translateTransactionContext(ctx *testvector.TransactionContext) (*pb.TransactionContext, error) { - var err error - var gas uint64 - if ctx.Gas != "" { - gas, err = strconv.ParseUint(ctx.Gas, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", ctx.Gas, err) - } - } - var value uint64 - if ctx.Value != "" { - value, err = strconv.ParseUint(ctx.Value, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", ctx.Value, err) - } - } - - var gasUsed uint64 - if ctx.GasUsed != "" { - gasUsed, err = strconv.ParseUint(ctx.GasUsed, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", ctx.GasUsed, err) - } - } - - var gasPrice uint64 - if ctx.GasPrice != "" { - gasPrice, err = strconv.ParseUint(ctx.GasPrice, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", ctx.GasPrice, err) - } - } - - var executionTime uint64 - if ctx.ExecutionTime != "" { - executionTime, err = strconv.ParseUint(ctx.ExecutionTime, encoding.Base10, bits32) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint32: %v", ctx.ExecutionTime, err) - } - } - if strings.HasPrefix(ctx.Data, "0x") { // nolint - ctx.Data = ctx.Data[2:] - } - if strings.HasPrefix(ctx.Batch, "0x") { // nolint - ctx.Batch = ctx.Batch[2:] - } - if strings.HasPrefix(ctx.Output, "0x") { // nolint - ctx.Output = ctx.Output[2:] - } - if strings.HasPrefix(ctx.OldStateRoot, "0x") { // nolint - ctx.OldStateRoot = ctx.OldStateRoot[2:] - } - - return &pb.TransactionContext{ - Type: ctx.Type, - From: ctx.From, - To: ctx.To, - Data: common.Hex2Bytes(ctx.Data), - Gas: gas, - Value: new(big.Int).SetUint64(value).String(), - GasUsed: gasUsed, - Batch: common.Hex2Bytes(ctx.Batch), - Output: common.Hex2Bytes(ctx.Output), - GasPrice: new(big.Int).SetUint64(gasPrice).String(), - ExecutionTime: uint32(executionTime), - OldStateRoot: common.Hex2Bytes(ctx.OldStateRoot), - }, nil -} - -func translateTransactionSteps(inputSteps []*testvector.TransactionStep) ([]*pb.TransactionStep, error) { - steps := []*pb.TransactionStep{} - - for _, inputStep := range inputSteps { - contract, err := translateContract(inputStep.Contract) - if err != nil { - return nil, err - } - - var gas uint64 - if inputStep.RemainingGas != "" { - gas, err = strconv.ParseUint(inputStep.RemainingGas, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", inputStep.RemainingGas, err) - } - } - var gasCost uint64 - if inputStep.GasCost != "" { - gasCost, err = strconv.ParseUint(inputStep.GasCost, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", inputStep.GasCost, err) - } - } - var gasRefund uint64 - if inputStep.GasRefund != "" { - gasRefund, err = strconv.ParseUint(inputStep.GasRefund, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", inputStep.GasRefund, err) - } - } - var op uint64 - if inputStep.Op != "" { - if strings.HasPrefix(inputStep.Op, "0x") { // nolint - inputStep.Op = inputStep.Op[2:] - } - opBI, ok := new(big.Int).SetString(inputStep.Op, hex.Base) - if !ok { - return nil, fmt.Errorf("Could not convert base16 %q to big int", inputStep.Op) - } - op = opBI.Uint64() - } - var pbErr uint64 - if inputStep.Error != "" { - pbErr, err = strconv.ParseUint(inputStep.Error, encoding.Base10, bits32) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint32: %v", inputStep.Error, err) - } - } - - if strings.HasPrefix(inputStep.StateRoot, "0x") { // nolint - inputStep.StateRoot = inputStep.StateRoot[2:] - } - - memory := []byte{} - if len(inputStep.Memory) > 0 { - memory = common.Hex2Bytes(inputStep.Memory[0]) - } - returnData := []byte{} - if len(inputStep.ReturnData) > 0 { - returnData = common.Hex2Bytes(inputStep.ReturnData[0]) - } - - newStep := &pb.TransactionStep{ - StateRoot: common.Hex2Bytes(inputStep.StateRoot), - Depth: inputStep.Depth, - Pc: inputStep.Pc, - Gas: gas, - GasCost: gasCost, - GasRefund: gasRefund, - Op: uint32(op), - Stack: inputStep.Stack, - Memory: memory, - ReturnData: returnData, - Contract: contract, - Error: pb.RomError(pbErr), - } - steps = append(steps, newStep) - } - - return steps, nil -} - -func translateContract(contract *testvector.Contract) (*pb.Contract, error) { - var err error - var value uint64 - if contract.Value != "" { - value, err = strconv.ParseUint(contract.Value, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", contract.Value, err) - } - } - var gas uint64 - if contract.Gas != "" { - gas, err = strconv.ParseUint(contract.Gas, encoding.Base10, bits64) - if err != nil { - return nil, fmt.Errorf("Could not convert %q to uint64: %v", contract.Gas, err) - } - } - - if strings.HasPrefix(contract.Data, "0x") { // nolint - contract.Data = contract.Data[2:] - } - - return &pb.Contract{ - Address: contract.Address, - Caller: contract.Caller, - Data: common.Hex2Bytes(contract.Data), - Value: new(big.Int).SetUint64(value).String(), - Gas: gas, - }, nil -} diff --git a/tools/zkevmprovermock/server/statedb.go b/tools/zkevmprovermock/server/statedb.go deleted file mode 100644 index fa967ea650..0000000000 --- a/tools/zkevmprovermock/server/statedb.go +++ /dev/null @@ -1,158 +0,0 @@ -package server - -import ( - "context" - "fmt" - "math/big" - "net" - "strings" - - "github.com/0xPolygonHermez/zkevm-node/encoding" - "github.com/0xPolygonHermez/zkevm-node/hex" - "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/merkletree" - "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" - "github.com/0xPolygonHermez/zkevm-node/tools/zkevmprovermock/testvector" - "google.golang.org/grpc" -) - -// StateDBMock represents a StateDB mock server. -type StateDBMock struct { - // address is the address on which the gRPC server will listen, eg. 0.0.0.0:50061 - address string - - tvContainer *testvector.Container - - // srv is an insance of the gRPC server. - srv *grpc.Server - // embedding an instance of pb.UnimplementedStateDBServiceServer will allow us - // to implement all the required method interfaces. - pb.UnimplementedStateDBServiceServer -} - -// NewStateDBMock is the StateDBMock constructor. -func NewStateDBMock(address string, tvContainer *testvector.Container) *StateDBMock { - return &StateDBMock{ - address: address, - tvContainer: tvContainer, - } -} - -// Start sets up the stateDB server to process requests. -func (server *StateDBMock) Start() { - lis, err := net.Listen("tcp", server.address) - if err != nil { - log.Fatalf("failed to listen: %v", err) - } - - server.srv = grpc.NewServer() - pb.RegisterStateDBServiceServer(server.srv, server) - - log.Infof("StateDB mock server: listening at %s", server.address) - if err := server.srv.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) - } -} - -// Stop stops the server. -func (server *StateDBMock) Stop() { - log.Info("StateDB mock server: stopping...") - server.srv.Stop() -} - -// Set is the mock of the method for setting values in the tree. -func (server *StateDBMock) Set(ctx context.Context, request *pb.SetRequest) (*pb.SetResponse, error) { - keyBIStr, err := getKeyBIStr(request.Key) - if err != nil { - return nil, err - } - - oldRootStr := merkletree.H4ToString([]uint64{request.OldRoot.Fe0, request.OldRoot.Fe1, request.OldRoot.Fe2, request.OldRoot.Fe3}) - log.Debugf("Set called with key %v, value %v, root %v", keyBIStr, request.Value, oldRootStr) - _, newRoot, err := server.tvContainer.FindSMTValue(keyBIStr, oldRootStr) - if err != nil { - return nil, err - } - h4NewRoot, err := merkletree.StringToh4(newRoot) - if err != nil { - return nil, err - } - return &pb.SetResponse{ - NewRoot: &pb.Fea{Fe0: h4NewRoot[0], Fe1: h4NewRoot[1], Fe2: h4NewRoot[2], Fe3: h4NewRoot[3]}, - }, nil -} - -// Get is the mock of the method for getting values from the tree. -func (server *StateDBMock) Get(ctx context.Context, request *pb.GetRequest) (*pb.GetResponse, error) { - keyBIStr, err := getKeyBIStr(request.Key) - if err != nil { - return nil, err - } - - rootStr := merkletree.H4ToString([]uint64{request.Root.Fe0, request.Root.Fe1, request.Root.Fe2, request.Root.Fe3}) - - value, _, err := server.tvContainer.FindSMTValue(keyBIStr, rootStr) - if err != nil { - return nil, err - } - valueBI, ok := new(big.Int).SetString(value, encoding.Base10) - if !ok { - return nil, fmt.Errorf("Could not convert base 10 %q to big.Int", value) - } - valueHex := hex.EncodeBig(valueBI)[2:] - - log.Debugf("Get called with key %v, root %v, returning value %v", keyBIStr, rootStr, valueHex) - return &pb.GetResponse{ - Value: valueHex, - }, nil -} - -// SetProgram is the mock of the method for setting SC contents in the tree. -func (server *StateDBMock) SetProgram(ctx context.Context, request *pb.SetProgramRequest) (*pb.SetProgramResponse, error) { - keyBIStr, err := getKeyBIStr(request.Key) - if err != nil { - return nil, err - } - - _, err = server.tvContainer.FindBytecode(keyBIStr) - if err != nil { - return nil, err - } - return &pb.SetProgramResponse{}, nil -} - -// GetProgram is the mock of the method for getting SC contents from the tree. -func (server *StateDBMock) GetProgram(ctx context.Context, request *pb.GetProgramRequest) (*pb.GetProgramResponse, error) { - keyBIStr, err := getKeyBIStr(request.Key) - if err != nil { - return nil, err - } - - bytecode, err := server.tvContainer.FindBytecode(keyBIStr) - if err != nil { - return nil, err - } - data, err := hex.DecodeHex(bytecode) - if err != nil { - return nil, err - } - return &pb.GetProgramResponse{ - Data: data, - }, nil -} - -func getKeyBIStr(key *pb.Fea) (string, error) { - keyStr := merkletree.H4ToString([]uint64{key.Fe0, key.Fe1, key.Fe2, key.Fe3}) - - if strings.HasPrefix(keyStr, "0x") { // nolint - keyStr = keyStr[2:] - } - - keyBI, ok := new(big.Int).SetString(keyStr, hex.Base) - if !ok { - return "", fmt.Errorf("Could not convert the hex string %q into big.Int", keyStr) - } - keyBytes := merkletree.ScalarToFilledByteSlice(keyBI) - - return new(big.Int).SetBytes(keyBytes).String(), nil -} diff --git a/tools/zkevmprovermock/testvector/main.go b/tools/zkevmprovermock/testvector/main.go deleted file mode 100644 index 8e7bc40316..0000000000 --- a/tools/zkevmprovermock/testvector/main.go +++ /dev/null @@ -1,229 +0,0 @@ -package testvector - -import ( - "encoding/json" - "fmt" - "os" - "strings" - - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/ethereum/go-ethereum/common" - "github.com/spf13/afero" -) - -// E2E contains all the test vectors. -type E2E struct { - Items []*E2EItem -} - -// E2EItem contains an end-to-end test vector. -type E2EItem struct { - BatchL2Data string - GlobalExitRoot string - Traces *Traces - GenesisRaw []*state.GenesisAction -} - -// Traces represents executor processing traces. -type Traces struct { - BatchHash string - OldStateRoot string `json:"old_state_root"` - GlobalHash string - NumBatch uint64 - Timestamp uint64 - SequencerAddr string - - *ProcessBatchResponse -} - -// ProcessBatchResponse contains information about the executor response to a -// ProcessBatch request. -type ProcessBatchResponse struct { - CumulativeGasUsed string `json:"cumulative_gas_used,omitempty"` - Responses []*ProcessTransactionResponse `json:"responses,omitempty"` - NewStateRoot string `json:"new_state_root,omitempty"` - NewLocalExitRoot string `json:"new_local_exit_root,omitempty"` - CntKeccakHashes uint32 `json:"cnt_keccak_hashes,omitempty"` - CntPoseidonHashes uint32 `json:"cnt_poseidon_hashes,omitempty"` - CntPoseidonPaddings uint32 `json:"cnt_poseidon_paddings,omitempty"` - CntMemAligns uint32 `json:"cnt_mem_aligns,omitempty"` - CntArithmetics uint32 `json:"cnt_arithmetics,omitempty"` - CntBinaries uint32 `json:"cnt_binaries,omitempty"` - CntSteps uint32 `json:"cnt_steps,omitempty"` -} - -// ProcessTransactionResponse contains information about the executor response to a -// transaction execution. -type ProcessTransactionResponse struct { - TxHash string `json:"tx_hash"` - Type uint32 - GasLeft string `json:"gas_left"` - GasUsed string `json:"gas_used"` - GasRefunded string `json:"gas_refunded"` - StateRoot string `json:"state_root"` - Logs []*Log - UnprocessedTransaction bool `json:"unprocessed_transaction,omitempty"` - CallTrace *CallTrace `json:"call_trace,omitempty"` -} - -// Log represent logs emitted by LOG opcode. -type Log struct { - Data []string - Topics []string - Address string - BatchNumber uint64 `json:"batch_number"` - TxHash string `json:"tx_hash"` - TxIndex uint32 `json:"tx_index"` - BatchHash string `json:"batch_hash"` - Index uint32 -} - -// CallTrace represents the batch call trace. -type CallTrace struct { - Context *TransactionContext `json:"context,omitempty"` - Steps []*TransactionStep `json:"steps,omitempty"` -} - -// TransactionContext represents a transaction's context. -type TransactionContext struct { - From string `json:"from,omitempty"` - To string `json:"to,omitempty"` - Type string `json:"type,omitempty"` - Data string `json:"data,omitempty"` - Gas string `json:"gas,omitempty"` - Value string `json:"value,omitempty"` - Batch string `json:"batch,omitempty"` - Output string `json:"output,omitempty"` - GasUsed string `json:"gas_used,omitempty"` - ExecutionTime string `json:"execution_time,omitempty"` - OldStateRoot string `json:"old_state_root,omitempty"` - GasPrice string `json:"gasPrice,omitempty"` -} - -// TransactionStep represents a transaction's step. -type TransactionStep struct { - Depth uint32 `json:"depth,omitempty"` - Pc uint64 `json:"pc,omitempty"` - RemainingGas string `json:"remaining_gas,omitempty"` - OpCode string - GasRefund string `json:"gas_refund,omitempty"` - Op string `json:"op,omitempty"` - Error string - StateRoot string `json:"state_root"` - Contract *Contract `json:"contract,omitempty"` - ReturnData []string `json:"return_data,omitempty"` - GasCost string `json:"gas_cost"` - Stack []string - Memory []string -} - -// Contract contains information about SCs executed in a batch. -type Contract struct { - Address string `json:"address,omitempty"` - Caller string `json:"caller,omitempty"` - Value string `json:"value,omitempty"` - Data string `json:"data,omitempty"` - Gas string `json:"gas,omitempty"` -} - -// Container is a wrapper for test vectors. -type Container struct { - E2E *E2E -} - -// NewContainer is the Container constructor. -func NewContainer(testVectorPath string, aferoFs afero.Fs) (*Container, error) { - e2e, err := getE2E(testVectorPath, aferoFs) - if err != nil { - return nil, err - } - - return &Container{ - E2E: e2e, - }, nil -} - -// FindSMTValue searches for the given key on all the genesisRaw items present, -// checking also that the given root was the root returned by the previous item. -// If both the value and the root of the previous item match it returns the -// associated value and new root. -func (c *Container) FindSMTValue(inputKey, oldRoot string) (value, newRoot string, err error) { - zero := common.HexToHash("").String() - var lastValue string - for _, item := range c.E2E.Items { - for index, action := range item.GenesisRaw { - if action.Key == inputKey { - if index > 0 && oldRoot == item.GenesisRaw[index-1].Root || - index == 0 && oldRoot == zero { - return item.GenesisRaw[index].Value, item.GenesisRaw[index].Root, nil - } else { - lastValue = item.GenesisRaw[index].Value - } - } - } - if len(item.GenesisRaw) > 0 && - oldRoot == item.GenesisRaw[len(item.GenesisRaw)-1].Root && - lastValue != "" { - return lastValue, oldRoot, nil - } - } - return "", "", fmt.Errorf("key %q not found for oldRoot %q", inputKey, oldRoot) -} - -// FindBytecode searches for the given key on the value fields of all the -// genesisRaw items present and returns the associated bytecode field on match. -func (c *Container) FindBytecode(inputKey string) (bytecode string, err error) { - for _, item := range c.E2E.Items { - for index, action := range item.GenesisRaw { - if action.Value == inputKey && action.Bytecode != "" { - return item.GenesisRaw[index].Bytecode, nil - } - } - } - return "", fmt.Errorf("bytecode for key %q not found", inputKey) -} - -// FindProcessBatchResponse searches for the responses to a process batch -// request identified by tge batch L2 data. -func (c *Container) FindProcessBatchResponse(batchL2Data string) (*ProcessBatchResponse, error) { - for _, item := range c.E2E.Items { - if strings.Replace(item.BatchL2Data, "0x", "", -1) == strings.Replace(batchL2Data, "0x", "", -1) { - return item.Traces.ProcessBatchResponse, nil - } - } - return nil, fmt.Errorf("ProcessBatchResponse for batchL2Data %q not found", batchL2Data) -} - -func getE2E(testVectorPath string, aferoFs afero.Fs) (*E2E, error) { - e2e := &E2E{} - - err := afero.Walk(aferoFs, testVectorPath, func(wpath string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if info == nil || info.IsDir() { - return nil - } - e2eFile, err := getE2EFile(wpath, aferoFs) - if err != nil { - return err - } - e2e.Items = append(e2e.Items, e2eFile.Items...) - - return nil - }) - - return e2e, err -} - -func getE2EFile(filePath string, aferoFs afero.Fs) (*E2E, error) { - contents, err := afero.ReadFile(aferoFs, filePath) - if err != nil { - return nil, err - } - var e2e E2E - if err := json.Unmarshal(contents, &e2e.Items); err != nil { - return nil, err - } - return &e2e, nil -} diff --git a/tools/zkevmprovermock/testvector/testvector_test.go b/tools/zkevmprovermock/testvector/testvector_test.go deleted file mode 100644 index f391049c9e..0000000000 --- a/tools/zkevmprovermock/testvector/testvector_test.go +++ /dev/null @@ -1,859 +0,0 @@ -package testvector_test - -import ( - "fmt" - "path/filepath" - "testing" - - "github.com/0xPolygonHermez/zkevm-node/state" - "github.com/0xPolygonHermez/zkevm-node/test/testutils" - "github.com/0xPolygonHermez/zkevm-node/tools/zkevmprovermock/testvector" - "github.com/spf13/afero" - "github.com/stretchr/testify/require" -) - -func TestNewContainer(t *testing.T) { - const defaultSourceDir = "/a/b/c" - - tcs := []struct { - description string - sourceFiles map[string]string - testVectorPath string - expectedContainer *testvector.Container - expectedError bool - expectedErrorMsg string - }{ - { - description: "happy path, single file", - sourceFiles: map[string]string{ - filepath.Join(defaultSourceDir, "a.json"): `[ -{ - "batchL2Data": "0xabc123456", - "globalExitRoot": "0x1234abcd", - "traces": { - "batchHash": "batchHash", - "old_state_root": "old_state_root", - "globalHash": "globalHash", - "numBatch": 1, - "timestamp": 1944498031, - "sequencerAddr": "sequencerAddr", - "responses": [ - { - "tx_hash": "0xabc", - "type": 0, - "gas_left": "28099", - "gas_used": "71901", - "gas_refunded": "0", - "state_root": "0x2031e0233b733481aa0e8c1056b874d68731fc0c673248538f7acfb81d2d7764", - "logs": [ - { - "data": [ - "000000000000000000000002540be400" - ], - "topics": [ - "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "00000000000000000000000000000000", - "4d5cf5032b2a844602278b01199ed191a86c93ff" - ], - "address": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - "batch_number": 1, - "tx_hash": "0xeeb51664fd2b6dcf865de752589f59f29b8398bdc38b5f556715ae88615c4641", - "tx_index": 0, - "batch_hash": "0x7624c022e923e798a6682171fd27b54912c426cfd92d49fb6be3bf300ba27679", - "index": 0 - } - ], - "unprocessed_transaction": false, - "call_trace": { - "context": { - "from": "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d", - "to": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - "type": "CALL", - "data": "0x40c10f190000000000000000000000004d5cf5032b2a844602278b01199ed191a86c93ff00000000000000000000000000000000000000000000000000000002540be400", - "gas": "100000", - "value": "0", - "batch": "0x7624c022e923e798a6682171fd27b54912c426cfd92d49fb6be3bf300ba27679", - "output": "", - "gas_used": "71901", - "execution_time": "", - "old_state_root": "0x2031e0233b733481aa0e8c1056b874d68731fc0c673248538f7acfb81d2d7764", - "nonce": 0, - "gasPrice": "1000000000", - "chainId": 1000, - "return_value": [] - }, - "steps": [ - { - "depth": 1, - "pc": 0, - "remaining_gas": "78392", - "opcode": "PUSH1", - "gas_refund": "0", - "op": "0x60", - "error": "", - "state_root": "0xdf403125ab76e36f1fb313619e704e4630b984bd93c3121b3775b71d1b72f9c6", - "contract": { - "address": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - "caller": "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d", - "value": "0", - "data": "0x40c10f190000000000000000000000004d5cf5032b2a844602278b01199ed191a86c93ff00000000000000000000000000000000000000000000000000000002540be40000000000000000000000000000000000000000000000000000000000", - "gas": "100000" - }, - "return_data": [], - "gas_cost": "3", - "stack": [ - "0x80" - ], - "memory": [] - } - ] - } - } - ], - "cumulative_gas_used": "171380", - "new_state_root": "0xb6f5c8f596b7130c7c7eb3257e80badfd7a89aa2977cc6d521a8b97f764230f5", - "new_local_exit_root": "0x00", - "cnt_keccak_hashes": 1, - "cnt_poseidon_hashes": 1, - "cnt_poseidon_paddings": 1, - "cnt_mem_aligns": 1, - "cnt_arithmetics": 1, - "cnt_binaries": 1, - "cnt_steps": 1 - }, - "genesisRaw": [ - { - "address": "addressRaw0", - "type": 0, - "key": "keyRaw0", - "value": "valueRaw0" - }, - { - "address": "addressRaw1", - "type": 1, - "key": "keyRaw1", - "value": "valueRaw1" - }, - { - "address": "addressRaw2", - "type": 2, - "key": "keyRaw2", - "value": "valueRaw2", - "bytecode": "bytecodeRaw2" - }, - { - "address": "addressRaw3", - "type": 3, - "key": "keyRaw3", - "value": "valueRaw3", - "storagePosition": "storagePositionRaw3" - }, - { - "address": "addressRaw4", - "type": 4, - "key": "keyRaw4", - "value": "valueRaw4" - } - ] -} -]`, - }, - testVectorPath: defaultSourceDir, - expectedContainer: &testvector.Container{ - E2E: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - BatchL2Data: "0xabc123456", - GlobalExitRoot: "0x1234abcd", - Traces: &testvector.Traces{ - BatchHash: "batchHash", - OldStateRoot: "old_state_root", - GlobalHash: "globalHash", - NumBatch: 1, - Timestamp: 1944498031, - SequencerAddr: "sequencerAddr", - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - Responses: []*testvector.ProcessTransactionResponse{ - { - TxHash: "0xabc", - Type: 0, - GasLeft: "28099", - GasUsed: "71901", - GasRefunded: "0", - StateRoot: "0x2031e0233b733481aa0e8c1056b874d68731fc0c673248538f7acfb81d2d7764", - Logs: []*testvector.Log{ - { - Data: []string{"000000000000000000000002540be400"}, - Topics: []string{ - "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "00000000000000000000000000000000", - "4d5cf5032b2a844602278b01199ed191a86c93ff", - }, - Address: "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - BatchNumber: 1, - TxHash: "0xeeb51664fd2b6dcf865de752589f59f29b8398bdc38b5f556715ae88615c4641", - TxIndex: 0, - BatchHash: "0x7624c022e923e798a6682171fd27b54912c426cfd92d49fb6be3bf300ba27679", - Index: 0, - }, - }, - UnprocessedTransaction: false, - CallTrace: &testvector.CallTrace{ - Context: &testvector.TransactionContext{ - From: "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d", - To: "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - Type: "CALL", - Data: "0x40c10f190000000000000000000000004d5cf5032b2a844602278b01199ed191a86c93ff00000000000000000000000000000000000000000000000000000002540be400", - Gas: "100000", - Value: "0", - Batch: "0x7624c022e923e798a6682171fd27b54912c426cfd92d49fb6be3bf300ba27679", - Output: "", - GasUsed: "71901", - ExecutionTime: "", - OldStateRoot: "0x2031e0233b733481aa0e8c1056b874d68731fc0c673248538f7acfb81d2d7764", - GasPrice: "1000000000", - }, - - Steps: []*testvector.TransactionStep{ - { - Depth: 1, - Pc: 0, - RemainingGas: "78392", - OpCode: "PUSH1", - GasRefund: "0", - Op: "0x60", - StateRoot: "0xdf403125ab76e36f1fb313619e704e4630b984bd93c3121b3775b71d1b72f9c6", - Contract: &testvector.Contract{ - Address: "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98", - Caller: "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d", - Value: "0", - Data: "0x40c10f190000000000000000000000004d5cf5032b2a844602278b01199ed191a86c93ff00000000000000000000000000000000000000000000000000000002540be40000000000000000000000000000000000000000000000000000000000", - Gas: "100000", - }, - ReturnData: []string{}, - GasCost: "3", - Stack: []string{"0x80"}, - Memory: []string{}, - }, - }, - }, - }, - }, - CumulativeGasUsed: "171380", - NewStateRoot: "0xb6f5c8f596b7130c7c7eb3257e80badfd7a89aa2977cc6d521a8b97f764230f5", - NewLocalExitRoot: "0x00", - CntKeccakHashes: 1, - CntPoseidonHashes: 1, - CntPoseidonPaddings: 1, - CntMemAligns: 1, - CntArithmetics: 1, - CntBinaries: 1, - CntSteps: 1, - }, - }, - GenesisRaw: []*state.GenesisAction{ - { - Address: "addressRaw0", - Type: 0, - Key: "keyRaw0", - Value: "valueRaw0", - }, - { - Address: "addressRaw1", - Type: 1, - Key: "keyRaw1", - Value: "valueRaw1", - }, - { - Address: "addressRaw2", - Type: 2, - Key: "keyRaw2", - Value: "valueRaw2", - Bytecode: "bytecodeRaw2", - }, - { - Address: "addressRaw3", - Type: 3, - Key: "keyRaw3", - Value: "valueRaw3", - StoragePosition: "storagePositionRaw3", - }, - { - Address: "addressRaw4", - Type: 4, - Key: "keyRaw4", - Value: "valueRaw4", - }, - }, - }, - }, - }, - }, - }, - { - description: "happy path, multiple files", - sourceFiles: map[string]string{ - filepath.Join(defaultSourceDir, "a.json"): `[ -{ - "genesisRaw": [ - { - "address": "addressRaw0", - "type": 0, - "key": "keyRaw0", - "value": "valueRaw0" - } - ] -} -]`, - filepath.Join(defaultSourceDir, "b.json"): `[ -{ - "genesisRaw": [ - { - "address": "addressRaw1", - "type": 1, - "key": "keyRaw1", - "value": "valueRaw1" - } - ] -} -]`, - }, - testVectorPath: defaultSourceDir, - expectedContainer: &testvector.Container{ - E2E: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Address: "addressRaw0", - Type: 0, - Key: "keyRaw0", - Value: "valueRaw0", - }, - }, - }, - { - GenesisRaw: []*state.GenesisAction{ - { - Address: "addressRaw1", - Type: 1, - Key: "keyRaw1", - Value: "valueRaw1", - }, - }, - }, - }, - }, - }, - }, - { - description: "invalid test vector causes error", - sourceFiles: map[string]string{ - filepath.Join(defaultSourceDir, "a.json"): "not a real json", - }, - testVectorPath: defaultSourceDir, - expectedError: true, - expectedErrorMsg: "invalid character 'o' in literal null (expecting 'u')", - }, - { - description: "empty test vector path returns empty object", - sourceFiles: map[string]string{}, - testVectorPath: defaultSourceDir, - expectedError: true, - expectedErrorMsg: fmt.Sprintf("open %s: file does not exist", defaultSourceDir), - }, - } - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - var appFs = afero.NewMemMapFs() - - require.NoError(t, testutils.CreateTestFiles(appFs, tc.sourceFiles)) - - actualContainer, err := testvector.NewContainer(tc.testVectorPath, appFs) - - require.NoError(t, testutils.CheckError(err, tc.expectedError, tc.expectedErrorMsg)) - - if err == nil { - require.Equal(t, tc.expectedContainer.E2E.Items, actualContainer.E2E.Items) - } - }) - } -} - -func TestFindSMTValue(t *testing.T) { - tcs := []struct { - description string - e2e *testvector.E2E - key string - oldRoot string - expectedValue string - expectedNewRoot string - expectedError bool - expectedErrorMsg string - }{ - { - description: "happy path, single item", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - }, - }, - }, - }, - key: "key2", - oldRoot: "root1", - expectedValue: "value2", - expectedNewRoot: "root2", - }, - { - description: "happy path, multiple items", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key3", - Value: "value3", - Root: "root3", - }, - { - Key: "key4", - Value: "value4", - Root: "root4", - }, - }, - }, - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - }, - }, - }, - }, - key: "key2", - oldRoot: "root1", - expectedValue: "value2", - expectedNewRoot: "root2", - }, - { - description: "happy path, first item requires zero root", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - }, - }, - }, - }, - key: "key1", - oldRoot: "0x0000000000000000000000000000000000000000000000000000000000000000", - expectedValue: "value1", - expectedNewRoot: "root1", - }, - { - description: "happy path, querying existing key and last root returns last value of the key", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - { - Key: "key1", - Value: "value3", - Root: "root2", - }, - { - Key: "key4", - Value: "value4", - Root: "root4", - }, - }, - }, - }, - }, - key: "key1", - oldRoot: "root4", - expectedValue: "value3", - expectedNewRoot: "root4", - }, - { - description: "unexisting key gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - }, - }, - }, - }, - key: "key10", - oldRoot: "root1", - expectedError: true, - expectedErrorMsg: `key "key10" not found for oldRoot "root1"`, - }, - { - description: "unmatched root gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Key: "key1", - Value: "value1", - Root: "root1", - }, - { - Key: "key2", - Value: "value2", - Root: "root2", - }, - }, - }, - }, - }, - key: "key1", - oldRoot: "root3", - expectedError: true, - expectedErrorMsg: `key "key1" not found for oldRoot "root3"`, - }, - { - description: "empty GenesisRaw gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - {}, - }, - }, - key: "key1", - oldRoot: "root2", - expectedError: true, - expectedErrorMsg: `key "key1" not found for oldRoot "root2"`, - }, - } - - subject := &testvector.Container{} - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - subject.E2E = tc.e2e - - actualValue, actualRoot, err := subject.FindSMTValue(tc.key, tc.oldRoot) - require.NoError(t, testutils.CheckError(err, tc.expectedError, tc.expectedErrorMsg)) - - if err == nil { - require.Equal(t, tc.expectedValue, actualValue) - require.Equal(t, tc.expectedNewRoot, actualRoot) - } - }) - } -} - -func TestFindBytecode(t *testing.T) { - tcs := []struct { - description string - e2e *testvector.E2E - key string - expectedBytecode string - expectedError bool - expectedErrorMsg string - }{ - { - description: "happy path, single item", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Value: "key1", - Bytecode: "bytecode1", - }, - { - Value: "key2", - Bytecode: "bytecode2", - }, - }, - }, - }, - }, - key: "key2", - expectedBytecode: "bytecode2", - }, - { - description: "happy path, multiple items", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Value: "key3", - Bytecode: "bytecode3", - }, - { - Value: "key4", - Bytecode: "bytecode4", - }, - }, - }, - { - GenesisRaw: []*state.GenesisAction{ - { - Value: "key1", - Bytecode: "bytecode1", - }, - { - Value: "key2", - Bytecode: "bytecode2", - }, - }, - }, - }, - }, - key: "key2", - expectedBytecode: "bytecode2", - }, - { - description: "unexisting key gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Value: "key1", - Bytecode: "bytecode1", - }, - { - Value: "key2", - Bytecode: "bytecode2", - }, - }, - }, - }, - }, - key: "key10", - expectedError: true, - expectedErrorMsg: `bytecode for key "key10" not found`, - }, - { - description: "empty GenesisRaw gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - {}, - }, - }, - key: "key1", - expectedError: true, - expectedErrorMsg: `bytecode for key "key1" not found`, - }, - { - description: "empty bytecode for matching key gives error", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - GenesisRaw: []*state.GenesisAction{ - { - Value: "key1", - }, - }, - }, - }, - }, - key: "key1", - expectedError: true, - expectedErrorMsg: `bytecode for key "key1" not found`, - }, - } - - subject := &testvector.Container{} - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - subject.E2E = tc.e2e - - actualBytecode, err := subject.FindBytecode(tc.key) - require.NoError(t, testutils.CheckError(err, tc.expectedError, tc.expectedErrorMsg)) - - if err == nil { - require.Equal(t, tc.expectedBytecode, actualBytecode) - } - }) - } -} - -func TestFindProcessBatchResponse(t *testing.T) { - tcs := []struct { - description string - e2e *testvector.E2E - batchL2Data string - expectedResponse *testvector.ProcessBatchResponse - expectedError bool - expectedErrorMsg string - }{ - { - description: "happy path, single item", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - BatchL2Data: "0xabc", - Traces: &testvector.Traces{ - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - }, - }, - }, - batchL2Data: "0xabc", - expectedResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - { - description: "happy path, no leading 0x in id", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - BatchL2Data: "0xabc", - Traces: &testvector.Traces{ - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - }, - }, - }, - batchL2Data: "abc", - expectedResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - { - description: "happy path, multiple item", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - BatchL2Data: "0xabc1234", - Traces: &testvector.Traces{ - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "1100", - CntKeccakHashes: 1200, - CntMemAligns: 1300, - }, - }, - }, - { - BatchL2Data: "0xabc", - Traces: &testvector.Traces{ - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - }, - }, - }, - batchL2Data: "0xabc", - expectedResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - { - description: "unhappy path, id not found", - e2e: &testvector.E2E{ - Items: []*testvector.E2EItem{ - { - BatchL2Data: "0xabc", - Traces: &testvector.Traces{ - ProcessBatchResponse: &testvector.ProcessBatchResponse{ - CumulativeGasUsed: "100", - CntKeccakHashes: 200, - CntMemAligns: 300, - }, - }, - }, - }, - }, - batchL2Data: "0x123", - expectedError: true, - expectedErrorMsg: `ProcessBatchResponse for batchL2Data "0x123" not found`, - }, - } - - subject := &testvector.Container{} - - for _, tc := range tcs { - tc := tc - t.Run(tc.description, func(t *testing.T) { - subject.E2E = tc.e2e - - actualResponse, err := subject.FindProcessBatchResponse(tc.batchL2Data) - require.NoError(t, testutils.CheckError(err, tc.expectedError, tc.expectedErrorMsg)) - - if err == nil { - require.Equal(t, tc.expectedResponse, actualResponse) - } - }) - } -}