Skip to content

Commit 29d1c35

Browse files
authored
Merge pull request #26 from taikoxyz/fix/ego_panic
2 parents df077e6 + dd56661 commit 29d1c35

22 files changed

Lines changed: 288 additions & 18 deletions

cmd/gaiko/server.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/signal"
11+
"runtime/debug"
1112
"sync"
1213
"syscall"
1314

@@ -48,6 +49,18 @@ const (
4849
HeklaBlock ProveMode = "hekla" // deprecated
4950
)
5051

52+
func recoverMiddleware(next http.Handler) http.Handler {
53+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
54+
defer func() {
55+
if err := recover(); err != nil {
56+
fmt.Printf("panic: %v\n%s", err, debug.Stack())
57+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
58+
}
59+
}()
60+
next.ServeHTTP(w, r)
61+
})
62+
}
63+
5164
func proveHandler(ctx context.Context, args *flags.Arguments, sgxProver *prover.SGXProver, w http.ResponseWriter, r *http.Request, proveMode ProveMode) {
5265
contentType := r.Header.Get("Content-Type")
5366
if contentType != "application/json" {
@@ -112,7 +125,9 @@ func runServer(c *cli.Context) error {
112125
port = "8080"
113126
}
114127
args := flags.NewArguments(c)
115-
http.HandleFunc("POST /prove/{action}", func(w http.ResponseWriter, r *http.Request) {
128+
129+
mux := http.NewServeMux()
130+
mux.HandleFunc("POST /prove/{action}", func(w http.ResponseWriter, r *http.Request) {
116131
args := args.Copy()
117132
defer r.Body.Close()
118133
// override the proof writer to get the proof & return as response
@@ -136,7 +151,8 @@ func runServer(c *cli.Context) error {
136151
})
137152

138153
server := &http.Server{
139-
Addr: ":" + port,
154+
Addr: ":" + port,
155+
Handler: recoverMiddleware(mux),
140156
}
141157

142158
go func() {

ego/_enclave.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Debug=1
2+
NumHeapPages=4194304
3+
NumStackPages=1024
4+
NumTCS=32
5+
ProductID=1
6+
SecurityVersion=1
7+
CapturePFGPExceptions=1

ego/enclave.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"exe": "gaiko-ego",
33
"key": "private.pem",
44
"debug": false,
5-
"heapSize": 8192,
5+
"heapSize": 16384,
66
"executableHeap": false,
77
"productID": 1,
88
"securityVersion": 1,
@@ -50,7 +50,11 @@
5050
{
5151
"name": "HOME",
5252
"value": "/root"
53+
},
54+
{
55+
"name": "GODEBUG",
56+
"value": "madvdontneed=1"
5357
}
5458
],
5559
"files": []
56-
}
60+
}

internal/prover/proof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func genAggregateProof(
7676
if err != nil {
7777
return err
7878
}
79-
log.Info("receive input: ", input)
79+
log.Info("receive input: ", "input", input)
8080
oldInstance := common.BytesToAddress(input.Proofs[0].Proof[4:24])
8181
curInstance := oldInstance
8282
for i, proof := range input.Proofs {

internal/types/access_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ package types
33
import (
44
"github.com/ethereum/go-ethereum/common"
55
"github.com/ethereum/go-ethereum/core/types"
6+
"github.com/ethereum/go-ethereum/log"
67
)
78

89
type AccessList []*AccessTuple
910

1011
func (a AccessList) GethType() types.AccessList {
12+
if a == nil {
13+
log.Warn("missing AccessList when converting to GethType")
14+
return nil
15+
}
1116
accessList := make(types.AccessList, len(a))
1217
for i, accessTuple := range a {
1318
accessList[i] = types.AccessTuple(*accessTuple)

internal/types/batch_proposed.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/ethereum/go-ethereum/common"
55
"github.com/ethereum/go-ethereum/common/hexutil"
66
"github.com/ethereum/go-ethereum/common/math"
7+
"github.com/ethereum/go-ethereum/log"
78
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/pacaya"
89
)
910

@@ -17,6 +18,10 @@ type BatchProposed struct {
1718
}
1819

1920
func (b *BatchProposed) GethType() *pacaya.TaikoInboxClientBatchProposed {
21+
if b == nil {
22+
log.Warn("missing BatchProposed when converting to GethType")
23+
return nil
24+
}
2025
blocks := make([]pacaya.ITaikoInboxBlockParams, len(b.Info.Blocks))
2126
for i, block := range b.Info.Blocks {
2227
blocks[i] = pacaya.ITaikoInboxBlockParams(*block)

internal/types/block.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"github.com/ethereum/go-ethereum/core/types"
5+
"github.com/ethereum/go-ethereum/log"
56
)
67

78
type Block struct {
@@ -12,6 +13,10 @@ type Block struct {
1213
}
1314

1415
func (b *Block) GethType() *types.Block {
16+
if b == nil {
17+
log.Warn("missing Block when converting to GethType")
18+
return nil
19+
}
1520
return types.NewBlockWithHeader(b.Header.GethType()).WithBody(types.Body{
1621
Transactions: b.Body.GethType(),
1722
Uncles: b.Ommers.GethType(),

internal/types/block_proposed.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ethereum/go-ethereum/common"
77
"github.com/ethereum/go-ethereum/common/math"
8+
"github.com/ethereum/go-ethereum/log"
89
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/ontake"
910
)
1011

@@ -20,6 +21,10 @@ type BlockProposed struct {
2021
}
2122

2223
func (b *BlockProposed) GethType() *ontake.TaikoL1ClientBlockProposed {
24+
if b == nil {
25+
log.Warn("missing BlockProposed when converting to GethType")
26+
return nil
27+
}
2328
deposits := make([]ontake.TaikoDataEthDeposit, len(b.DepositsProcessed))
2429
for i, deposit := range b.DepositsProcessed {
2530
deposits[i] = ontake.TaikoDataEthDeposit{

internal/types/block_proposed_v2.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ import (
55

66
"github.com/ethereum/go-ethereum/common"
77
"github.com/ethereum/go-ethereum/common/math"
8+
"github.com/ethereum/go-ethereum/log"
89
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/ontake"
910
)
1011

1112
//go:generate go run github.com/fjl/gencodec -type BlockProposedV2 -field-override blockProposedV2Marshaling -out gen_block_proposed_v2.go
1213

1314
// BlockProposedV2 represents a BlockProposed event raised by the TaikoL1Client contract.
1415
type BlockProposedV2 struct {
15-
BlockId *big.Int `json:"blockId" gencodec:"required"`
16+
BlockID *big.Int `json:"blockId" gencodec:"required"`
1617
Meta *BlockMetadataV2 `json:"meta" gencodec:"required"`
1718
}
1819

1920
func (b *BlockProposedV2) GethType() *ontake.TaikoL1ClientBlockProposedV2 {
21+
if b == nil {
22+
log.Warn("missing BlockProposedV2 when converting to GethType")
23+
return nil
24+
}
2025
return &ontake.TaikoL1ClientBlockProposedV2{
21-
BlockId: b.BlockId,
26+
BlockId: b.BlockID,
2227
Meta: ontake.TaikoDataBlockMetadataV2{
2328
AnchorBlockHash: b.Meta.AnchorBlockHash,
2429
Difficulty: b.Meta.Difficulty,
@@ -51,7 +56,7 @@ func (b *BlockProposedV2) GethType() *ontake.TaikoL1ClientBlockProposedV2 {
5156
}
5257

5358
type blockProposedV2Marshaling struct {
54-
BlockId *math.HexOrDecimal256 `json:"blockId" gencodec:"required"`
59+
BlockID *math.HexOrDecimal256 `json:"blockId" gencodec:"required"`
5560
}
5661

5762
//go:generate go run github.com/fjl/gencodec -type BlockMetadataV2 -field-override blockMetadataV2Marshaling -out gen_block_metadata_v2.go

internal/types/gen_block_proposed_v2.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)