Skip to content

Commit 332fe52

Browse files
authored
Merge pull request #36 from ethereum-optimism/tip/pcw109550/expose-witness
rvgo: Witness cmd saves witness & stateHash to json
2 parents 9ae663d + 57d3f68 commit 332fe52

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

rvgo/cmd/witness.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"os"
65

76
cannon "github.com/ethereum-optimism/optimism/cannon/cmd"
87
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
@@ -11,6 +10,11 @@ import (
1110
"github.com/ethereum-optimism/asterisc/rvgo/fast"
1211
)
1312

13+
type WitnessOutput struct {
14+
Witness []byte `json:"witness"`
15+
StateHash [32]byte `json:"stateHash"`
16+
}
17+
1418
func Witness(ctx *cli.Context) error {
1519
input := ctx.Path(cannon.WitnessInputFlag.Name)
1620
output := ctx.Path(cannon.WitnessOutputFlag.Name)
@@ -19,23 +23,25 @@ func Witness(ctx *cli.Context) error {
1923
return fmt.Errorf("invalid input state (%v): %w", input, err)
2024
}
2125
witness := state.EncodeWitness()
22-
h, err := witness.StateHash()
26+
stateHash, err := witness.StateHash()
2327
if err != nil {
2428
return fmt.Errorf("failed to compute witness hash: %w", err)
2529
}
26-
if output != "" {
27-
if err := os.WriteFile(output, witness, 0755); err != nil {
28-
return fmt.Errorf("writing output to %v: %w", output, err)
29-
}
30+
witnessOutput := &WitnessOutput{
31+
Witness: witness,
32+
StateHash: stateHash,
33+
}
34+
if err := jsonutil.WriteJSON(output, witnessOutput, OutFilePerm); err != nil {
35+
return fmt.Errorf("failed to write witness output %w", err)
3036
}
31-
fmt.Println(h.Hex())
37+
fmt.Println(stateHash.Hex())
3238
return nil
3339
}
3440

3541
var WitnessCommand = &cli.Command{
3642
Name: "witness",
3743
Usage: "Convert an Asterisc JSON state into a binary witness",
38-
Description: "Convert an Asterisc JSON state into a binary witness. The hash of the witness is written to stdout",
44+
Description: "Convert an Asterisc JSON state into a binary witness. The statehash is written to stdout",
3945
Action: Witness,
4046
Flags: []cli.Flag{
4147
cannon.WitnessInputFlag,

0 commit comments

Comments
 (0)