Skip to content

Commit 14c6c22

Browse files
committed
take into account proper validation and double check if the time is actaully in the past
1 parent 358fa04 commit 14c6c22

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

crates/rollkit/src/consensus.rs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,48 +70,19 @@ impl HeaderValidator for RollkitConsensus {
7070
header: &SealedHeader,
7171
parent: &SealedHeader,
7272
) -> Result<(), ConsensusError> {
73-
// Custom validation that allows same timestamps
74-
// This is the key difference from standard Ethereum consensus
75-
76-
// First validate parent hash and number
77-
if header.parent_hash != parent.hash() {
78-
return Err(ConsensusError::ParentHashMismatch(GotExpectedBoxed(
79-
Box::new(GotExpected {
80-
got: header.parent_hash,
81-
expected: parent.hash(),
82-
}),
83-
)));
84-
}
85-
86-
if header.number != parent.number + 1 {
87-
return Err(ConsensusError::ParentBlockNumberMismatch {
88-
parent_block_number: parent.number,
89-
block_number: header.number,
90-
});
91-
}
92-
93-
// ROLLKIT MODIFICATION: Allow same timestamp
94-
// Standard Ethereum requires: header.timestamp > parent.timestamp
95-
// Rollkit allows: header.timestamp >= parent.timestamp
96-
if header.timestamp < parent.timestamp {
97-
return Err(ConsensusError::TimestampIsInPast {
98-
parent_timestamp: parent.timestamp,
99-
timestamp: header.timestamp,
100-
});
101-
}
102-
// NOTE: We explicitly do NOT check for header.timestamp == parent.timestamp
103-
// as an error, which is the main change for Rollkit
104-
105-
// For all other validations, delegate to the inner consensus
106-
// but skip it when timestamps are equal since the inner consensus
107-
// would reject this case
108-
if header.timestamp == parent.timestamp {
109-
// Timestamps are equal, which we explicitly allow for Rollkit
110-
// Skip the inner consensus validation that would reject this
111-
Ok(())
112-
} else {
113-
// Timestamps are different, so we can safely delegate to inner consensus
114-
self.inner.validate_header_against_parent(header, parent)
73+
match self.inner.validate_header_against_parent(header, parent) {
74+
Ok(()) => Ok(()),
75+
Err(ConsensusError::TimestampIsInPast { .. }) => {
76+
if header.timestamp == parent.timestamp {
77+
Ok(())
78+
} else {
79+
Err(ConsensusError::TimestampIsInPast {
80+
parent_timestamp: parent.timestamp,
81+
timestamp: header.timestamp,
82+
})
83+
}
84+
}
85+
Err(e) => Err(e),
11586
}
11687
}
11788
}

0 commit comments

Comments
 (0)