Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API returns panic when fail to verify adapter or aggregator #1254

Closed
martinkersner opened this issue Mar 14, 2024 · 1 comment · Fixed by #1259
Closed

API returns panic when fail to verify adapter or aggregator #1254

martinkersner opened this issue Mar 14, 2024 · 1 comment · Fixed by #1259

Comments

@martinkersner
Copy link
Member

goroutine 29 [running]:
runtime/debug.Stack()
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/runtime/debug/stack.go:24 +0x64
bisonai.com/orakl/api/utils.CustomStackTraceHandler(0x14000442cc0?, {0x104da9fe0?, 0x1052f2fa0})
        /Users/kersner/git/orakl/api/utils/utils.go:301 +0x1d8
bisonai.com/orakl/api/utils.Setup.New.func2.1()
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/middleware/recover/recover.go:31 +0x70
panic({0x0?, 0x0?})
        /opt/homebrew/Cellar/go/1.21.5/libexec/src/runtime/panic.go:914 +0x218
bisonai.com/orakl/api/aggregator.computeAggregatorHash(0x140000af748, 0x1)
        /Users/kersner/git/orakl/api/aggregator/controller.go:322 +0x190
bisonai.com/orakl/api/aggregator.hash(0x104d9c820?)
        /Users/kersner/git/orakl/api/aggregator/controller.go:208 +0x338
github.com/gofiber/fiber/v2.(*App).next(0x14000483400, 0x14000478c00)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/router.go:145 +0x188
github.com/gofiber/fiber/v2.(*Ctx).Next(0x104e5bb00?)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/ctx.go:1030 +0x5c
bisonai.com/orakl/api/utils.Setup.func1(0x100?)
        /Users/kersner/git/orakl/api/utils/utils.go:180 +0x104
github.com/gofiber/fiber/v2.(*Ctx).Next(0x1400001c330?)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/ctx.go:1027 +0x48
github.com/gofiber/fiber/v2/middleware/cors.New.func1(0x14000478c00)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/middleware/cors/cors.go:166 +0x318
github.com/gofiber/fiber/v2.(*Ctx).Next(0x140000afaf8?)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/ctx.go:1027 +0x48
bisonai.com/orakl/api/utils.Setup.New.func2(0x104d9c820?)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/middleware/recover/recover.go:43 +0xa4
github.com/gofiber/fiber/v2.(*App).next(0x14000483400, 0x14000478c00)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/router.go:145 +0x188
github.com/gofiber/fiber/v2.(*App).handler(0x14000483400, 0x1049f6e88?)
        /Users/kersner/.go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.0/router.go:172 +0x74
github.com/valyala/fasthttp.(*Server).serveConn(0x14000480fc0, {0x104e73b28?, 0x140005060b0})
        /Users/kersner/.go/pkg/mod/github.com/valyala/fasthttp@v1.52.0/server.go:2374 +0xdd0
github.com/valyala/fasthttp.(*workerPool).workerFunc(0x140004900a0, 0x1400028c040)
        /Users/kersner/.go/pkg/mod/github.com/valyala/fasthttp@v1.52.0/workerpool.go:224 +0x70
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
        /Users/kersner/.go/pkg/mod/github.com/valyala/fasthttp@v1.52.0/workerpool.go:196 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 1
        /Users/kersner/.go/pkg/mod/github.com/valyala/fasthttp@v1.52.0/workerpool.go:195 +0x208

2024/03/13 20:07:12 | 500 | 127.0.0.1 | POST | /api/v1/aggregator/hash | panic called with nil argument
@nick-bisonai
Copy link
Collaborator

  • should update ./api/aggregator/controller.go starting from line 311
  • don't panic but return appropriate fiber return types for failure
func computeAggregatorHash(data *AggregatorHashComputeInputModel, verify bool) error {
	input := data
	processData := input.AggregatorHashComputeProcessModel
	out, err := json.Marshal(processData)
	if err != nil {
		panic(err)
	}

	hash := crypto.Keccak256Hash([]byte(out))
	hashString := fmt.Sprintf("0x%x", hash)
	if verify && data.AggregatorHash != hashString {
		panic(err)
	}

	data.AggregatorHash = hashString
	return nil
}

@nick-bisonai nick-bisonai linked a pull request Mar 15, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants