It has been suggested that ultrahigh-energy cosmic rays $($UHECRs$)$ can be produced by turbulent stochastic acceleration in relativistic jets of gamma-ray bursts $($GRBs$)$ on set of early afterglow. We develop a time-dependent model for proton energization by cascading compressible waves in GRB jets considering the concurrent effect of the jet's dynamics and the mutual interactions between turbulent waves and particles.
Considering fast magnetosonic wave as the dominant particle scatterer and assuming interstellar medium $($ISM$)$ for the circumburst environment, our results suggest that protons can be accelerated up to $\textrm{10}^{\textrm{19}}~$$\textrm{eV}$ during the phase of early afterglow. The spectral slope $\textrm{d}{N}/\textrm{d}{E} \propto {E}^\textrm{0}$, which is consistent with the requirement for the performance of intermediate-mass composition of UHECR as measured by the Pierre Auger Observatory.