Repository: unionlabs/union
File: light-clients/cometbls-light-client/src/client.rs (Rust)

Code before:

        // if untrusted_timestamp >= max_clock_drift {
        //     return Err(Error::InvalidHeader("header back to the future".into()));
        // }

        let trusted_validators_hash = consensus_state.data.next_validators_hash;

        let untrusted_validators_hash = if untrusted_height_number == trusted_height_number + 1 {
            trusted_validators_hash.clone()
        } else {
            header.signed_header.header.validators_hash.clone()
        };

        let expected_block_hash = header
            .signed_header
            .header
            .calculate_merkle_root()
            .ok_or(Error::UnableToCalculateMerkleRoot)?;

        if header.signed_header.commit.block_id.hash.0.as_slice() != expected_block_hash {
            return Err(Error::InvalidHeader(
                "commit.block_id.hash != header.root()".into(),
            ));
        }

        if client_state.data.chain_id != header.signed_header.header.chain_id {
            return Err(Error::InvalidHeader(format!(
                "chain ids dont match: {} {}",
                client_state.data.chain_id, header.signed_header.header.chain_id
            )));
        }

        let signed_vote = canonical_vote(
            &header.signed_header.commit,
            header.signed_header.header.chain_id.clone(),
            expected_block_hash,
        )
        .encode_length_delimited_to_vec();

        if !verify_zkp_v2(
            &trusted_validators_hash.0,
            &untrusted_validators_hash.0,
            &signed_vote,
            &header.zero_knowledge_proof,
        ) {
            return Err(Error::InvalidZKP);
        }

        Ok(())
    }


Review comment (bug):
this is removed because normally this check doesn't exist and it is only added for debugging purposes.

Code after:
            return Err(InvalidHeaderError::HeaderExpired(consensus_state.data.timestamp).into());
        }

        let max_clock_drift = env.block.time.seconds() + client_state.data.max_clock_drift;
        if untrusted_timestamp >= max_clock_drift {
            return Err(InvalidHeaderError::SignerHeaderCannotExceedMaxClockDrift {
                signed_timestamp: untrusted_timestamp,
                max_clock_drift,
            }
            .into());
        }

        let trusted_validators_hash = consensus_state.data.next_validators_hash;

        let untrusted_validators_hash = if untrusted_height_number == trusted_height_number + 1 {
            trusted_validators_hash.clone()
        } else {
            header.signed_header.header.validators_hash.clone()
        };

        let expected_block_hash = header
            .signed_header
            .header
            .calculate_merkle_root()
            .ok_or(Error::UnableToCalculateMerkleRoot)?;

        if header.signed_header.commit.block_id.hash != expected_block_hash {
            return Err(InvalidHeaderError::SignedHeaderMismatchWithCommitHash {
                commit_hash: header.signed_header.commit.block_id.hash,
                signed_header_root: expected_block_hash,
            }
            .into());
        }

        let signed_vote = canonical_vote(
            &header.signed_header.commit,
            header.signed_header.header.chain_id.clone(),
            expected_block_hash,
        )
        .encode_length_delimited_to_vec();

        if !verify_zkp_v2(
            &trusted_validators_hash.0,
            &untrusted_validators_hash.0,
            &signed_vote,
            &header.zero_knowledge_proof,
        ) {
            return Err(Error::InvalidZKP);
        }

        Ok(())