File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,13 @@ package distribution
66import (
77 "fmt"
88 "github.com/ethereum/go-ethereum/common"
9+ "github.com/ethereum/go-ethereum/crypto"
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,22 @@ 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: keccak256(abi.encodePacked(OPERATOR_TABLE_LEAF_SALT, operatorTableBytes))
151+ //
152+ // Parameters:
153+ // - operatorTableBytes: The operator table data bytes
154+ //
155+ // Returns:
156+ // - []byte: The 32-byte keccak256 hash of the salted leaf
157+ func EncodeOperatorTableLeaf (operatorTableBytes []byte ) []byte {
158+ saltByte := []byte {OPERATOR_TABLE_LEAF_SALT }
159+ data := append (saltByte , operatorTableBytes ... )
160+
161+ hash := crypto .Keccak256 (data )
162+ return hash
163+ }
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