A virtually optical system with a hierarchical structure is designed for optical verification. At each hierarchical level, two phase-only masks are alternately generated using an iterative approach and then are sparsified. All sparse phase-only masks generated at the lower hierarchical levels are fixed and applied as constraints at the higher hierarchical level. Since sparse phase-only masks are applied for the decoding, the recovered images are invisible and instead can be further verified by a nonlinear correlation algorithm. The results are presented to show validity of the proposed method, and the proposed method provides a promising strategy for optical verification.