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

Commit

Permalink
feat(all): update bindings && integrate new circuits for L3 (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jun 30, 2023
1 parent 2ffa052 commit 59469fa
Show file tree
Hide file tree
Showing 15 changed files with 1,060 additions and 457 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-3

- 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 @@
6a8029519c6170a9240972f82d11271bafd0e2d3
9d7bc39c282c6ceb0e62146aa6271d5ceaee7633
1,239 changes: 947 additions & 292 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {

log.Info("Comparing proposer TKO balance to block fee", "proposer", p.l1ProposerAddress.Hex())

if err := p.checkTaikoTokenBalance(); err != nil {
return fmt.Errorf("failed to check Taiko token balance: %w", err)
}

// Wait until L2 execution engine is synced at first.
if err := p.rpc.WaitTillL2ExecutionEngineSynced(ctx); err != nil {
return fmt.Errorf("failed to wait until L2 execution engine synced: %w", err)
Expand Down Expand Up @@ -395,7 +391,9 @@ func getTxOpts(
return opts, nil
}

func (p *Proposer) checkTaikoTokenBalance() error {
// CheckTaikoTokenBalance checks if the current proposer has enough balance to pay
// the current block fee.
func (p *Proposer) CheckTaikoTokenBalance() error {
fee, err := p.rpc.TaikoL1.GetBlockFee(nil)
if err != nil {
return fmt.Errorf("failed to get block fee: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions prover/proof_producer/dummy_producer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package producer

import (
"bytes"
"context"
"math/big"
"math/rand"
Expand Down Expand Up @@ -39,8 +40,8 @@ func (d *DummyProofProducer) RequestProof(
BlockID: blockID,
Meta: meta,
Header: header,
ZkProof: []byte{0xff},
Degree: CircuitsDegree10Txs,
ZkProof: bytes.Repeat([]byte{0xff}, 100),
Degree: CircuitsIdx,
Opts: opts,
}
})
Expand Down
16 changes: 2 additions & 14 deletions prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package producer

import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -11,11 +10,7 @@ import (
)

const (
CircuitsDegree10Txs = 19
CircuitsDegree80Txs = 21

CircuitsIdx10Txs = 0
CircuitsIdx80Txs = 1
CircuitsIdx = 0 // Currently we only have one verification contract in protocol.
)

// ProofRequestOptions contains all options that need to be passed to zkEVM rpcd service.
Expand Down Expand Up @@ -57,12 +52,5 @@ type ProofProducer interface {
}

func DegreeToCircuitsIdx(degree uint64) (uint16, error) {
switch degree {
case CircuitsDegree10Txs:
return CircuitsIdx10Txs, nil
case CircuitsDegree80Txs:
return CircuitsIdx80Txs, nil
default:
return 0, fmt.Errorf("invalid degree: %d", degree)
}
return CircuitsIdx, nil
}
2 changes: 1 addition & 1 deletion prover/proof_producer/zkevm_cmd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *ZkevmCmdProducer) RequestProof(
Header: header,
Meta: meta,
ZkProof: proof,
Degree: CircuitsDegree10Txs,
Degree: CircuitsIdx,
Opts: opts,
}

Expand Down
115 changes: 69 additions & 46 deletions prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,34 @@ type RequestProofBody struct {

// RequestProofBody represents the JSON body of RequestProofBody's `param` field.
type RequestProofBodyParam struct {
Circuit string `json:"circuit"`
Block *big.Int `json:"block"`
L2RPC string `json:"l2_rpc"`
Retry bool `json:"retry"`
Param string `json:"param"`
VerifyProof bool `json:"verify_proof"`
Mock bool `json:"mock"`
Aggregate bool `json:"aggregate"`
Prover string `json:"prover"`
L1SignalService string `json:"l1_signal_service"`
L2SignalService string `json:"l2_signal_service"`
TaikoL2 string `json:"l2_contract"`
MetaHash string `json:"meta_hash"`
BlockHash string `json:"block_hash"`
ParentHash string `json:"parent_hash"`
SignalRoot string `json:"signal_root"`
Graffiti string `json:"graffiti"`
GasUsed uint64 `json:"gas_used"`
ParentGasUsed uint64 `json:"parent_gas_used"`
BlockMaxGasLimit uint64 `json:"block_max_gas_limit"`
MaxTransactionsPerBlock uint64 `json:"max_transactions_per_block"`
MaxBytesPerTxList uint64 `json:"max_bytes_per_tx_list"`
Circuit string `json:"circuit"`
Block *big.Int `json:"block"`
L2RPC string `json:"rpc"`
Retry bool `json:"retry"`
Param string `json:"param"`
VerifyProof bool `json:"verify_proof"`
Mock bool `json:"mock"`
MockFeedback bool `json:"mock_feedback"`
Aggregate bool `json:"aggregate"`
ProtocolInstance *ProtocolInstance `json:"protocol_instance"`
}

// RequestProofBody represents the JSON body of RequestProofBody.Param's `protocol_instance` field.
type ProtocolInstance struct {
L1SignalService string `json:"l1_signal_service"`
L2SignalService string `json:"l2_signal_service"`
TaikoL2 string `json:"l2_contract"`
MetaHash string `json:"meta_hash"`
BlockHash string `json:"block_hash"`
ParentHash string `json:"parent_hash"`
SignalRoot string `json:"signal_root"`
Graffiti string `json:"graffiti"`
Prover string `json:"prover"`
GasUsed uint64 `json:"gas_used"`
ParentGasUsed uint64 `json:"parent_gas_used"`
BlockMaxGasLimit uint64 `json:"block_max_gas_limit"`
MaxTransactionsPerBlock uint64 `json:"max_transactions_per_block"`
MaxBytesPerTxList uint64 `json:"max_bytes_per_tx_list"`
}

// RequestProofBodyResponse represents the JSON body of the response of the proof requests.
Expand All @@ -87,6 +93,11 @@ type RpcdOutput struct {
Proof string `json:"proof"`
Degree uint64 `json:"k"`
} `json:"circuit"`
Aggregation struct {
Instances []string `json:"instance"`
Proof string `json:"proof"`
Degree uint64 `json:"k"`
} `json:"aggregation"`
}

// NewZkevmRpcdProducer creates a new `ZkevmRpcdProducer` instance.
Expand Down Expand Up @@ -172,8 +183,17 @@ func (p *ZkevmRpcdProducer) callProverDaemon(ctx context.Context, opts *ProofReq
log.Info("Proof generating", "height", opts.Height, "time", time.Since(start))
return errProofGenerating
}
proof = common.Hex2Bytes(output.Circuit.Proof[2:])
degree = output.Circuit.Degree

log.Debug("Proof generation output", "output", output)

var proofOutput string
for _, instance := range output.Aggregation.Instances {
proofOutput += instance[2:]
}
proofOutput += output.Aggregation.Proof[2:]

proof = common.Hex2Bytes(proofOutput)
degree = output.Aggregation.Degree
log.Info("Proof generated", "height", opts.Height, "degree", degree, "time", time.Since(start))
return nil
}, backoff.NewConstantBackOff(proofPollingInterval)); err != nil {
Expand All @@ -189,28 +209,31 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
ID: common.Big1,
Method: "proof",
Params: []*RequestProofBodyParam{{
Circuit: "pi",
Block: opts.Height,
L2RPC: p.L2Endpoint,
Retry: true,
Param: p.Param,
VerifyProof: true,
Mock: false,
Aggregate: false,
Prover: opts.ProverAddress.Hex()[2:],
L1SignalService: opts.L1SignalService.Hex()[2:],
L2SignalService: opts.L2SignalService.Hex()[2:],
TaikoL2: opts.TaikoL2.Hex()[2:],
MetaHash: opts.MetaHash.Hex()[2:],
BlockHash: opts.BlockHash.Hex()[2:],
ParentHash: opts.ParentHash.Hex()[2:],
SignalRoot: opts.SignalRoot.Hex()[2:],
Graffiti: opts.Graffiti,
GasUsed: opts.GasUsed,
ParentGasUsed: opts.ParentGasUsed,
BlockMaxGasLimit: p.ProtocolConfig.BlockMaxGasLimit,
MaxTransactionsPerBlock: p.ProtocolConfig.MaxTransactionsPerBlock,
MaxBytesPerTxList: p.ProtocolConfig.MaxBytesPerTxList,
Circuit: "super",
Block: opts.Height,
L2RPC: p.L2Endpoint,
Retry: true,
Param: p.Param,
VerifyProof: true,
Mock: false,
MockFeedback: false,
Aggregate: true,
ProtocolInstance: &ProtocolInstance{
Prover: opts.ProverAddress.Hex()[2:],
L1SignalService: opts.L1SignalService.Hex()[2:],
L2SignalService: opts.L2SignalService.Hex()[2:],
TaikoL2: opts.TaikoL2.Hex()[2:],
MetaHash: opts.MetaHash.Hex()[2:],
BlockHash: opts.BlockHash.Hex()[2:],
ParentHash: opts.ParentHash.Hex()[2:],
SignalRoot: opts.SignalRoot.Hex()[2:],
Graffiti: opts.Graffiti,
GasUsed: opts.GasUsed,
ParentGasUsed: opts.ParentGasUsed,
BlockMaxGasLimit: p.ProtocolConfig.BlockMaxGasLimit,
MaxTransactionsPerBlock: p.ProtocolConfig.MaxTransactionsPerBlock,
MaxBytesPerTxList: p.ProtocolConfig.MaxBytesPerTxList,
},
}},
}

Expand Down
2 changes: 1 addition & 1 deletion prover/proof_producer/zkevm_rpcd_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestNewZkevmRpcdProducer(t *testing.T) {
require.Nil(t, err)

dummyZkevmRpcdProducer.CustomProofHook = func() ([]byte, uint64, error) {
return []byte{0}, CircuitsDegree10Txs, nil
return []byte{0}, CircuitsIdx, nil
}

resCh := make(chan *ProofWithHeader, 1)
Expand Down
52 changes: 0 additions & 52 deletions prover/proof_submitter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

var (
errUnretryable = errors.New("unretryable")
errNeedWaiting = errors.New("need waiting before the proof submission")
)

// isSubmitProofTxErrorRetryable checks whether the error returned by a proof submission transaction
Expand Down Expand Up @@ -75,7 +74,6 @@ func sendTxWithBackoff(
) error {
var (
isUnretryableError bool
proposedTime = time.Unix(int64(proposedAt), 0)
)

if err := backoff.Retry(func() error {
Expand Down Expand Up @@ -106,56 +104,6 @@ func sendTxWithBackoff(
return nil
}

// Check the expected reward.
if expectedReward != 0 {
// Check if this proof is still needed at first.
needNewProof, err := rpc.NeedNewProof(ctx, cli, blockID, common.Address{}, nil)
if err != nil {
log.Warn(
"Failed to check if the generated proof is needed",
"blockID", blockID,
"error", err,
)
return err
}

if needNewProof {
stateVar, err := cli.TaikoL1.GetStateVariables(nil)
if err != nil {
log.Warn("Failed to get protocol state variables", "blockID", blockID, "error", err)
return err
}

targetDelay := stateVar.ProofTimeTarget * 4
if stateVar.BlockFee != 0 {
targetDelay = uint64(float64(expectedReward) / float64(stateVar.BlockFee) * float64(stateVar.ProofTimeTarget))
if targetDelay < stateVar.ProofTimeTarget/4 {
targetDelay = stateVar.ProofTimeTarget / 4
} else if targetDelay > stateVar.ProofTimeTarget*4 {
targetDelay = stateVar.ProofTimeTarget * 4
}
}

log.Info(
"Target delay",
"blockID", blockID,
"delay", targetDelay,
"expectedReward", expectedReward,
"blockFee", stateVar.BlockFee,
"proofTimeTarget", stateVar.ProofTimeTarget,
"proposedTime", proposedTime,
"timeToWait", time.Until(proposedTime.Add(time.Duration(targetDelay)*time.Second)),
)

if time.Now().Before(proposedTime.Add(time.Duration(targetDelay) * time.Second)) {
return errNeedWaiting
}
} else {
log.Info("Proof was submitted another prover, skip the current proof submission", "blockID", blockID)
return nil
}
}

tx, err := sendTxFunc()
if err != nil {
err = encoding.TryParsingCustomError(err)
Expand Down
3 changes: 2 additions & 1 deletion prover/proof_submitter/valid_proof_submitter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package submitter

import (
"bytes"
"context"
"os"
"sync"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (s *ProofSubmitterTestSuite) TestValidProofSubmitterSubmitProofMetadataNotF
BlockID: common.Big256,
Meta: &bindings.TaikoDataBlockMetadata{},
Header: &types.Header{},
ZkProof: []byte{0xff},
ZkProof: bytes.Repeat([]byte{0xff}, 100),
},
),
)
Expand Down
10 changes: 9 additions & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,15 @@ func (p *Prover) submitProofOp(ctx context.Context, proofWithHeader *proofProduc
}()

if err := backoff.Retry(
func() error { return p.validProofSubmitter.SubmitProof(p.ctx, proofWithHeader) },
func() error {
err := p.validProofSubmitter.SubmitProof(p.ctx, proofWithHeader)
if err != nil {
log.Error("Submit proof error", "error", err)
return err
}

return nil
},
backoff.WithMaxRetries(backoff.NewConstantBackOff(p.cfg.BackOffRetryInterval), p.cfg.BackOffMaxRetrys),
); err != nil {
log.Error("Submit proof error", "error", err)
Expand Down
6 changes: 3 additions & 3 deletions testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ func DepositEtherToL2(s *ClientTestSuite, depositerPrivKey *ecdsa.PrivateKey) {

opts, err := bind.NewKeyedTransactorWithChainID(depositerPrivKey, s.RpcClient.L1ChainID)
s.Nil(err)
opts.Value = config.MinEthDepositAmount
opts.Value = config.EthDepositMinAmount

for i := 0; i < int(config.MinEthDepositsPerBlock); i++ {
_, err = s.RpcClient.TaikoL1.DepositEtherToL2(opts)
for i := 0; i < int(config.EthDepositMinAmount.Uint64()); i++ {
_, err = s.RpcClient.TaikoL1.DepositEtherToL2(opts, crypto.PubkeyToAddress(depositerPrivKey.PublicKey))
s.Nil(err)
}
}
Expand Down
Loading

0 comments on commit 59469fa

Please sign in to comment.