  The opacity due to grains in the envelope of a protoplanet regulates the
accretion rate of gas during formation, thus the final bulk composition of
planets with primordial H/He is a function of it. Observationally, for
exoplanets with known mass and radius it is possible to estimate the bulk
composition via internal structure models. We first determine the reduction
factor of the ISM grain opacity f_opa that leads to gas accretion rates
consistent with grain evolution models. We then compare the bulk composition of
synthetic low-mass and giant planets at different f_opa with observations. For
f_opa=1 (full ISM opacity) the synthetic low-mass planets have too small radii,
i.e., too low envelope masses compared to observations. At f_opa=0.003, the
value calibrated with the grain evolution models, synthetic and actual planets
occupy similar mass-radius loci. The mean enrichment of giant planets relative
to the host star as a function of planet mass M can be approximated as
Z_p/Z_star = beta*(M/M_Jup)^alpha. We find alpha=-0.7 independent of f_opa in
synthetic populations in agreement with the observational result (-0.71+-0.10).
The absolute enrichment level decreases from beta=8.5 at f_opa=1 to 3.5 at
f_opa=0. At f_opa=0.003 one finds beta=7.2 which is similar to the
observational result (6.3+-1.0). We thus find observational hints that the
opacity in protoplanetary atmospheres is much smaller than in the ISM even if
the specific value of the grain opacity cannot be constrained here. The result
for the enrichment of giant planets helps to distinguish core accretion and
gravitational instability. In the simplest picture of core accretion where
first a critical core forms and afterwards only gas is added, alpha=-1. If a
core accretes all planetesimals inside the feeding zone, alpha=-2/3. The
observational result lies between these values, pointing to core accretion as
the formation mechanism.
