Skip to content

Commit

Permalink
Merge pull request #61 from 0xPolygon/pullupstream/v0.5.0-RC23
Browse files Browse the repository at this point in the history
Pullupstream/v0.5.0 rc23
  • Loading branch information
arnaubennassar authored Feb 1, 2024
2 parents a03bdeb + 6208cca commit 916ec91
Show file tree
Hide file tree
Showing 199 changed files with 38,936 additions and 20,705 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jsonschema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
# /~https://github.com/actions/checkout#Checkout-pull-request-HEAD-commit-instead-of-merge-commit
# Checkout pull request HEAD commit instead of merge commit
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: Lint
run: |
make install-linter
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/push-docker-develop.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/push-docker-tagged.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting.
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744

- name: Install Go
uses: actions/setup-go@v3
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/test-from-prover.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test-full-non-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744

- name: Install Go
uses: actions/setup-go@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/updatedeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744

- name: Install Go
uses: actions/setup-go@v3
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ issues:
include:
- EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
- EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments
exclude-rules:
- path: cmd/policy.go
text: "unused"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Note that non of this is a hard rule, but suggestions / guidelines. Although eve
- Offer clarification, explain the decisions you made to reach a solution in question.
- Try to respond to every comment.
- If there is growing confusion or debate, ask yourself if the written word is still the best form of communication. Talk (virtually) face-to-face, then mutually consider posting a follow-up to summarize any offline discussion (useful for others who be following along, now or later).
- If concensus is still not reached, involve someone else in the discussion. As a last resource the lead of the project could take the decision
- If consensus is still not reached, involve someone else in the discussion. As a last resource the lead of the project could take the decision

## Links and credits

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ venv: $(VENV_PYTHON)
.PHONY: install-config-doc-gen
$(GENERATE_SCHEMA_DOC): $(VENV_PYTHON)
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install json-schema-for-humans
$(PYTHON) -m pip install json-schema-for-humans==0.47

.PHONY: config-doc-gen
config-doc-gen: config-doc-node config-doc-custom_network ## Generate config file's json-schema for node and custom_network and documentation
Expand Down
95 changes: 57 additions & 38 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,7 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.

isForcedBatch := false
batchRawData := &state.BatchRawV2{}

if batchToVerify.BatchNumber == 1 || batchToVerify.ForcedBatchNum != nil {
if batchToVerify.BatchNumber == 1 || batchToVerify.ForcedBatchNum != nil || batchToVerify.BatchNumber == a.cfg.UpgradeEtrogBatchNumber {
isForcedBatch = true
} else {
batchRawData, err = state.DecodeBatchV2(batchToVerify.BatchL2Data)
Expand All @@ -992,7 +991,12 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
}

l1InfoTreeData := map[uint32]*prover.L1Data{}
l1InfoRoot := common.Hash{}
vb, err := a.State.GetVirtualBatch(ctx, batchToVerify.BatchNumber, nil)
if err != nil {
log.Errorf("Failed getting virtualBatch %d, err: %v", batchToVerify.BatchNumber, err)
return nil, err
}
l1InfoRoot := vb.L1InfoRoot
forcedBlockhashL1 := common.Hash{}

if !isForcedBatch {
Expand All @@ -1004,51 +1008,49 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
for _, l2blockRaw := range batchRawData.Blocks {
_, contained := l1InfoTreeData[l2blockRaw.IndexL1InfoTree]
if !contained && l2blockRaw.IndexL1InfoTree != 0 {
if l2blockRaw.IndexL1InfoTree != 0 {
l1InfoTreeExitRootStorageEntry, err := a.State.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, nil)
if err != nil {
return nil, err
}

leaves, err := a.State.GetLeafsByL1InfoRoot(ctx, l1InfoTreeExitRootStorageEntry.L1InfoTreeRoot, nil)
if err != nil {
return nil, err
}

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
}

// Calculate smt proof
smtProof, _, err := tree.ComputeMerkleProof(l2blockRaw.IndexL1InfoTree, aLeaves)
if err != nil {
return nil, err
}

protoProof := make([][]byte, len(smtProof))
for i, proof := range smtProof {
protoProof[i] = proof[:]
}

l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = &prover.L1Data{
GlobalExitRoot: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.GlobalExitRoot.Bytes(),
BlockhashL1: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.PreviousBlockHash.Bytes(),
MinTimestamp: uint32(l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.Timestamp.Unix()),
SmtProof: protoProof,
}
l1InfoTreeExitRootStorageEntry, err := a.State.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, nil)
if err != nil {
return nil, err
}

leaves, err := a.State.GetLeafsByL1InfoRoot(ctx, l1InfoTreeExitRootStorageEntry.L1InfoTreeRoot, nil)
if err != nil {
return nil, err
}

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
}

// Calculate smt proof
smtProof, _, err := tree.ComputeMerkleProof(l2blockRaw.IndexL1InfoTree, aLeaves)
if err != nil {
return nil, err
}

protoProof := make([][]byte, len(smtProof))
for i, proof := range smtProof {
tmpProof := proof
protoProof[i] = tmpProof[:]
}

l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = &prover.L1Data{
GlobalExitRoot: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.GlobalExitRoot.Bytes(),
BlockhashL1: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.PreviousBlockHash.Bytes(),
MinTimestamp: uint32(l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.Timestamp.Unix()),
SmtProof: protoProof,
}
}
}
} else {
// Initial batch must be handled differently
if batchToVerify.BatchNumber == 1 {
if batchToVerify.BatchNumber == 1 || batchToVerify.BatchNumber == a.cfg.UpgradeEtrogBatchNumber {
forcedBlockhashL1, err = a.State.GetVirtualBatchParentHash(ctx, batchToVerify.BatchNumber, nil)
if err != nil {
return nil, err
}
} else {
l1InfoRoot = batchToVerify.GlobalExitRoot
forcedBlockhashL1, err = a.State.GetForcedBatchParentHash(ctx, *batchToVerify.ForcedBatchNum, nil)
if err != nil {
return nil, err
Expand All @@ -1075,9 +1077,26 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
ContractsBytecode: map[string]string{},
}

printInputProver(inputProver)

return inputProver, nil
}

func printInputProver(inputProver *prover.InputProver) {
log.Debugf("OldStateRoot: %v", common.BytesToHash(inputProver.PublicInputs.OldStateRoot))
log.Debugf("OldAccInputHash: %v", common.BytesToHash(inputProver.PublicInputs.OldAccInputHash))
log.Debugf("OldBatchNum: %v", inputProver.PublicInputs.OldBatchNum)
log.Debugf("ChainId: %v", inputProver.PublicInputs.ChainId)
log.Debugf("ForkId: %v", inputProver.PublicInputs.ForkId)
log.Debugf("BatchL2Data: %v", common.Bytes2Hex(inputProver.PublicInputs.BatchL2Data))
log.Debugf("L1InfoRoot: %v", common.BytesToHash(inputProver.PublicInputs.L1InfoRoot))
log.Debugf("TimestampLimit: %v", inputProver.PublicInputs.TimestampLimit)
log.Debugf("SequencerAddr: %v", inputProver.PublicInputs.SequencerAddr)
log.Debugf("AggregatorAddr: %v", inputProver.PublicInputs.AggregatorAddr)
log.Debugf("L1InfoTreeData: %+v", inputProver.PublicInputs.L1InfoTreeData)
log.Debugf("ForcedBlockhashL1: %v", common.Bytes2Hex(inputProver.PublicInputs.ForcedBlockhashL1))
}

// healthChecker will provide an implementation of the HealthCheck interface.
type healthChecker struct{}

Expand Down
Loading

0 comments on commit 916ec91

Please sign in to comment.