{"record":{"id":"a862c63b594e1105","repo":"ethereum/go-ethereum","slug":"invalid-group-depth-size","errorCode":null,"errorMessage":"invalid group depth size","messagePattern":"invalid group depth size","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"trie/bintrie/trie.go","lineNumber":140,"sourceCode":"// operations will report the original (unhashed) account, storage, and code\n// writes to the recorder so the post-state can be exported as a GenesisAlloc.\n// Pass nil to detach.\nfunc (t *BinaryTrie) SetRecorder(r *Recorder) { t.recorder = r }\n\n// Recorder returns the currently attached alloc recorder, or nil.\nfunc (t *BinaryTrie) Recorder() *Recorder { return t.recorder }\n\n// ToDot converts the binary trie to a DOT language representation. Useful for debugging.\nfunc (t *BinaryTrie) ToDot() string {\n\tt.store.computeHash(t.store.root)\n\treturn t.store.toDot(t.store.root, \"\", \"\")\n}\n\n// NewBinaryTrie creates a new binary trie.\n// groupDepth specifies the number of levels per serialized group (1-8).\nfunc NewBinaryTrie(root common.Hash, db database.NodeDatabase, groupDepth int) (*BinaryTrie, error) {\n\tif groupDepth < 1 || groupDepth > MaxGroupDepth {\n\t\tpanic(\"invalid group depth size\")\n\t}\n\treader, err := trie.NewReader(root, common.Hash{}, db)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tt := &BinaryTrie{\n\t\tstore:      newNodeStore(),\n\t\treader:     reader,\n\t\ttracer:     trie.NewPrevalueTracer(),\n\t\tgroupDepth: groupDepth,\n\t}\n\t// Parse the root node if it's not empty\n\tif root != types.EmptyBinaryHash && root != types.EmptyRootHash {\n\t\tblob, err := t.nodeResolver(nil, root)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tref, err := t.store.deserializeNodeWithHash(blob, 0, root)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/trie/bintrie/trie.go#L122-L158","documentation":"trie/bintrie.NewBinaryTrie panics when groupDepth is outside [1, MaxGroupDepth] (MaxGroupDepth is 8). groupDepth controls how many trie levels are grouped in each serialized node group; values below 1 or above 8 break the encoding scheme, so they are rejected as invalid configuration.","triggerScenarios":"Calling bintrie.NewBinaryTrie(root, db, 0) or with depth 9+; computing depth from user input or config without bounds checking; passing an uninitialized int (0) for groupDepth.","commonSituations":"Config-driven tree tuning where a typo or missing default yields 0; porting code from a library version with a different valid range; using a constant defined elsewhere that drifted out of range.","solutions":["Pass a groupDepth in 1..8; if unsure, use the package's default/recommended value.","Clamp or validate external input before constructing the trie.","Reference bintrie.MaxGroupDepth in validation instead of hard-coding 8."],"exampleFix":"// before\ntr, err := bintrie.NewBinaryTrie(root, db, groupDepth) // groupDepth==0 -> panic\n\n// after\nif groupDepth < 1 || groupDepth > bintrie.MaxGroupDepth {\n    return nil, fmt.Errorf(\"groupDepth %d out of range [1, %d]\", groupDepth, bintrie.MaxGroupDepth)\n}\ntr, err := bintrie.NewBinaryTrie(root, db, groupDepth)","handlingStrategy":"validation","validationCode":"if groupDepth < 1 || groupDepth > bintrie.MaxGroupDepth {\n    return nil, fmt.Errorf(\"groupDepth %d out of range [1, %d]\", groupDepth, bintrie.MaxGroupDepth)\n}\ntr, err := bintrie.NewBinaryTrie(root, db, groupDepth)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate groupDepth against bintrie.MaxGroupDepth instead of hard-coding the bound.","Default missing config values to a known-good depth before construction.","Reject zero-valued ints from config structs explicitly (Go zero value 0 is invalid here)."],"tags":["trie","bintrie","config","bounds-check","panic","go"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}