File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,14 @@ package distribution
55
66import (
77 "fmt"
8+
89 "github.com/ethereum/go-ethereum/common"
910)
1011
12+ // OPERATOR_TABLE_LEAF_SALT is the salt used for encoding operator table leaves
13+ // This matches the salt used in the EigenLayer contracts to prevent second preimage attacks
14+ const OPERATOR_TABLE_LEAF_SALT = 0x8e
15+
1116// OperatorSet represents a unique operator set in the EigenLayer ecosystem.
1217// It consists of an ID and the address of the associated AVS (Actively Validated Service).
1318type OperatorSet struct {
@@ -137,3 +142,20 @@ func (d *Distribution) GetOperatorSets() []OperatorSet {
137142 }
138143 return sets
139144}
145+
146+ // EncodeOperatorTableLeaf encodes an operator table leaf for merkleization.
147+ // This function creates a consistent leaf encoding format that matches the EigenLayer
148+ // contracts' LeafCalculatorMixin implementation to prevent second preimage attacks.
149+ //
150+ // The format follows: OPERATOR_TABLE_LEAF_SALT || operatorTableBytes
151+ // The Merkle tree library will then hash this salted data with keccak256.
152+ //
153+ // Parameters:
154+ // - operatorTableBytes: The operator table data bytes
155+ //
156+ // Returns:
157+ // - []byte: The salted leaf data (salt + operatorTableBytes)
158+ func EncodeOperatorTableLeaf (operatorTableBytes []byte ) []byte {
159+ saltByte := []byte {OPERATOR_TABLE_LEAF_SALT }
160+ return append (saltByte , operatorTableBytes ... )
161+ }
Original file line number Diff line number Diff line change @@ -114,7 +114,15 @@ func (c *StakeTableCalculator) CalculateStakeTableRoot(
114114 zap .String ("opsetAvs" , opset .Avs .String ()),
115115 zap .String ("bytes" , hexutil .Encode (tableBytes )),
116116 )
117- opsetTableRoots [i ] = tableBytes
117+
118+ encodedLeaf := distribution .EncodeOperatorTableLeaf (tableBytes )
119+ opsetTableRoots [i ] = encodedLeaf
120+
121+ c .logger .Sugar ().Infow ("Encoded operator table leaf for opset" ,
122+ zap .Uint32 ("opsetId" , opset .Id ),
123+ zap .String ("opsetAvs" , opset .Avs .String ()),
124+ zap .String ("encodedLeaf" , hexutil .Encode (encodedLeaf )),
125+ )
118126
119127 err = dist .SetTableData (opset , tableBytes )
120128 if err != nil {
You can’t perform that action at this time.
0 commit comments