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

Commit

Permalink
feat(prover): update ZkevmRpcdProducer to integrate new circuits (#217
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidtaikocha committed May 11, 2023
1 parent 79ba210 commit 81cf612
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 41 deletions.
7 changes: 0 additions & 7 deletions cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ var (
Required: true,
Category: driverCategory,
}
SignalServiceAddress = &cli.StringFlag{
Name: "l1.signalService",
Usage: "L1 singal service contract address",
Required: true,
Category: driverCategory,
}
)

// Optional flags used by driver.
Expand Down Expand Up @@ -53,7 +47,6 @@ var (
var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{
L2WSEndpoint,
L2AuthEndpoint,
SignalServiceAddress,
JWTSecret,
P2PSyncVerifiedBlocks,
P2PSyncTimeout,
Expand Down
2 changes: 0 additions & 2 deletions driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Config struct {
L2CheckPoint string
TaikoL1Address common.Address
TaikoL2Address common.Address
SignalServiceAddress common.Address
JwtSecret string
P2PSyncVerifiedBlocks bool
P2PSyncTimeout time.Duration
Expand Down Expand Up @@ -49,7 +48,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
L2CheckPoint: l2CheckPoint,
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)),
TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)),
SignalServiceAddress: common.HexToAddress(c.String(flags.SignalServiceAddress.Name)),
JwtSecret: string(jwtSecret),
P2PSyncVerifiedBlocks: p2pSyncVerifiedBlocks,
P2PSyncTimeout: time.Duration(int64(time.Second) * int64(c.Uint(flags.P2PSyncTimeout.Name))),
Expand Down
4 changes: 0 additions & 4 deletions driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
l2EngineEndpoint := os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT")
taikoL1 := os.Getenv("TAIKO_L1_ADDRESS")
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")
l1SignalService := os.Getenv("L1_SIGNAL_SERVICE_CONTRACT_ADDRESS")

app := cli.NewApp()
app.Flags = []cli.Flag{
Expand All @@ -24,7 +23,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
&cli.StringFlag{Name: flags.L2AuthEndpoint.Name},
&cli.StringFlag{Name: flags.TaikoL1Address.Name},
&cli.StringFlag{Name: flags.TaikoL2Address.Name},
&cli.StringFlag{Name: flags.SignalServiceAddress.Name},
&cli.StringFlag{Name: flags.JWTSecret.Name},
&cli.UintFlag{Name: flags.P2PSyncTimeout.Name},
}
Expand All @@ -36,7 +34,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
s.Equal(l2EngineEndpoint, c.L2EngineEndpoint)
s.Equal(taikoL1, c.TaikoL1Address.String())
s.Equal(taikoL2, c.TaikoL2Address.String())
s.Equal(l1SignalService, c.SignalServiceAddress.String())
s.Equal(120*time.Second, c.P2PSyncTimeout)
s.NotEmpty(c.JwtSecret)
s.Nil(new(Driver).InitFromCli(context.Background(), ctx))
Expand All @@ -51,7 +48,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
"-" + flags.L2AuthEndpoint.Name, l2EngineEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.SignalServiceAddress.Name, l1SignalService,
"-" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"-" + flags.P2PSyncTimeout.Name, "120",
}))
Expand Down
10 changes: 9 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@ func InitFromConfig(ctx context.Context, d *Driver, cfg *Config) (err error) {
log.Warn("P2P syncing verified blocks enabled, but no connected peer found in L2 execution engine")
}

var signalServiceNameBytes [32]byte
copy(signalServiceNameBytes[:], []byte("signal_service"))

signalServiceAddress, err := d.rpc.TaikoL1.Resolve0(nil, signalServiceNameBytes, false)
if err != nil {
return err
}

if d.l2ChainSyncer, err = chainSyncer.New(
d.ctx,
d.rpc,
d.state,
cfg.P2PSyncVerifiedBlocks,
cfg.P2PSyncTimeout,
cfg.SignalServiceAddress,
signalServiceAddress,
); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
return p.CustomProposeOpHook()
}

log.Info("Comparing proposer TKO balance to block fee")
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)
Expand Down
10 changes: 10 additions & 0 deletions prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ type ProofRequestOptions struct {
Height *big.Int // the block number
ProverAddress common.Address
ProposeBlockTxHash common.Hash
L1SignalService common.Address
L2SignalService common.Address
TaikoL2 common.Address
MetaHash common.Hash
BlockHash common.Hash
ParentHash common.Hash
SignalRoot common.Hash
Graffiti string
GasUsed uint64
ParentGasUsed uint64
}

type ProofWithHeader struct {
Expand Down
68 changes: 46 additions & 22 deletions prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,36 @@ 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"`
L1RPC string `json:"l1_rpc"`
L2RPC string `json:"l2_rpc"`
ProposeBlockTxHash string `json:"propose_tx_hash"`
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"`
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"`
}

// RequestProofBodyResponse represents the JSON body of the response of the proof requests.
type RequestProofBodyResponse struct {
JsonRPC string `json:"jsonrpc"`
ID *big.Int `json:"id"`
Result *RpcdOutput `json:"result"`
Error *struct {
Code *big.Int `json:"code"`
Message string `json:"message"`
} `json:"error,omitempty"`
}

// RpcdOutput represents the JSON body of RequestProofBodyResponse's `result` field.
Expand Down Expand Up @@ -169,17 +181,25 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
ID: common.Big1,
Method: "proof",
Params: []*RequestProofBodyParam{{
Circuit: "pi",
Block: opts.Height,
L1RPC: p.L1Endpoint,
L2RPC: p.L2Endpoint,
Retry: true,
Param: p.Param,
VerifyProof: true,
Mock: false,
Aggregate: false,
Prover: opts.ProverAddress.Hex()[2:],
ProposeBlockTxHash: opts.ProposeBlockTxHash.Hex()[2:],
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,
}},
}

Expand Down Expand Up @@ -208,6 +228,10 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
return nil, err
}

if output.Error != nil {
return nil, errors.New(output.Error.Message)
}

return output.Result, nil
}

Expand Down
56 changes: 52 additions & 4 deletions prover/proof_submitter/valid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type ValidProofSubmitter struct {
anchorTxValidator *anchorTxValidator.AnchorTxValidator
proverPrivKey *ecdsa.PrivateKey
proverAddress common.Address
taikoL2Address common.Address
l1SignalService common.Address
l2SignalService common.Address
mutex *sync.Mutex
isOracleProver bool
isSystemProver bool
Expand All @@ -54,6 +57,19 @@ func NewValidProofSubmitter(
return nil, err
}

var signalServiceNameBytes [32]byte
copy(signalServiceNameBytes[:], []byte("signal_service"))

l1SignalService, err := rpc.TaikoL1.Resolve0(nil, signalServiceNameBytes, false)
if err != nil {
return nil, err
}

l2SignalService, err := rpc.TaikoL2.Resolve0(nil, signalServiceNameBytes, false)
if err != nil {
return nil, err
}

var graffitiBytes [32]byte
copy(graffitiBytes[:], []byte(graffiti))

Expand All @@ -64,6 +80,9 @@ func NewValidProofSubmitter(
anchorTxValidator: anchorValidator,
proverPrivKey: proverPrivKey,
proverAddress: crypto.PubkeyToAddress(proverPrivKey.PublicKey),
l1SignalService: l1SignalService,
l2SignalService: l2SignalService,
taikoL2Address: taikoL2Address,
mutex: mutex,
isOracleProver: isOracleProver,
isSystemProver: isSystemProver,
Expand All @@ -79,19 +98,48 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
}

// Get the header of the block to prove from L2 execution engine.
header, err := s.rpc.L2.HeaderByHash(ctx, l1Origin.L2BlockHash)
block, err := s.rpc.L2.BlockByHash(ctx, l1Origin.L2BlockHash)
if err != nil {
return err
}

parent, err := s.rpc.L2.BlockByHash(ctx, block.ParentHash())
if err != nil {
return err
}

blockInfo, err := s.rpc.TaikoL1.GetBlock(nil, event.Id)
if err != nil {
return err
}

if block.Transactions().Len() == 0 {
return errors.New("no transaction in block")
}

signalRoot, err := s.anchorTxValidator.GetAnchoredSignalRoot(ctx, block.Transactions()[0])
if err != nil {
return err
}

// Request proof.
opts := &proofProducer.ProofRequestOptions{
Height: header.Number,
Height: block.Number(),
ProverAddress: s.proverAddress,
ProposeBlockTxHash: event.Raw.TxHash,
L1SignalService: s.l1SignalService,
L2SignalService: s.l2SignalService,
TaikoL2: s.taikoL2Address,
MetaHash: blockInfo.MetaHash,
BlockHash: block.Hash(),
ParentHash: block.ParentHash(),
SignalRoot: signalRoot,
Graffiti: common.Bytes2Hex(s.graffiti[:]),
GasUsed: block.GasUsed(),
ParentGasUsed: parent.GasUsed(),
}

if err := s.proofProducer.RequestProof(ctx, opts, event.Id, &event.Meta, header, s.resultCh); err != nil {
if err := s.proofProducer.RequestProof(ctx, opts, event.Id, &event.Meta, block.Header(), s.resultCh); err != nil {
return err
}

Expand All @@ -112,7 +160,7 @@ func (s *ValidProofSubmitter) SubmitProof(
"beneficiary", proofWithHeader.Meta.Beneficiary,
"hash", proofWithHeader.Header.Hash(),
"proof", common.Bytes2Hex(proofWithHeader.ZkProof),
"graffiti", string(s.graffiti[:]),
"graffiti", common.Bytes2Hex(s.graffiti[:]),
)
var (
blockID = proofWithHeader.BlockID
Expand Down

0 comments on commit 81cf612

Please sign in to comment.