Skip to content

Commit

Permalink
Merge branch 'main' into deployment.md
Browse files Browse the repository at this point in the history
  • Loading branch information
intls authored Nov 30, 2024
2 parents d8b69c4 + 02d13d1 commit 073388c
Show file tree
Hide file tree
Showing 19 changed files with 605 additions and 579 deletions.
6 changes: 3 additions & 3 deletions contracts/docs/operational.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Linea Operational Scripts
<br />

This document aims to explain how to run the Linea operational scripts. There are several ways the scripts can be executed dependant if you have an environment file (.env) or not.
This document aims to explain how to run the Linea operational scripts. There are several ways the scripts can be executed dependent if you have an environment file (.env) or not.

Running the script with an .env file set, you will need to make sure that the correct variables are set in the .env file, considering the network that you're deploying on. In this way, when the script is being run, it will take the variables it needs to execute the script from that .env file.

Expand All @@ -12,7 +12,7 @@ The command-line arguments will create or replace existing .env (only in memory)

## Network specific variables

Dependant on which network you are using, a specific network private key needs to be used, as well as the corresponding API Key or RPC URL. The following table highlights which private key variable will be used per network. Please use the variable that pertains to the network. e.g. for `linea_sepolia` use `LINEA_SEPOLIA_PRIVATE_KEY` (`LINEA_SEPOLIA_PRIVATE_KEY=<key> INFURA_API_KEY=<key>`)
dependent on which network you are using, a specific network private key needs to be used, as well as the corresponding API Key or RPC URL. The following table highlights which private key variable will be used per network. Please use the variable that pertains to the network. e.g. for `linea_sepolia` use `LINEA_SEPOLIA_PRIVATE_KEY` (`LINEA_SEPOLIA_PRIVATE_KEY=<key> INFURA_API_KEY=<key>`)

| Network | Private key parameter name | API Key / RPC URL |
| ------------- | ----------------- | ---- |
Expand Down Expand Up @@ -271,4 +271,4 @@ npx hardhat transferOwnershipAndSetRemoteTokenBridge \
(make sure to replace `<key>` with actual values)

<br />
<br />
<br />
4 changes: 2 additions & 2 deletions docs/architecture-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ l1RollingHashes(
The gas price for transaction execution in Linea is computed from L1 gas price.


![gas price API](assets/gasPrice.drawio.svgo.svg)
![gas price API](assets/gasPrice.drawio.svg)


Gas price is based on the history of the gas price on L1.
Expand Down Expand Up @@ -977,4 +977,4 @@ For a Linea besu node to support `finalized` tag on Ethereum RPC methods (e.g. `

The plugin periodically calls the L1 Linea rollup contract's `currentL2BlockNumber` method to retrieve the latest proven L2 block number from the current L1 `finalized` block, and set the L2 block number as the `finalized` (and `safe` block number) to the plugin-hosting besu client.

For more information on how to run besu node with plugin, please check out the Besu official [website](https://besu.hyperledger.org/private-networks/concepts/plugins)
For more information on how to run besu node with plugin, please check out the Besu official [website](https://besu.hyperledger.org/private-networks/concepts/plugins)
58 changes: 29 additions & 29 deletions prover/backend/aggregation/craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ func collectFields(cfg *config.Config, req *Request) (*CollectedFields, error) {
for i, execReqFPath := range req.ExecutionProofs {

var (
po = &execution.Response{}
l2MessageHashes []string
fpath = path.Join(cfg.Execution.DirTo(), execReqFPath)
f = files.MustRead(fpath)
initialBlockTimestamp uint64
po execution.Response
l2MessageHashes []string
fpath = path.Join(cfg.Execution.DirTo(), execReqFPath)
f = files.MustRead(fpath)
)

if err := json.NewDecoder(f).Decode(po); err != nil {
if err := json.NewDecoder(f).Decode(&po); err != nil {
return nil, fmt.Errorf("fields collection, decoding %s, %w", execReqFPath, err)
}

Expand All @@ -85,11 +84,9 @@ func collectFields(cfg *config.Config, req *Request) (*CollectedFields, error) {
// This is purposefully overwritten at each iteration over i. We want to
// keep the final value.
cf.FinalBlockNumber = uint(po.FirstBlockNumber + len(po.BlocksData) - 1)
rollingHashUpdateEvents := po.AllRollingHashEvent // check redundant data for discrepancy

for i, blockdata := range po.BlocksData {
if i == 0 {
initialBlockTimestamp = blockdata.TimeStamp
}
for _, blockdata := range po.BlocksData {

for i := range blockdata.L2ToL1MsgHashes {
l2MessageHashes = append(l2MessageHashes, blockdata.L2ToL1MsgHashes[i].Hex())
Expand All @@ -101,12 +98,29 @@ func collectFields(cfg *config.Config, req *Request) (*CollectedFields, error) {
// The goal is that we want to keep the final value
lastRollingHashEvent := blockdata.LastRollingHashUpdatedEvent
if lastRollingHashEvent != (bridge.RollingHashUpdated{}) {
if len(rollingHashUpdateEvents) == 0 {
return nil, fmt.Errorf("data discrepancy: only %d rolling hash update events available in the conflation object, more available in the block data", len(po.AllRollingHashEvent))
}

update := rollingHashUpdateEvents[0]
rollingHashUpdateEvents = rollingHashUpdateEvents[1:]

if lastRollingHashEvent.RollingHash != update.RollingHash {
return nil, fmt.Errorf("data discrepancy: rolling hash update from conflation: %x. from block: %x", update.RollingHash, lastRollingHashEvent.RollingHash)
}
if lastRollingHashEvent.MessageNumber != update.MessageNumber {
return nil, fmt.Errorf("data discrepancy: rolling hash message number update from conflation: %d. from block: %d", update.MessageNumber, lastRollingHashEvent.MessageNumber)
}

cf.L1RollingHash = lastRollingHashEvent.RollingHash.Hex()
cf.L1RollingHashMessageNumber = uint(lastRollingHashEvent.MessageNumber)
}

cf.FinalTimestamp = uint(blockdata.TimeStamp)
}
if len(rollingHashUpdateEvents) != 0 {
return nil, fmt.Errorf("data discrepancy: %d rolling hash updates in conflation object but only %d collected from blocks", len(po.AllRollingHashEvent), len(po.AllRollingHashEvent)-len(rollingHashUpdateEvents))
}

// Append the proof claim to the list of collected proofs
if !cf.IsProoflessJob { // TODO @Tabaie @alexandre.belling proofless jobs will no longer be accepted post PI interconnection
Expand All @@ -116,25 +130,11 @@ func collectFields(cfg *config.Config, req *Request) (*CollectedFields, error) {
return nil, fmt.Errorf("could not parse the proof claim for `%v` : %w", fpath, err)
}
cf.ProofClaims = append(cf.ProofClaims, *pClaim)
// TODO make sure this belongs in the if
finalBlock := &po.BlocksData[len(po.BlocksData)-1]
piq, err := public_input.ExecutionSerializable{
InitialBlockTimestamp: initialBlockTimestamp,
L2MsgHashes: l2MessageHashes,
FinalStateRootHash: finalBlock.RootHash.Hex(),
FinalBlockNumber: uint64(cf.FinalBlockNumber),
FinalBlockTimestamp: finalBlock.TimeStamp,
FinalRollingHash: cf.L1RollingHash,
FinalRollingHashNumber: uint64(cf.L1RollingHashMessageNumber),
L2MessageServiceAddr: po.L2BridgeAddress,
ChainID: uint64(po.ChainID),
}.Decode()
if err != nil {
return nil, err
}

if piq.L2MessageServiceAddr != types.EthAddress(cfg.Layer2.MsgSvcContract) {
return nil, fmt.Errorf("execution #%d: expected L2 msg service addr %x, encountered %x", i, cfg.Layer2.MsgSvcContract, piq.L2MessageServiceAddr)
pi := po.FuncInput()

if pi.L2MessageServiceAddr != types.EthAddress(cfg.Layer2.MsgSvcContract) {
return nil, fmt.Errorf("execution #%d: expected L2 msg service addr %x, encountered %x", i, cfg.Layer2.MsgSvcContract, pi.L2MessageServiceAddr)
}
if po.ChainID != cfg.Layer2.ChainID {
return nil, fmt.Errorf("execution #%d: expected chain ID %x, encountered %x", i, cfg.Layer2.ChainID, po.ChainID)
Expand All @@ -145,7 +145,7 @@ func collectFields(cfg *config.Config, req *Request) (*CollectedFields, error) {
return nil, fmt.Errorf("execution #%d: public input mismatch: given %x, computed %x", i, po.PublicInput, pi)
}

cf.ExecutionPI = append(cf.ExecutionPI, piq)
cf.ExecutionPI = append(cf.ExecutionPI, *pi)
}

allL2MessageHashes = append(allL2MessageHashes, l2MessageHashes...)
Expand Down
38 changes: 21 additions & 17 deletions prover/backend/aggregation/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ func makeProof(
return circuits.SerializeProofSolidityBn254(proofBn254), nil
}

func (cf CollectedFields) AggregationPublicInput(cfg *config.Config) public_input.Aggregation {
return public_input.Aggregation{
FinalShnarf: cf.FinalShnarf,
ParentAggregationFinalShnarf: cf.ParentAggregationFinalShnarf,
ParentStateRootHash: cf.ParentStateRootHash,
ParentAggregationLastBlockTimestamp: cf.ParentAggregationLastBlockTimestamp,
FinalTimestamp: cf.FinalTimestamp,
LastFinalizedBlockNumber: cf.LastFinalizedBlockNumber,
FinalBlockNumber: cf.FinalBlockNumber,
LastFinalizedL1RollingHash: cf.LastFinalizedL1RollingHash,
L1RollingHash: cf.L1RollingHash,
LastFinalizedL1RollingHashMessageNumber: cf.LastFinalizedL1RollingHashMessageNumber,
L1RollingHashMessageNumber: cf.L1RollingHashMessageNumber,
L2MsgRootHashes: cf.L2MsgRootHashes,
L2MsgMerkleTreeDepth: utils.ToInt(cf.L2MsgTreeDepth),
ChainID: uint64(cfg.Layer2.ChainID),
L2MessageServiceAddr: types.EthAddress(cfg.Layer2.MsgSvcContract),
}
}

func makePiProof(cfg *config.Config, cf *CollectedFields) (plonk.Proof, witness.Witness, error) {

var setup circuits.Setup
Expand All @@ -87,23 +107,7 @@ func makePiProof(cfg *config.Config, cf *CollectedFields) (plonk.Proof, witness.
assignment, err := c.Assign(pi_interconnection.Request{
Decompressions: cf.DecompressionPI,
Executions: cf.ExecutionPI,
Aggregation: public_input.Aggregation{
FinalShnarf: cf.FinalShnarf,
ParentAggregationFinalShnarf: cf.ParentAggregationFinalShnarf,
ParentStateRootHash: cf.ParentStateRootHash,
ParentAggregationLastBlockTimestamp: cf.ParentAggregationLastBlockTimestamp,
FinalTimestamp: cf.FinalTimestamp,
LastFinalizedBlockNumber: cf.LastFinalizedBlockNumber,
FinalBlockNumber: cf.FinalBlockNumber,
LastFinalizedL1RollingHash: cf.LastFinalizedL1RollingHash,
L1RollingHash: cf.L1RollingHash,
LastFinalizedL1RollingHashMessageNumber: cf.LastFinalizedL1RollingHashMessageNumber,
L1RollingHashMessageNumber: cf.L1RollingHashMessageNumber,
L2MsgRootHashes: cf.L2MsgRootHashes,
L2MsgMerkleTreeDepth: utils.ToInt(cf.L2MsgTreeDepth),
ChainID: uint64(cfg.Layer2.ChainID),
L2MessageServiceAddr: types.EthAddress(cfg.Layer2.MsgSvcContract),
},
Aggregation: cf.AggregationPublicInput(cfg),
})
if err != nil {
return nil, nil, fmt.Errorf("could not assign the public input circuit: %w", err)
Expand Down
15 changes: 7 additions & 8 deletions prover/backend/execution/craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package execution

import (
"bytes"
public_input "github.com/consensys/linea-monorepo/prover/public-input"
"path"

"github.com/consensys/linea-monorepo/prover/backend/ethereum"
"github.com/consensys/linea-monorepo/prover/backend/execution/bridge"
"github.com/consensys/linea-monorepo/prover/backend/execution/statemanager"
"github.com/consensys/linea-monorepo/prover/crypto/mimc"

"github.com/consensys/linea-monorepo/prover/circuits/execution"
"github.com/consensys/linea-monorepo/prover/config"
blob "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v1"
"github.com/consensys/linea-monorepo/prover/utils"
Expand Down Expand Up @@ -174,14 +174,13 @@ func (req *Request) collectSignatures() ([]ethereum.Signature, [][32]byte) {
// are functionally useful to contextualize what the proof is proving. This
// is used by the aggregation circuit to ensure that the execution proofs
// relate to consecutive Linea block execution.
func (rsp *Response) FuncInput() *execution.FunctionalPublicInput {
func (rsp *Response) FuncInput() *public_input.Execution {

var (
firstBlock = &rsp.BlocksData[0]
lastBlock = &rsp.BlocksData[len(rsp.BlocksData)-1]
fi = &execution.FunctionalPublicInput{
fi = &public_input.Execution{
L2MessageServiceAddr: types.EthAddress(rsp.L2BridgeAddress),
MaxNbL2MessageHashes: rsp.MaxNbL2MessageHashes,
ChainID: uint64(rsp.ChainID),
FinalBlockTimestamp: lastBlock.TimeStamp,
FinalBlockNumber: uint64(rsp.FirstBlockNumber + len(rsp.BlocksData) - 1),
Expand All @@ -200,10 +199,10 @@ func (rsp *Response) FuncInput() *execution.FunctionalPublicInput {
lastRHEvent = rsp.AllRollingHashEvent[len(rsp.AllRollingHashEvent)-1]
)

fi.InitialRollingHash = firstRHEvent.RollingHash
fi.FinalRollingHash = lastRHEvent.RollingHash
fi.InitialRollingHashNumber = uint64(firstRHEvent.MessageNumber)
fi.FinalRollingHashNumber = uint64(lastRHEvent.MessageNumber)
fi.InitialRollingHashUpdate = firstRHEvent.RollingHash
fi.FinalRollingHashUpdate = lastRHEvent.RollingHash
fi.InitialRollingHashMsgNumber = uint64(firstRHEvent.MessageNumber)
fi.FinalRollingHashMsgNumber = uint64(lastRHEvent.MessageNumber)
}

return fi
Expand Down
5 changes: 3 additions & 2 deletions prover/backend/execution/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"github.com/consensys/linea-monorepo/prover/circuits/dummy"
"github.com/consensys/linea-monorepo/prover/circuits/execution"
"github.com/consensys/linea-monorepo/prover/config"
public_input "github.com/consensys/linea-monorepo/prover/public-input"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/utils/profiling"
"github.com/consensys/linea-monorepo/prover/zkevm"
"github.com/sirupsen/logrus"
)

type Witness struct {
FuncInp *execution.FunctionalPublicInput
FuncInp *public_input.Execution
ZkEVM *zkevm.Witness
}

Expand Down Expand Up @@ -144,7 +145,7 @@ func mustProveAndPass(
}

// TODO: implements the collection of the functional inputs from the prover response
return execution.MakeProof(setup, fullZkEvm.WizardIOP, proof, *w.FuncInp), setup.VerifyingKeyDigest()
return execution.MakeProof(traces, setup, fullZkEvm.WizardIOP, proof, *w.FuncInp), setup.VerifyingKeyDigest()

case config.ProverModeBench:

Expand Down
31 changes: 18 additions & 13 deletions prover/circuits/execution/circuit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package execution

import (
"github.com/consensys/linea-monorepo/prover/config"
public_input "github.com/consensys/linea-monorepo/prover/public-input"
"math/big"

"github.com/consensys/gnark-crypto/ecc"
Expand Down Expand Up @@ -45,30 +47,32 @@ func Allocate(zkevm *zkevm.ZkEvm) CircuitExecution {
extractor: zkevm.PublicInput.Extractor,
FuncInputs: FunctionalPublicInputSnark{
FunctionalPublicInputQSnark: FunctionalPublicInputQSnark{
L2MessageHashes: NewL2MessageHashes(
[][32]frontend.Variable{},
zkevm.Limits().BlockL2L1Logs,
),
L2MessageHashes: L2MessageHashes{
Values: make([][32]frontend.Variable, zkevm.Limits().BlockL2L1Logs),
Length: nil,
},
},
},
}
}

// assign the wizard proof to the outer circuit
func assign(
limits *config.TracesLimits,
comp *wizard.CompiledIOP,
proof wizard.Proof,
funcInputs FunctionalPublicInput,
funcInputs public_input.Execution,
) CircuitExecution {
wizardVerifier := wizard.GetWizardVerifierCircuitAssignment(comp, proof)
fpiSnark, err := funcInputs.ToSnarkType()
if err != nil {
panic(err) // TODO error handling
}

return CircuitExecution{
WizardVerifier: *wizardVerifier,
FuncInputs: fpiSnark,
PublicInput: new(big.Int).SetBytes(funcInputs.Sum(nil)),
FuncInputs: FunctionalPublicInputSnark{
FunctionalPublicInputQSnark: FunctionalPublicInputQSnark{
L2MessageHashes: L2MessageHashes{Values: make([][32]frontend.Variable, limits.BlockL2L1Logs)}, // TODO use a maximum from config
},
},
PublicInput: new(big.Int).SetBytes(funcInputs.Sum(nil)),
}
}

Expand All @@ -89,13 +93,14 @@ func (c *CircuitExecution) Define(api frontend.API) error {
}

func MakeProof(
limits *config.TracesLimits,
setup circuits.Setup,
comp *wizard.CompiledIOP,
wproof wizard.Proof,
funcInputs FunctionalPublicInput,
funcInputs public_input.Execution,
) string {

assignment := assign(comp, wproof, funcInputs)
assignment := assign(limits, comp, wproof, funcInputs)
witness, err := frontend.NewWitness(&assignment, ecc.BLS12_377.ScalarField())
if err != nil {
panic(err)
Expand Down
Loading

0 comments on commit 073388c

Please sign in to comment.