We present high-precision photometric observations of the transiting exoplanets HAT-P-40b and HAT-P-51b by the Rozhen 2-m telescope. The newly-observed transit of HAT-P-40b is the first one with a complete curve. The orbital periods of the two targets were improved. We modeled the observed transits and found bigger stellar radii than those derived from the stellar models. The planet radii of HAT-P-40b and HAT-P-51b obtained from our transit solutions are bigger than the values calculated by the empirical relations for Jupiter-mass and Saturn-mass planets respectively. Their values reveal the highly-inflated nature of the two targets, especially that of HAT-P-51b. We established that the best transit solutions correspond to a quadratic limb-darkening law. The fitted limb-darkening coefficients of HAT-P-40 are close to the theoretical ones while those of HAT-P-51 are a little different. The precise astrometric Gaia distances of the two targets are smaller by 6%-7% than the calculated values from the stellar models. We propose the Gaia distances to be used for improvement of the stellar models as well as for more reliable calculation of the parameters of the known exoplanets.