Skip to content

Commit

Permalink
feat(prover): add special prover (system / oracle) (taikoxyz#214)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
cyberhorsey and davidtaikocha authored May 10, 2023
1 parent 1c21610 commit 5d199e1
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 136 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ec477de46f543339e71d4aa8453b62f44c32b32f
e8ba7168231f9a8bbef1378fa93448b11c4267ac
84 changes: 40 additions & 44 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/gen_taiko_l2.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ var (
Usage: "Set whether prover should use oracle prover or not",
Category: proverCategory,
}
SystemProver = &cli.BoolFlag{
Name: "systemProver",
Usage: "Set whether prover should use system prover or not",
Category: proverCategory,
}
OracleProverPrivateKey = &cli.StringFlag{
Name: "oracleProverPrivateKey",
Usage: "Private key of oracle prover",
Category: proverCategory,
}
SystemProverPrivateKey = &cli.StringFlag{
Name: "systemProverPrivateKey",
Usage: "Private key of system prover",
Category: proverCategory,
}
Graffiti = &cli.StringFlag{
Name: "graffiti",
Usage: "When string is passed, adds additional graffiti info to proof evidence",
Expand All @@ -84,6 +94,8 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
Dummy,
RandomDummyProofDelay,
OracleProver,
SystemProver,
OracleProverPrivateKey,
SystemProverPrivateKey,
Graffiti,
})
7 changes: 4 additions & 3 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COMPILE_PROTOCOL=${COMPILE_PROTOCOL:-false}
TESTNET_CONFIG=$TESTNET_CONFIG \
COMPILE_PROTOCOL=$COMPILE_PROTOCOL \
TAIKO_MONO_DIR=$TAIKO_MONO_DIR \
$DIR/nodes/init.sh
$DIR/nodes/init.sh

DEPLOYMENT_JSON=$(cat $TAIKO_MONO_DIR/packages/protocol/deployments/deploy_l1.json)
TAIKO_L1_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko' | sed 's/\"//g')
Expand All @@ -32,6 +32,7 @@ L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.signal_service
trap "docker compose -f $TESTNET_CONFIG down -v" EXIT INT KILL ERR

RUN_TESTS=${RUN_TESTS:-false}
PACKAGE=${PACKAGE:-...}

echo "TAIKO_L1_CONTRACT_ADDRESS: $TAIKO_L1_CONTRACT_ADDRESS"
echo "L1_SIGNAL_SERVICE_CONTRACT_ADDRESS: $L1_SIGNAL_SERVICE_CONTRACT_ADDRESS"
Expand All @@ -43,14 +44,14 @@ if [ "$RUN_TESTS" == "true" ]; then
L2_EXECUTION_ENGINE_WS_ENDPOINT=ws://localhost:28546 \
L2_EXECUTION_ENGINE_AUTH_ENDPOINT=http://localhost:28551 \
TAIKO_L1_ADDRESS=$TAIKO_L1_CONTRACT_ADDRESS \
TAIKO_L2_ADDRESS=0x0000777700000000000000000000000000000001 \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$L1_SIGNAL_SERVICE_CONTRACT_ADDRESS \
L1_CONTRACT_OWNER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L1_PROPOSER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L2_SUGGESTED_FEE_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
L1_PROVER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
JWT_SECRET=$DIR/nodes/jwt.hex \
go test -v -p=1 ./... -coverprofile=coverage.out -covermode=atomic -timeout=300s
go test -v -p=1 ./$PACKAGE -coverprofile=coverage.out -covermode=atomic -timeout=300s
else
echo "💻 Local dev net started"
docker compose -f $TESTNET_CONFIG logs -f l2_execution_engine
Expand Down
8 changes: 5 additions & 3 deletions integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ L2_GENESIS_HASH=$(
# Deploy Taiko protocol.
cd $TAIKO_MONO_DIR/packages/protocol &&
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
SYSTEM_PROVER=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
ORACLE_PROVER=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
SOLO_PROPOSER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
OWNER=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TREASURE=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TAIKO_L2_ADDRESS=0x0000777700000000000000000000000000000001 \
L2_SIGNAL_SERVICE=0x0000777700000000000000000000000000000007 \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L2_SIGNAL_SERVICE=0x1000777700000000000000000000000000000007 \
SHARED_SIGNAL_SERVICE=0x0000000000000000000000000000000000000000 \
TAIKO_TOKEN_PREMINT_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
TAIKO_TOKEN_PREMINT_AMOUNT=18446744073709551614 \
Expand All @@ -51,4 +52,5 @@ cd $TAIKO_MONO_DIR/packages/protocol &&
--fork-url http://localhost:18545 \
--broadcast \
--ffi \
-vvvv
-vvvv \
--block-gas-limit 100000000
27 changes: 26 additions & 1 deletion prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ type Config struct {
MaxConcurrentProvingJobs uint
Dummy bool
OracleProver bool
SystemProver bool
OracleProverPrivateKey *ecdsa.PrivateKey
SystemProverPrivateKey *ecdsa.PrivateKey
Graffiti string
RandomDummyProofDelayLowerBound *time.Duration
RandomDummyProofDelayUpperBound *time.Duration
Expand All @@ -43,8 +45,15 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
return nil, fmt.Errorf("invalid L1 prover private key: %w", err)
}

oracleProverSet := c.IsSet(flags.OracleProver.Name)
systemProverSet := c.IsSet(flags.SystemProver.Name)

if oracleProverSet && systemProverSet {
return nil, fmt.Errorf("cannot set both oracleProver and systemProver")
}

var oracleProverPrivKey *ecdsa.PrivateKey
if c.IsSet(flags.OracleProver.Name) {
if oracleProverSet {
if !c.IsSet(flags.OracleProverPrivateKey.Name) {
return nil, fmt.Errorf("oracleProver flag set without oracleProverPrivateKey set")
}
Expand All @@ -57,6 +66,20 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}
}

var systemProverPrivKey *ecdsa.PrivateKey
if systemProverSet {
if !c.IsSet(flags.SystemProverPrivateKey.Name) {
return nil, fmt.Errorf("systemProver flag set without systemProverPrivateKey set")
}

systemProverPrivKeyStr := c.String(flags.SystemProverPrivateKey.Name)

systemProverPrivKey, err = crypto.ToECDSA(common.Hex2Bytes(systemProverPrivKeyStr))
if err != nil {
return nil, fmt.Errorf("invalid system private key: %w", err)
}
}

var (
randomDummyProofDelayLowerBound *time.Duration
randomDummyProofDelayUpperBound *time.Duration
Expand Down Expand Up @@ -106,6 +129,8 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
Dummy: c.Bool(flags.Dummy.Name),
OracleProver: c.Bool(flags.OracleProver.Name),
OracleProverPrivateKey: oracleProverPrivKey,
SystemProver: c.Bool(flags.SystemProver.Name),
SystemProverPrivateKey: systemProverPrivKey,
Graffiti: c.String(flags.Graffiti.Name),
RandomDummyProofDelayLowerBound: randomDummyProofDelayLowerBound,
RandomDummyProofDelayUpperBound: randomDummyProofDelayUpperBound,
Expand Down
168 changes: 139 additions & 29 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ import (
"github.com/urfave/cli/v2"
)

func (s *ProverTestSuite) TestNewConfigFromCliContext() {
var testFlags = []cli.Flag{
&cli.StringFlag{Name: flags.L1WSEndpoint.Name},
&cli.StringFlag{Name: flags.L1HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.L2WSEndpoint.Name},
&cli.StringFlag{Name: flags.L2HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.TaikoL1Address.Name},
&cli.StringFlag{Name: flags.TaikoL2Address.Name},
&cli.StringFlag{Name: flags.L1ProverPrivKey.Name},
&cli.BoolFlag{Name: flags.Dummy.Name},
&cli.StringFlag{Name: flags.RandomDummyProofDelay.Name},
&cli.BoolFlag{Name: flags.OracleProver.Name},
&cli.StringFlag{Name: flags.OracleProverPrivateKey.Name},
&cli.BoolFlag{Name: flags.SystemProver.Name},
&cli.StringFlag{Name: flags.SystemProverPrivateKey.Name},
&cli.StringFlag{Name: flags.Graffiti.Name},
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProver() {
l1WsEndpoint := os.Getenv("L1_NODE_WS_ENDPOINT")
l1HttpEndpoint := os.Getenv("L1_NODE_HTTP_ENDPOINT")
l2WsEndpoint := os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT")
Expand All @@ -19,20 +36,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext() {
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")

app := cli.NewApp()
app.Flags = []cli.Flag{
&cli.StringFlag{Name: flags.L1WSEndpoint.Name},
&cli.StringFlag{Name: flags.L1HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.L2WSEndpoint.Name},
&cli.StringFlag{Name: flags.L2HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.TaikoL1Address.Name},
&cli.StringFlag{Name: flags.TaikoL2Address.Name},
&cli.StringFlag{Name: flags.L1ProverPrivKey.Name},
&cli.BoolFlag{Name: flags.Dummy.Name},
&cli.StringFlag{Name: flags.RandomDummyProofDelay.Name},
&cli.BoolFlag{Name: flags.OracleProver.Name},
&cli.StringFlag{Name: flags.OracleProverPrivateKey.Name},
&cli.StringFlag{Name: flags.Graffiti.Name},
}
app.Flags = testFlags
app.Action = func(ctx *cli.Context) error {
c, err := NewConfigFromCliContext(ctx)
s.Nil(err)
Expand Down Expand Up @@ -77,7 +81,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext() {
}))
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverError() {
func (s *ProverTestSuite) TestNewConfigFromCliContext_SystemProver() {
l1WsEndpoint := os.Getenv("L1_NODE_WS_ENDPOINT")
l1HttpEndpoint := os.Getenv("L1_NODE_HTTP_ENDPOINT")
l2WsEndpoint := os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT")
Expand All @@ -86,20 +90,61 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverError() {
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")

app := cli.NewApp()
app.Flags = []cli.Flag{
&cli.StringFlag{Name: flags.L1WSEndpoint.Name},
&cli.StringFlag{Name: flags.L1HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.L2WSEndpoint.Name},
&cli.StringFlag{Name: flags.L2HTTPEndpoint.Name},
&cli.StringFlag{Name: flags.TaikoL1Address.Name},
&cli.StringFlag{Name: flags.TaikoL2Address.Name},
&cli.StringFlag{Name: flags.L1ProverPrivKey.Name},
&cli.BoolFlag{Name: flags.Dummy.Name},
&cli.StringFlag{Name: flags.RandomDummyProofDelay.Name},
&cli.BoolFlag{Name: flags.OracleProver.Name},
&cli.StringFlag{Name: flags.OracleProverPrivateKey.Name},
&cli.StringFlag{Name: flags.Graffiti.Name},
app.Flags = testFlags
app.Action = func(ctx *cli.Context) error {
c, err := NewConfigFromCliContext(ctx)
s.Nil(err)
s.Equal(l1WsEndpoint, c.L1WsEndpoint)
s.Equal(l1HttpEndpoint, c.L1HttpEndpoint)
s.Equal(l2WsEndpoint, c.L2WsEndpoint)
s.Equal(l2HttpEndpoint, c.L2HttpEndpoint)
s.Equal(taikoL1, c.TaikoL1Address.String())
s.Equal(taikoL2, c.TaikoL2Address.String())
s.Equal(
crypto.PubkeyToAddress(s.p.cfg.L1ProverPrivKey.PublicKey),
crypto.PubkeyToAddress(c.L1ProverPrivKey.PublicKey),
)
s.Equal(30*time.Minute, *c.RandomDummyProofDelayLowerBound)
s.Equal(time.Hour, *c.RandomDummyProofDelayUpperBound)
s.True(c.Dummy)
s.True(c.SystemProver)
s.Equal(
crypto.PubkeyToAddress(s.p.cfg.SystemProverPrivateKey.PublicKey),
crypto.PubkeyToAddress(c.SystemProverPrivateKey.PublicKey),
)
s.Equal("", c.Graffiti)
s.Nil(new(Prover).InitFromCli(context.Background(), ctx))

return err
}

s.Nil(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"-" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"-" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"-" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Dummy.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1h",
"-" + flags.SystemProver.Name,
"-" + flags.SystemProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Graffiti.Name, "",
}))
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverError() {
l1WsEndpoint := os.Getenv("L1_NODE_WS_ENDPOINT")
l1HttpEndpoint := os.Getenv("L1_NODE_HTTP_ENDPOINT")
l2WsEndpoint := os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT")
l2HttpEndpoint := os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT")
taikoL1 := os.Getenv("TAIKO_L1_ADDRESS")
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")

app := cli.NewApp()
app.Flags = testFlags
app.Action = func(ctx *cli.Context) error {
_, err := NewConfigFromCliContext(ctx)
s.NotNil(err)
Expand All @@ -121,3 +166,68 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverError() {
"-" + flags.Graffiti.Name, "",
}), "oracleProver flag set without oracleProverPrivateKey set")
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_SystemProverError() {
l1WsEndpoint := os.Getenv("L1_NODE_WS_ENDPOINT")
l1HttpEndpoint := os.Getenv("L1_NODE_HTTP_ENDPOINT")
l2WsEndpoint := os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT")
l2HttpEndpoint := os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT")
taikoL1 := os.Getenv("TAIKO_L1_ADDRESS")
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")

app := cli.NewApp()
app.Flags = testFlags
app.Action = func(ctx *cli.Context) error {
_, err := NewConfigFromCliContext(ctx)
s.NotNil(err)
return err
}

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"-" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"-" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"-" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Dummy.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1h",
"-" + flags.SystemProver.Name,
"-" + flags.Graffiti.Name, "",
}), "systemProver flag set without systemProverPrivateKey set")
}

func (s *ProverTestSuite) TestNewConfigFromCliContext_SystemProverAndOracleProverBothSetError() {
l1WsEndpoint := os.Getenv("L1_NODE_WS_ENDPOINT")
l1HttpEndpoint := os.Getenv("L1_NODE_HTTP_ENDPOINT")
l2WsEndpoint := os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT")
l2HttpEndpoint := os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT")
taikoL1 := os.Getenv("TAIKO_L1_ADDRESS")
taikoL2 := os.Getenv("TAIKO_L2_ADDRESS")

app := cli.NewApp()
app.Flags = testFlags
app.Action = func(ctx *cli.Context) error {
_, err := NewConfigFromCliContext(ctx)
s.NotNil(err)
return err
}

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"-" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"-" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"-" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Dummy.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1h",
"-" + flags.OracleProver.Name,
"-" + flags.SystemProver.Name,
"-" + flags.Graffiti.Name, "",
}), "cannot set both oracleProver and systemProver")
}
Loading

0 comments on commit 5d199e1

Please sign in to comment.