Cryptocode/falign: spacing between lines

cryptocodeline-spacingspacing

I'm using cryptocode to display some crypto-related things in a memoir document, but I'd like to decrease the default spacing, which is huge (especially when using one half spacing in the rest of the document):

enter image description here

I managed to make everything smaller but I still have a few issues, sometimes I've too much spacing (in red squares, sometimes it's even sometimes more than in the original picture), sometimes I've not enough (in green circles):

enter image description here

Any idea how to fix that?
MWE

\documentclass{memoir}

\checkandfixthelayout
%% Configure 1.5 spacing between lines
\OnehalfSpacing
% even if not documented, one must use checkandfixthelayout not to break the title template
% https://tex.stackexchange.com/questions/601273/memoir-checkandfixthelayout-required-for-single-onehalfspacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{interactGame}{center,boxed}{}{}{}


\begin{document}

What I managed to have (problem: still too much space between two arrows):

\NewExpandableDocumentCommand{\mysendmessageleft}{m}{\sendmessage{<-,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewExpandableDocumentCommand{\mysendmessageright}{m}{\sendmessage{->,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewDocumentEnvironment{gameInteract}{mb}{
\begin{Spacing}{0}%
  \interactGame[linenumbering]{#1}{#2\vspace{5mm}}
\end{Spacing}\par\vskip\baselineskip % Seems required or the next line will be eated up.
}{}

\begin{gameInteract}{My protocol}
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
    c \sample \bin                                  \>                                      \> \\
    (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
    \> \mysendmessageright{k}                \> \\
    \> \mysendmessageleft{\tilde{c}}         \> \\
    \pcreturn \tilde{c} = c                         \>                                      \>
\end{gameInteract}


What I have by default:
{\normalfont \interactGame[linenumbering]{My protocol}{
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
                                                  \> \sendmessageleft*{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin                                  \>                                      \> \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
                                                  \> \sendmessageright*{k}                \> \\
                                                  \> \sendmessageleft*{\tilde{c}}         \> \\
  \pcreturn \tilde{c} = c                         \>                                      \>
}}

\end{document}

Best Answer

The body of \gameInteract is not typeset with much attention to line spacing. You can get a uniform distance by setting Spacing to 1.2 and by smashing the labels above the arrows. I also reduced their size with \scriptstyle. Remove it if you don't like the style.

\documentclass{memoir}
\usepackage{amsmath}

\OnehalfSpacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}

\createprocedureblock{interactGame}{center,boxed}{}{}{}

\NewDocumentCommand{\mysendmessageleft}{m}{%
  \sendmessage{<-,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}
\NewDocumentCommand{\mysendmessageright}{m}{%
  \sendmessage{->,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}

\NewDocumentEnvironment{gameInteract}{m+b}
 {%
  \par\begin{Spacing}{1.2}
  \interactGame[linenumbering]{#1}{#2}
  \par\addvspace{\baselineskip}
  \end{Spacing}
 }{}

\begin{document}

What I managed to have (problem: still too much space between two arrows):

\begin{gameInteract}{My protocol}
  \textbf{Challenger} \> \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \\
    \> \mysendmessageright{k} \\
    \> \mysendmessageleft{\tilde{c}} \\
  \pcreturn \tilde{c} = c
\end{gameInteract}

Some other text to see what happens after the game.

\end{document}

enter image description here

Related Question