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

Commit

Permalink
merge main, plus remove some other fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Jun 30, 2023
2 parents b8011c0 + 59469fa commit ce83688
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 135 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
<<<<<<< HEAD
ref: alpha_4_test_fixes
=======
>>>>>>> main

- 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 @@
00c23d1ece9f23b600d4cfe77efab90285741cc2
c133bdd2bee6192bab2531f8463100c778c71820
7 changes: 0 additions & 7 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ var (
Category: proverCategory,
Value: "",
}
ExpectedReward = &cli.Uint64Flag{
Name: "expectedReward",
Usage: "The expected prover reward for each block",
Category: proverCategory,
Value: 100_000_000,
}
TaikoProverPoolL1Address = &cli.StringFlag{
Name: "taikoProverPoolL1",
Usage: "TaikoProverPoolL1 contract address",
Expand All @@ -98,6 +92,5 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
OracleProver,
OracleProverPrivateKey,
Graffiti,
ExpectedReward,
TaikoProverPoolL1Address,
})
10 changes: 3 additions & 7 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,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 @@ -400,9 +396,9 @@ func getTxOpts(
return opts, nil
}

// checkTaikoTokenBalance ensures you have at least the block fee in your balance, and approved, before
// attempting to propose block, as it will use transferFrom.
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, p.protocolConfigs.BlockMaxGasLimit)
if err != nil {
return fmt.Errorf("failed to get block fee: %w", err)
Expand Down
2 changes: 0 additions & 2 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Config struct {
Graffiti string
RandomDummyProofDelayLowerBound *time.Duration
RandomDummyProofDelayUpperBound *time.Duration
ExpectedReward uint64
BackOffMaxRetrys uint64
BackOffRetryInterval time.Duration
}
Expand Down Expand Up @@ -116,7 +115,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
Graffiti: c.String(flags.Graffiti.Name),
RandomDummyProofDelayLowerBound: randomDummyProofDelayLowerBound,
RandomDummyProofDelayUpperBound: randomDummyProofDelayUpperBound,
ExpectedReward: c.Uint64(flags.ExpectedReward.Name),
BackOffMaxRetrys: c.Uint64(flags.BackOffMaxRetrys.Name),
BackOffRetryInterval: time.Duration(c.Uint64(flags.BackOffRetryInterval.Name)) * time.Second,
}, nil
Expand Down
14 changes: 4 additions & 10 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,16 +40,9 @@ func (d *DummyProofProducer) RequestProof(
BlockID: blockID,
Meta: meta,
Header: header,
// proof must be 32 bytes min since protocol uses bytes utils and reads 32 bytes, so even
// make proofs must be 32 bytes
ZkProof: []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff,
},
Degree: CircuitsDegree10Txs,
Opts: opts,
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: uint64(p.ProtocolConfig.BlockMaxGasLimit),
MaxTransactionsPerBlock: p.ProtocolConfig.BlockMaxTransactions,
MaxBytesPerTxList: p.ProtocolConfig.BlockMaxTxListBytes,
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: uint64(p.ProtocolConfig.BlockMaxGasLimit),
MaxTransactionsPerBlock: p.ProtocolConfig.BlockMaxTransactions,
MaxBytesPerTxList: p.ProtocolConfig.BlockMaxTxListBytes,
},
}},
}

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
30 changes: 13 additions & 17 deletions prover/proof_submitter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func sendTxWithBackoff(
cli *rpc.Client,
blockID *big.Int,
proposedAt uint64,
expectedReward uint64,
meta *bindings.TaikoDataBlockMetadata,
sendTxFunc func() (*types.Transaction, error),
retryInterval time.Duration,
Expand Down Expand Up @@ -104,23 +103,20 @@ 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{})
if err != nil {
log.Warn(
"Failed to check if the generated proof is needed",
"blockID", blockID,
"error", err,
)
return err
}
// Check if this proof is still needed at first.
needNewProof, err := rpc.NeedNewProof(ctx, cli, blockID, common.Address{})
if err != nil {
log.Warn(
"Failed to check if the generated proof is needed",
"blockID", blockID,
"error", err,
)
return err
}

if !needNewProof {
log.Info("Proof was submitted another prover, skip the current proof submission", "blockID", blockID)
return nil
}
if !needNewProof {
log.Info("Proof was submitted another prover, skip the current proof submission", "blockID", blockID)
return nil
}

tx, err := sendTxFunc()
Expand Down
2 changes: 0 additions & 2 deletions prover/proof_submitter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (s *ProofSubmitterTestSuite) TestSendTxWithBackoff() {
s.RpcClient,
common.Big1,
0,
0,
meta,
func() (*types.Transaction, error) { return nil, errors.New("L1_TEST") },
12*time.Second,
Expand All @@ -48,7 +47,6 @@ func (s *ProofSubmitterTestSuite) TestSendTxWithBackoff() {
s.RpcClient,
common.Big1,
0,
0,
meta,
func() (*types.Transaction, error) {
height, err := s.RpcClient.L1.BlockNumber(context.Background())
Expand Down
Loading

0 comments on commit ce83688

Please sign in to comment.