@@ -197,7 +197,7 @@ func getInitialState(ctx context.Context, genesis genesis.Genesis, signer signer
197197 BaseHeader : types.BaseHeader {
198198 ChainID : genesis .ChainID ,
199199 Height : genesis .InitialHeight ,
200- Time : uint64 (genesis .GenesisDAStartTime .UnixNano ()),
200+ Time : uint64 (genesis .GenesisDAStartTime .UnixNano ()), //nolint:gosec // G115: Conversion is safe, time values fit in uint64
201201 },
202202 }
203203
@@ -254,16 +254,17 @@ func getInitialState(ctx context.Context, genesis genesis.Genesis, signer signer
254254 DAHeight : 0 ,
255255 }
256256 return s , nil
257- } else if err != nil {
257+ }
258+ if err != nil {
258259 logger .Error ("error while getting state" , "error" , err )
259260 return types.State {}, err
260- } else {
261- // Perform a sanity-check to stop the user from
262- // using a higher genesis than the last stored state.
263- // if they meant to hard-fork, they should have cleared the stored State
264- if uint64 ( genesis . InitialHeight ) > s . LastBlockHeight { //nolint:unconvert
265- return types. State {}, fmt . Errorf ( " genesis.InitialHeight (%d) is greater than last stored state's LastBlockHeight (%d)" , genesis . InitialHeight , s . LastBlockHeight )
266- }
261+ }
262+
263+ // Perform a sanity-check to stop the user from
264+ // using a higher genesis than the last stored state.
265+ // if they meant to hard-fork, they should have cleared the stored State
266+ if uint64 ( genesis .InitialHeight ) > s . LastBlockHeight { //nolint:unconvert
267+ return types. State {}, fmt . Errorf ( "genesis.InitialHeight (%d) is greater than last stored state's LastBlockHeight (%d)" , genesis . InitialHeight , s . LastBlockHeight )
267268 }
268269
269270 return s , nil
@@ -770,7 +771,7 @@ func (m *Manager) applyBlock(ctx context.Context, header *types.SignedHeader, da
770771 return m .execApplyBlock (ctx , m .lastState , header , data )
771772}
772773
773- func (m * Manager ) Validate (ctx context.Context , header * types.SignedHeader , data * types.Data ) error {
774+ func (m * Manager ) Validate (_ context.Context , header * types.SignedHeader , data * types.Data ) error {
774775 m .lastStateMtx .RLock ()
775776 defer m .lastStateMtx .RUnlock ()
776777 return m .execValidate (m .lastState , header , data )
@@ -923,7 +924,13 @@ func convertBatchDataToBytes(batchData [][]byte) []byte {
923924 for _ , data := range batchData {
924925 // Encode length as 4-byte big-endian integer
925926 lengthBytes := make ([]byte , 4 )
926- binary .LittleEndian .PutUint32 (lengthBytes , uint32 (len (data )))
927+ dataLen := len (data )
928+ // Note: In practice, data chunks should never exceed uint32 max size
929+ // This check prevents integer overflow but should not occur in normal operation
930+ if dataLen > 0x7FFFFFFF { // Use a reasonable limit to avoid issues
931+ dataLen = 0x7FFFFFFF
932+ }
933+ binary .LittleEndian .PutUint32 (lengthBytes , uint32 (dataLen )) //nolint:gosec // G115: Conversion is safe after bounds check
927934
928935 // Append length prefix
929936 result = append (result , lengthBytes ... )
@@ -1120,6 +1127,7 @@ func (m *Manager) RollbackLastBlock(ctx context.Context) error {
11201127 if err == nil {
11211128 // Note: We can't remove from cache as there's no Remove method in the interface
11221129 // This is acceptable as the cache will eventually expire or be overwritten
1130+ m .logger .Debug ("Header exists in cache after rollback, will be overwritten on next access" )
11231131 }
11241132
11251133 // Reset DA included height if it was at the rolled-back height
0 commit comments