Skip to content

Commit

Permalink
feat(rollapp): move DRS version to be part of the block descriptor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Oct 21, 2024
1 parent 0382bbc commit 8fb2d25
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 252 deletions.
3 changes: 1 addition & 2 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollap
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := uint64(0); k < numOfBlocks; k++ {
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC()}
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC(), DrsVersion: drsVersion}
}

updateState := rollapptypes.MsgUpdateState{
Expand All @@ -135,7 +135,6 @@ func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollap
DAPath: "",
BDs: bds,
Last: false,
DrsVersion: drsVersion,
}
msgServer := rollappkeeper.NewMsgServerImpl(*s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
Expand Down
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/block_descriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ message BlockDescriptor {
bytes stateRoot = 2;
// timestamp is the time from the block header
google.protobuf.Timestamp timestamp = 3 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 4;
}

// BlockDescriptors defines list of BlockDescriptor.
Expand Down
2 changes: 0 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/state_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ message StateInfo {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"created_at\""
];
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 11;
}

// StateInfoSummary is a compact representation of StateInfo
Expand Down
2 changes: 0 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ message MsgUpdateState {
BlockDescriptors BDs = 7 [(gogoproto.nullable) = false];
// last is true if this is the last batch of the sequencer
bool last = 8;
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 9;
}

message MsgUpdateStateResponse {
Expand Down
7 changes: 5 additions & 2 deletions x/rollapp/keeper/msg_server_mark_vulnerable_rollapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ func (k Keeper) MarkVulnerableRollapps(ctx sdk.Context, drsVersions []string) (i
logger.With("rollapp_id", rollapp.RollappId).Info("no latest state info for rollapp")
continue
}

// check only last block descriptor DRS, since if that last is not vulnerable it means the rollapp already upgraded and is not vulnerable anymore
bd := info.BDs.BD[len(info.BDs.BD)-1]
// TODO: this check may be deleted once empty DRS version is marked vulnerable
// https://github.com/dymensionxyz/dymension/issues/1233
if info.DrsVersion == "" {
if bd.DrsVersion == "" {
logger.With("rollapp_id", rollapp.RollappId).Info("no DRS version set for rollapp")
}

_, vulnerable := vulnerableVersions[info.DrsVersion]
_, vulnerable := vulnerableVersions[bd.DrsVersion]
if vulnerable {
err := k.MarkRollappAsVulnerable(ctx, rollapp.RollappId)
if err != nil {
Expand Down
23 changes: 12 additions & 11 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
return nil, errorsmod.Wrap(err, "before update state")
}

// verify the DRS version is not vulnerable
if k.IsDRSVersionVulnerable(ctx, msg.DrsVersion) {
// the rollapp is not marked as vulnerable yet, mark it now
err := k.MarkRollappAsVulnerable(ctx, msg.RollappId)
if err != nil {
return nil, fmt.Errorf("mark rollapp vulnerable: %w", err)
for _, bd := range msg.BDs.BD {
// verify the DRS version is not vulnerable
if k.IsDRSVersionVulnerable(ctx, bd.DrsVersion) {
// the rollapp is not marked as vulnerable yet, mark it now
err := k.MarkRollappAsVulnerable(ctx, msg.RollappId)
if err != nil {
return nil, fmt.Errorf("mark rollapp vulnerable: %w", err)
}
k.Logger(ctx).With("rollapp_id", msg.RollappId, "drs_version", bd.DrsVersion).
Info("non-frozen rollapp tried to submit MsgUpdateState with the vulnerable DRS version, mark the rollapp as vulnerable")
// we must return non-error if we want the changes to be saved
return &types.MsgUpdateStateResponse{}, nil
}
k.Logger(ctx).With("rollapp_id", msg.RollappId, "drs_version", msg.DrsVersion).
Info("non-frozen rollapp tried to submit MsgUpdateState with the vulnerable DRS version, mark the rollapp as vulnerable")
// we must return non-error if we want the changes to be saved
return &types.MsgUpdateStateResponse{}, nil
}

// retrieve last updating index
Expand Down Expand Up @@ -107,7 +109,6 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
creationHeight,
msg.BDs,
blockTime,
msg.DrsVersion,
)
// Write new state information to the store indexed by <RollappId,LatestStateInfoIndex>
k.SetStateInfo(ctx, *stateInfo)
Expand Down
94 changes: 74 additions & 20 deletions x/rollapp/types/block_descriptor.pb.go

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

1 change: 1 addition & 0 deletions x/rollapp/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ var (
ErrDisputeAlreadyReverted = errorsmod.Register(ModuleName, 2001, "disputed height already reverted")
ErrWrongClientId = errorsmod.Register(ModuleName, 2002, "client id does not match the rollapp")
ErrWrongProposerAddr = errorsmod.Register(ModuleName, 2003, "wrong proposer address")
ErrInvalidDRSVersion = errorsmod.Register(ModuleName, 2004, "wrong DRS version")
)
14 changes: 10 additions & 4 deletions x/rollapp/types/message_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const TypeMsgUpdateState = "update_state"
const (
TypeMsgUpdateState = "update_state"
DRSVersionLength = 40
)

var _ sdk.Msg = &MsgUpdateState{}

Expand Down Expand Up @@ -68,11 +71,14 @@ func (msg *MsgUpdateState) ValidateBasic() error {
return errorsmod.Wrapf(ErrWrongBlockHeight, "StartHeight must be greater than zero")
}

// TODO: add a validation for DrsVersion once empty DRS version is marked vulnerable
// https://github.com/dymensionxyz/dymension/issues/1233

// check that the blocks are sequential by height
for bdIndex := uint64(0); bdIndex < msg.NumBlocks; bdIndex += 1 {

// TODO: by now DRS version can be empty, but it will be deprecated
// https://github.com/dymensionxyz/dymension/issues/1233
if msg.BDs.BD[bdIndex].DrsVersion != "" && len(msg.BDs.BD[bdIndex].DrsVersion) != DRSVersionLength {
return ErrInvalidDRSVersion
}
if msg.BDs.BD[bdIndex].Height != msg.StartHeight+bdIndex {
return ErrInvalidBlockSequence
}
Expand Down
2 changes: 0 additions & 2 deletions x/rollapp/types/state_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewStateInfo(
height uint64,
BDs BlockDescriptors,
createdAt time.Time,
drsVersion string,
) *StateInfo {
stateInfoIndex := StateInfoIndex{RollappId: rollappId, Index: newIndex}
status := common.Status_PENDING
Expand All @@ -33,7 +32,6 @@ func NewStateInfo(
Status: status,
BDs: BDs,
CreatedAt: createdAt,
DrsVersion: drsVersion,
}
}

Expand Down
Loading

0 comments on commit 8fb2d25

Please sign in to comment.