Skip to content

Commit

Permalink
da validation
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Feb 11, 2025
1 parent 0625c8b commit cb06f8e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
11 changes: 10 additions & 1 deletion block/slvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ func NewSettlementValidator(logger types.Logger, blockManager *Manager) *Settlem
func (v *SettlementValidator) ValidateStateUpdate(batch *settlement.ResultRetrieveBatch) error {
v.logger.Debug("validating state update", "start height", batch.StartHeight, "end height", batch.EndHeight)

// validate da in state update matches rollapp param
daClient, err := v.blockManager.Store.LoadDA(batch.EndHeight)
if err != nil {
return err
}
if daClient != string(batch.MetaData.Client) {
return types.NewErrStateUpdateDAFraud(batch.StateIndex, batch.EndHeight, daClient, string(batch.MetaData.Client))
}

// loads blocks applied from P2P, if any.
p2pBlocks := make(map[uint64]*types.Block)
for height := batch.StartHeight; height <= batch.EndHeight; height++ {
Expand Down Expand Up @@ -102,7 +111,7 @@ func (v *SettlementValidator) ValidateStateUpdate(batch *settlement.ResultRetrie
}

// validate DA blocks against the state update
err := v.ValidateDaBlocks(batch, daBlocks)
err = v.ValidateDaBlocks(batch, daBlocks)
if err != nil {
return err
}
Expand Down
56 changes: 56 additions & 0 deletions mocks/github.com/dymensionxyz/dymint/store/mock_Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions store/storeIface.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Store interface {

SaveDRSVersion(height uint64, version uint32, batch KVBatch) (KVBatch, error)

LoadDA(height uint64) (string, error)

SaveDA(height uint64, da string, batch KVBatch) (KVBatch, error)

RemoveBlockCid(height uint64) error
Expand Down
28 changes: 28 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,31 @@ func (e ErrStateUpdateDRSVersionFraud) Error() string {
func (e ErrStateUpdateDRSVersionFraud) Unwrap() error {
return gerrc.ErrFault
}

// ErrStateUpdateDAFraud represents an error where the DA used in the state update does not follow rollapp param.
type ErrStateUpdateDAFraud struct {
StateIndex uint64
Height uint64
DA string
DAFraud string
}

func NewErrStateUpdateDAFraud(stateIndex uint64, height uint64, da string, daFraud string) error {
return &ErrStateUpdateDAFraud{
StateIndex: stateIndex,
Height: height,
DA: da,
DAFraud: daFraud,
}
}

func (e ErrStateUpdateDAFraud) Error() string {
return fmt.Sprintf(
"possible fraud detected: DA Mismatch - StateIndex: %d, Rollapp DA: %s, State Update DA: %s",
e.StateIndex, e.DA, e.DAFraud,
)
}

func (e ErrStateUpdateDAFraud) Unwrap() error {
return gerrc.ErrFault
}

0 comments on commit cb06f8e

Please sign in to comment.