\subsection{The Emerton-Gee stack}~
\vspace{3mm}

We follow the notation of \cite{EG19}.
For each $d>0$, \cite{EG19}
constructed the moduli stack
$\mathcal{X}_d = \mathcal{X}_{K,d}$
of projection \'etale $(\phi, \Gamma_K)$-modules of rank $d$.

We prove a mild generalization of
\cite[Proposition 5.4.4(1)]{EG19}.

Let $T$ be a reduced finite type
$\bar{\mathbb{F}}_p$-scheme.
Let $f:T\to (\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}$
be a morphism.
There is a morphism
$$
\eta:(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
\to (\mathcal{X}_{ad, \operatorname{red}})_{\bar{\mathbb{F}}_p}
$$
sending a pair of $(\phi, \Gamma)$-modules
$M, N$
to their hom module $\operatorname{Hom}_{\phi, \Gamma}(M,N)$.
The morphism $\eta(f)$
corresponds to a family $\bar\rho_T$
of rank-$ad$ Galois representations over
$T$.
We assume $H^2(G_K, \bar\rho_{\eta(t)})$
is of constant rank for all $t\in T(\bar{\mathbb{F}}_p)$.
By \cite[Lemma 5.4.4]{EG19},
the coherent sheaf
$H^2(G_K, \bar\rho_T)$
is locally free of rank $r$ as
an $\mathcal{O}_E$-module.

By \cite[Theorem 5.1.21]{EG19},
we can choose a complex of finite rank
locally free $\mathcal{O}_E$-modules
$$
C_T^0\to C_T^1\to C_T^2
$$
computing $H^{\bullet}(G_K, \bar\rho_T)$.
Since $H^2(G_K, \bar\rho_T)$
is a locally free sheaf,
the truncated complex
$$
C_T^0\to Z^1_T
$$
is again a complex of locally free $\mathcal{O}_T$-modules.
The vector bundle
$\mathscr{V}(Z^1_T):=
\underline{Spec}(\operatorname{Sym}(Z^1_T)^{\vee})$
associated to the locally free sheaf
$Z^1_{T}$ parameterizes all extensions
$$
0\to \bar\rho_{\eta(t)} \to ? \to \bar{\mathbb{F}}_p \to 0,
\hspace{3mm}t\in T(\bar{\mathbb{F}}_p)
$$
of the trivial $G_K$-representation $\bar{\mathbb{F}}_p$
by $\bar\rho_{\eta(t)}$.
There are two projection morphisms
$$()_1:
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
\to (\mathcal{X}_{a,\operatorname{red}})_{\bar{\mathbb{F}}_p}$$
and
$$()_2:
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
\to (\mathcal{X}_{d,\operatorname{red}})_{\bar{\mathbb{F}}_p}$$
For each $t\in T(\bar{\mathbb{F}}_p)$,
$f(t)_1 \in (\mathcal{X}_{a, \operatorname{red}})({\bar{\mathbb{F}}_p})$
corresponds to a rank-$a$ Galois representation $\bar\rho_{t_1}$,
and
$f(t)_2 \in (\mathcal{X}_{d, \operatorname{red}})({\bar{\mathbb{F}}_p})$
corresponds to a rank-$d$ Galois representation $\bar\rho_{t_2}$.
We have
$\bar\rho_{\eta(t)}=\operatorname{Hom}_{G_K}(\bar\rho_{t_1}, \bar\rho_{t_2})$.
So we can also regard $\mathscr{V}(Z^1_T)$
is a scheme parametrizing all extensions
$$
0\to \bar\rho_{t_1}\to ? \to \bar\rho_{t_2}\to 0,
\hspace{3mm}t\in T(\bar{\mathbb{F}}_p)
$$
and we have a morphism
sending extension classes
to equivalence classes of $G_K$-representations
$$
g:\mathscr{V}(Z^1_T)\to (\mathcal{X}_{a+d, \operatorname{red}})_{\bar{\mathbb{F}}_p}.
$$

\paragraph{Lemma}
\label{lem:est}
Let $e$ denote the dimension of
the scheme-theoretic image of $T$
in
$
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
$.
Then the scheme-theoretic image of
$V=\mathscr{V}(Z^1_T)$
in $(\mathcal{X}_{a+d, \operatorname{red}})_{\bar{\mathbb{F}}_p}$
has dimension at most
$$
e+r+ad[K:\mathbb{Q}_p].
$$

\begin{proof}
Without loss of generality,
we assume $T$ (and hence $V$) is irreducible.
The proof is a routine calculation
using stacks. We follow the proof
of \cite[Proposition 5.4.4]{EG19} closely.

Let $v\in V(\bar{\mathbb{F}}_p)$.
Write $t$ for the composite
$\operatorname{Spec} \bar{\mathbb{F}}_p \xrightarrow{v} V\to T$.
Write $f(t)$ for the composite $f\circ t$
Write $g(v)$ for the composite $g\circ v$.
Define
$$T_{f(t)}:= T\underset{f,
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
,f(t)}{\times}\operatorname{Spec} \bar{\mathbb{F}}_p$$
$$V_{g(v)}:= V\underset{g,
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
,g(v)}{\times}\operatorname{Spec} \bar{\mathbb{F}}_p$$
$$V_{f(t),g(v)}:= V_{g(v)}\underset{
(\mathcal{X}_{a, \operatorname{red}})_{\bar{\mathbb{F}}_p}\times
(\mathcal{X}_{d, \operatorname{red}})_{\bar{\mathbb{F}}_p}
,f(t)}{\times}\operatorname{Spec} \bar{\mathbb{F}}_p.$$
Note that
$V_{f(t), g(v)}\cong T_{f(t)}\times_TV_{g(v)}$.

By \cite[Tag 0DS4]{stacks-project},
it suffices to show, for $v$ lying
in some dense open subset of $V$,
$$
\dim V_{f(t),g(v)}
\ge \dim V -(e+r+ad[K:\mathbb{Q}_p]).
$$
Let $\bar\rho_{f(t)_1}$ denote
the Galois representation
corresponding to
$f(t)_1:\operatorname{Spec} \bar{\mathbb{F}}_p\to (\mathcal{X}_{a,\operatorname{red}})_{\bar{\mathbb{F}}_p}$.
Let $\bar\rho_{f(t)_2}$ denote
the Galois representation
corresponding to
$f(t)_2:\operatorname{Spec} \bar{\mathbb{F}}_p\to (\mathcal{X}_{d,\operatorname{red}})_{\bar{\mathbb{F}}_p}$.
Say $G_{t_1}:=\operatorname{Aut}(\bar\rho_{f(t)_1})$,
and $G_{t_2}:=\operatorname{Aut}(\bar\rho_{f(t)_2})$.
The morphism $f(t)$ factors through
a monomorphism
$$
[\operatorname{Spec} \bar{\mathbb{F}}_p/G_{t_1}]
\times [\operatorname{Spec} \bar{\mathbb{F}}_p/G_{t_2}]
\hookrightarrow
(\mathcal{X}_{a,\operatorname{red}})_{\bar{\mathbb{F}}_p}
\times(\mathcal{X}_{d,\operatorname{red}})_{\bar{\mathbb{F}}_p}
$$
which induces a monomorphism
$$
([\operatorname{Spec} \bar{\mathbb{F}}_p/G_{t_1}]
\times [\operatorname{Spec} \bar{\mathbb{F}}_p/G_{t_2}])
\underset{(\mathcal{X}_{a,\operatorname{red}})_{\bar{\mathbb{F}}_p}\times (\mathcal{X}_{d,\operatorname{red}})_{\bar{\mathbb{F}}_p}}{\times}V_{g(v)}
\hookrightarrow
V_{g(v)}.
$$
So it suffices to show
$$
\text{($\dagger$)}\hspace{5mm}\dim V_{f(t),g(v)} \ge \dim V
-(e+r+ad[K:\mathbb{Q}_p]) + \dim G_{t_1}+\dim G_{t_2}
$$
for $v$ lying in a dense open of $V$.

There exists an \'etale cover
$S$ of $(T_{f(t)})_{\operatorname{red}}$
such that the pull-back family
$\bar\rho_S$ is a trivial family
with fiber $\bar\rho_t$.

Let $C^0_S\to Z^1_S$ denote the
pullback family of $C^0_T\to Z^1_T$
to $S$.
$C^0_S\to Z^1_S$ is also the
pullback family of the fiber
$C^0_{t}\to Z^1_{t}$ to $S$.
Write $W$ for the affine scheme associated to
$H^1(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar\rho_{f(t)_2})$.
By the isomorphism
$$
H^1(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar\rho_{f(t)_2})\cong \operatorname{Ext}_{G_K}(\bar\rho_{f(t)_1},\bar\rho_{f(t)_2})
$$
there is a morphism $W\to(\mathcal{X}_{a+d,\operatorname{red}})_{\bar{\mathbb{F}}_p}$.
Denote by $w$ the image of $v$ in $w$.
We have
$$
S\times_T V_{g(v)} = S\times_TV\times_WW_{h(w)}.
$$
Let $V'$ be the kernel of
$S\times_TV\to S\times_{\bar{\mathbb{F}}_p}W$,
which is a trivial vector bundle over $S$.
We have
\begin{eqnarray}
\dim V_{f(t),g(v)}&=&\dim S\times_TV_{g(v)}\nonumber\\
&=&\operatorname{rank} V' + \dim S + \dim W_{h(w)}\nonumber\\
&=&\operatorname{rank} Z^1_T-\dim H^1(G_K,\bar\rho_{f(t)_1}^{\vee}\otimes\bar\rho_{f(t)_2})+\dim S+\dim W_{h(w)}\nonumber
\end{eqnarray}
Note that $\dim V-\dim T=\operatorname{rank} Z^1_T$,
and by local Euler characteristic
$
H^0(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar \rho_{f(t)_2})-
H^1(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar \rho_{f(t)_2})
+ r =- ad[K:\mathbb{Q}_p]
$.
We can replace $T$ by a dense open of $T$
where $e=\dim T-\dim T_{f(t)}=\dim T-\dim S$.
Combine all these equalities, ($\dagger$)
becomes
$$
\dim W_{h(w)} \ge \dim H^0(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar\rho_{f(t)_2})+\dim G_{t_1} + \dim G_{t_2}
$$
which follows from the fact that
$$
H^0(G_K, \bar\rho_{f(t)_1}^{\vee}\otimes\bar\rho_{f(t)_2}) \rtimes (G_{t_1}\times G_{t_2}) \subset \operatorname{Aut}(\bar\rho_w)
$$
and $\dim W_{h(w)}\ge \dim \operatorname{Aut}(\bar\rho_w)$.
\end{proof}

We recall some terminology from
\cite{EG19}.
Denote by $\operatorname{ur}_x:\mathbb{G}_m\to\mathcal{X}_1$
the family of unramified characters of
$G_K$.
Let $T$ be a reduced finite type
${\mathbb{F}}$-scheme.
Let $T\to\mathcal{X}$ be a morphism,
corresponding to a family
$\bar \rho_T$ of $G_K$-representations
over $T$.
We can construct the family of
unramified twisting
$
\bar \rho_T \boxtimes \operatorname{ur}_x
$
over $T\times \mathbb{G}_m$.
$\bar\rho_T$ is said to be \textit{twistable}
if whenever $\bar\rho_t\cong \bar\rho_{t'}\otimes \operatorname{ur}_a$ for
    $t,t'\in T(\bar{\mathbb{F}}_p)$ and
    $a\in \bar{\mathbb{F}}_p^{\times}$, we have $a=1$.
 $\bar\rho_T$ is said to be \textit{essentially twistable} if for each $t\in T(\bar{\mathbb{F}}_p)$, the set of $a\ne 1$ for which $\bar\rho_t\cong \bar\rho_{t'}\otimes \operatorname{ur}_a$
 is finite.

 We say $\bar\rho_T$ is \textit{untwistable} if $\bar\rho$ is not essentially twistable.

From now on,
write $\mathcal{X} = (\mathcal{X}_{2, \operatorname{red}})_{\bar{\mathbb{F}}_p}$
for the moduli stack
parameterizing $(\phi, \Gamma)$-modules
of rank $2$.

Let $\bar r^{\operatorname{univ}}$ be the universal family
of $(\phi, \Gamma)$-modules
over $\mathcal{X}$.

\subsection{Loci cut out by $H^2(G_K, \operatorname{sym}^3/\det^2)$}~

\vspace{3mm}

Write $H^2$ for
$
H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}^{\operatorname{univ}})}{\det(\bar{r}^{\operatorname{univ}})^2})
$.
Let $x\in \mathcal{X}(\bar{\mathbb{F}}_p)$
with corresponding Galois representation
$\bar r_x:G_K\to \operatorname{GL}_2(\bar{\mathbb{F}}_p)$.
\vspace{3mm}

\paragraph{Lemma}
\label{lem:h2-irr}
If
$\bar r_x$ is irreducible, then
$$
h^2_x:=\dim_{\bar{\mathbb{F}}_p} H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r}_x)^2})\le 2.
$$

\begin{proof}
An irreducible mod $\varpi$ representation
is of the shape
$\operatorname{Ind}_{G_{K_2}}^{G_K}\bar\chi$
for some character $\bar\chi$ of
    the degree-$2$ unramified extension
    $K_2$ of $K$.
    A direct computation shows
    $$
    \operatorname{sym}^3(\bar{r}_x)=
    \operatorname{Ind}(\bar{\chi}^3) \oplus \operatorname{Ind}(\bar\chi\det\bar {r}_x).
    $$
Both
$H^2(G_K, \frac{\operatorname{Ind}(\bar\chi^3)}{\det(\bar{r}_x)^2})$
and
$H^2(G_K, \frac{\operatorname{Ind}(\bar\chi\det \bar{r}_x)}{\det(\bar{r}_x)^2})$
has dimension at most $1$.
This is because the induction
of a character can't  be
a direct sum of two isomorphic characters
(when $p\ne 2$).
\begin{comment}
So if we assume this Lemma fails,
then we must have
$H^2(G_K, \frac{1}{\det(\bar {r}_x)})=
\bar{\mathbb{F}}_p$, that is,
$\det(\bar{r}_x)=\bar{\mathbb{F}}_p(-1)$.
Now that since $\bar {r}_x=\operatorname{Ind}(\bar\chi)$ is irreducible,
$\frac{\operatorname{Ind}(\bar\chi\det \bar{r}_x)}{\det(\bar{r}_x)^2}$ must also be irreducible.
Hence
$$
H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r})^2}\oplus \frac{1}{\det(\bar {r}_x)})=
H^2(G_K, \frac{\operatorname{Ind}(\bar\chi^3)}{\det(\bar{r}_x)^2}) \oplus
H^2(G_K, \frac{1}{\det(\bar {r}_x)})
$$
has dimension at most $2$.
\end{comment}
\end{proof}

\paragraph{Corollary}
$H^2$ is SGR when restricted on the
irreducible locus.

\begin{proof}
Up to unramified twist,
there are only finitely many irreducible
representations.
The automorphism group of an irreducible representation is $1$-dimensional.
By Lemma \ref{lem:h2-irr}, we have
$h^2_x\le 2$ when $\bar r_x$ is irreducible.

We first consider the locus where
$h^2_x = 2$.
This locus consists of finitely many
irreducible $G_K$-representations, and
has dimension $-1$.
Then we consider the locus where
$h^2_x \le 1$.
This locus consists of
the unramified twisting of finitely many
irreducible $G_K$-representations, and has dimension
$0$.
In either case, $\dim$ of locus $\le [K:\mathbb{Q}_p]-h^2_x$.
\end{proof}

\paragraph{Lemma}
\label{lem:h2-ext}
If $\bar {r}_x$ is  a non-trivial
extension of two characters, then
$$
h^2_x:=\dim H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r}_x)^2})\le1
$$
and when the equality holds,
the quotient character of $\bar {r}_x$
is a character whose cubic power
is $\bar{\mathbb{F}}_p(1)$.

\begin{proof}
This is where we make use of
the assumption $p > 3$.
Say $\bar{r}_x \sim
\begin{bmatrix}
\bar{\chi}_1 & \bar c \\
& \bar{\chi}_2
\end{bmatrix}
$.
We have
$$
\operatorname{sym}^3(\bar{r}_x) \sim
\begin{bmatrix}
\bar{\chi}_1^3 & \bar{\chi}_1^2 \bar c & * & *\\
& \bar{\chi}_1^2\bar{\chi}_2&2\bar{\chi}_1\bar{\chi}_2\bar c & * \\
& & \bar{\chi}_1\bar\chi_2^2 & 3\bar{\chi}_2^2\bar c\\
& & & \bar{\chi}_2^3
\end{bmatrix}
$$
which has a unique $G_K$-invariant quotient line.
We give a proof of the above simple observation.
Let $\{e_1, e_2\}$ be a basis
of the representation space of $\bar {r}_x$ such that $e_1$ is an invariant line.
Then $\{e_1^3, e_1^2e_2,e_1e_2^2,e_2^3\}$
is a basis of the representation space
of $\operatorname{sym}^3(\bar{r}_x)$.
By duality, it is equivalent to saying that
$\operatorname{sym}^3(\bar {r}_x)$ has a unique
invariant line.
Clearly $\{e_1^3\}$ defines an invariant line.
Assume there is another invariant line
$\operatorname{span}(v)$.
We quotient $\operatorname{sym}^{3}(\bar {r}_x)$
by $\operatorname{span} (e_1)$.
The quotient representation has a unique
invariant line generated by the
image of $e_1^2e_2$.
So $v\in \operatorname{span}(e_1^3, e_1^2e_2)$.
But then we must have $v\in \operatorname{span}(e_1^3)$,
since $[\bar c]$ is a non-trivial
extension class.
\end{proof}

\vspace{3mm}

\paragraph{Corollary}
$H^2$ is SGR when restricted on the
locus where
$\bar {r}_x$ is a non-trivial extension
of two characters.

\begin{proof}
Say $\bar r_x$ is the extension of
$\bar \beta$ by $\bar \alpha$.
By Lemma \ref{lem:h2-ext}, we have
$h^2_x\le 1$ when $\bar r_x$ is a nontrivial extension of characters.
So the locus where $\bar{r}_x$
is a non-trivial extension of characters
consists of four sub-loci:
\begin{itemize}
\item[(i)]
$h^2_x = 1$ and $\operatorname{Ext}^2(\beta, \alpha)=0$;
\item[(ii)]
$h^2_x = 1$ and $\operatorname{Ext}^2(\beta, \alpha)\ne0$;
\item[(iii)]
$h^2_x = 0$ and $\operatorname{Ext}^2(\beta, \alpha)=0$; and
\item[(iv)]
$h^2_x = 0$ and $\operatorname{Ext}^2(\beta, \alpha)\ne 0$;
\end{itemize}

Let $T\subset (\mathcal{X}_{1,\operatorname{red}})_{\bar{\mathbb{F}}_p}
\times (\mathcal{X}_{1,\operatorname{red}})_{\bar{\mathbb{F}}_p}$
be the locus of the pair $(\alpha, \beta)$.
say $\dim T = e$, and
$\dim \operatorname{Ext}^2(\beta, \alpha) = r$.
By Lemma \ref{lem:est}, each sub-locus
has dimension at most
$$
e+r+[K:\mathbb{Q}_p].
$$
In sub-locus (i),
$\beta$ has only finitely many choices,
so $e=-1$, $r=1$;
in sub-locus (ii),
both $\beta$ and $\alpha$ have only
finitely many choices, so
$e=-2$, $r=0$;
in sub-locus (iii),
both $\beta$ and $\alpha$ can vary in a dense open of $(\mathcal{X}_{1,\operatorname{red}})_{\bar{\mathbb{F}}_p}$,
so $e=2\dim (\mathcal{X}_{1,\operatorname{red}})_{\bar{\mathbb{F}}_p}=0$,
$r=0$;
in sub-locus (iv),
when $\alpha$ is chosen, $\beta$ has only finitely many choices, so
$e=-1$, $r=1$.
We can verify that in each case
$e+r+[K:\mathbb{Q}_p] \le \dim \mathcal{X} -h^2_x=
[K:\mathbb{Q}_p]-h^2_x$.
\end{proof}

\paragraph{Lemma}
\label{lem:h2-dist}
If $\bar{r}_x$ is a direct sum of distinct characters,
then
$$
H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r}_x)^2})\le 2.
$$

\begin{proof}
Say $\bar{r}_x \sim
\begin{bmatrix}
\bar{\chi}_1 &  \\
& \bar{\chi}_2
\end{bmatrix}$.
We have
$$
 \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r})^2}
 \cong
 \bar{\chi}_1\bar{\chi}_2^{-2}\oplus
 \bar{\chi}_2^{-1}\oplus \bar{\chi}_1^{-1}
 \oplus \bar{\chi}_2\bar{\chi}_1^{-2}.
$$
If $\bar\chi_1\ne\bar\chi_2$,
then the multiset
$\{
 \bar{\chi}_1\bar{\chi}_2^{-2},
 \bar{\chi}_2^{-1}, \bar{\chi}_1^{-1},
 \bar{\chi}_1^{-2}\bar{\chi}_2\}
$
contains at most
$2$ isomorphic characters.
\end{proof}

\paragraph{Corollary}
$H^2$ is SGR when restricted on the locus
where $\bar {r}_x$ is a direct sum of
distinct characters.

\begin{proof}
By Lemma \ref{lem:h2-dist},
we have $h^2_x \le 2$ when
$\bar x = \alpha\oplus \beta$
is a direct sum of distinct characters.

In the locus where $h^2_x = 2$,
we must have $\pm \alpha=\pm \beta={\mathbb{F}}(-1)$.
So both $\alpha$ and $\beta$ lives in
a twistable family and this locus has dimension $-2$.

In the locus where $h^2_x =1$, we have
one of the following:
(i) $\alpha={\mathbb{F}}(-1)$, (ii)
$\beta={\mathbb{F}}(-1)$, (iii)
$\alpha=\beta^2(-1)$, (iv)
$\beta=\alpha^2(-1)$.
In each of these cases,
the locus has dimension
$\dim \mathbb{G}_m - \dim \text{Aut}(\bar {r}_x)
= 1-2=-1$.

In the locus where $h^2_x=0$,
both $\alpha$ and $\beta$ lives
in an untwistable family, and the locus
has dimension
$2\dim \mathbb{G}_m - \dim \text{Aut}(\bar {r}_x)
=2-2=0$.
\end{proof}

\paragraph{Lemma}
\label{lem:h2-scalar}
If $\bar {r}_x$ is a direct sum of
isomorphic characters, then
$$
H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r}_x)^2})\le 4.
$$

\begin{proof}
This is trivial because the underlying
$\bar{\mathbb{F}}_p$-vector space is $4$-dimensional.
\end{proof}

\paragraph{Corollary}
$H^2$ is SGR when restricted on the locus
where $\bar {r}_x$ is a direct sum of
isomorphic characters.

\begin{proof}
The automorphism group is $4$-dimensional.
So the locus in the moduli stack  has dimension
$\dim \mathbb{G}_m - \dim \text{Aut}(\bar {r}_x)
=1-4=-3$.
\end{proof}

\vspace{3mm}

\paragraph{Theorem}
\label{thm:egstack}
The locus of $\bar r_x$ in $\mathcal{X}$ for which
$$
H^2(G_K, \frac{\operatorname{sym}^3(\bar {r}_x)}{\det(\bar{r}_x)^2})\ge r.
$$
is of dimension
at most
$[K:\mathbb{Q}_p]-r$.

\begin{proof}
This theorem follows immediately from
Lemma \ref{lem:h2-irr},
Lemma \ref{lem:h2-ext},
Lemma \ref{lem:h2-dist},
Lemma \ref{lem:h2-scalar},
and their corollaries.
\end{proof}

Fix a mod $\varpi$ representation
$
\bar r: G_K\to GL_2({\mathbb{F}})
$.
Let $\underline{\lambda}$ be a Hodge type.
Let $R$ be an irreducible component of the crystalline lifting ring
${R_{\bar r}^{\operatorname{crys}, \underline{\lambda}, \mathcal{O}_E}}$.
Assume $\operatorname{Spec} R[1/p]\ne \emptyset$.
Let $r^{\operatorname{univ}}$ be the universal family
of Galois representations on $R$.

Since $H^2(G_K, \frac{\operatorname{sym}^3({r}^{\operatorname{univ}})}{\det({r}^{\operatorname{univ}})^2})$ is a coherent sheaf,
by the semicontinuity theorem,
the locus
$ X_s:=\{x\in\operatorname{Spec} R|\dim \kappa(x)\otimes_R H^2 \ge s\}$
is locally closed, and
has a reduced induced scheme structure.

\vspace{3mm}
\paragraph{Theorem}
\label{thm:codim-ad}
Let $R$ be an irreducible component of the crystalline lifting ring
of regular labeled Hodge-Tate weights.
If $H^2(G_K, \frac{\operatorname{sym}^3({r}^{\operatorname{univ}})}{\det({r}^{\operatorname{univ}})^2})$ is $\varpi$-torsion,
the locus $$\{x\in\operatorname{Spec} R|\dim \kappa(x)\otimes_R H^2(G_K, \frac{\operatorname{sym}^3({r}^{\operatorname{univ}})}{\det({r}^{\operatorname{univ}})^2}) \ge s\}$$ has codimension
$\ge s+1$ in $\operatorname{Spec} R$.

\begin{proof}
The proof is identical to that
of \cite[Theorem 6.1.1]{EG19}
if we use
Theorem \ref{thm:egstack} instead of
\cite[Theorem 5.5.11]{EG19}.
\end{proof}

\vspace{3mm}

\subsection{Loci cut out by $H^2(G_K, 1/\det)$}
~
\vspace{3mm}

\paragraph{Theorem}
\label{thm:codim-z}
Let $R$ be an irreducible component of the crystalline lifting ring
of regular labeled Hodge-Tate weights.
(1)
The locus of $\bar r_x$ in $\mathcal{X}$ for which
$$
H^2(G_K, \frac{1}{\det(\bar{r}_x)})\ge r
$$
is of dimension
at most
$[K:\mathbb{Q}_p]-r$.

(2) Let $\operatorname{Spec} R$ be an irreducible component of a crystalline lifting
ring such that $\operatorname{Spec} R[1/p]\ne \emptyset$.
If $H^2(G_K,\frac{1}{\det({r}^{\operatorname{univ}})})$ is $\varpi$-torsion,
the locus $\{x\in\operatorname{Spec} R|\dim \kappa(x)\otimes_R H^2(G_K,\frac{1}{\det({r}^{\operatorname{univ}})}) \ge s\}$ has codimension
$\ge s+1$ in $\operatorname{Spec} R$.

\begin{proof}
(1) Follows from an analysis
similar to, but much simpler than
Theorem \ref{thm:egstack}.

(2) Completely similar to
Theorem \ref{thm:codim-ad}.
\end{proof}

\subsubsection{Lemma}
\label{lem:cup-C-nondeg}
The cup products on cochains
$$
\cup_{{\mathbb{F}}}:
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\times
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\to C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))
$$
is non-degenerate.

\noindent
\textbf{Ideas} \hspace{3mm}
We compute the cup products
$v\cup w$
for $v,w\in\mathscr{B}$.
The matrix $[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$
is anti-lower-triangular, (that is,
of the shape
$$
\begin{bmatrix}
0 & 0 & 0 &* \\
0 & 0 & * &* \\
0 & * & * & * \\
* & * & * & *
\end{bmatrix}
$$
whose anti-diagonal blocks are
constant invertible matrices
), and thus non-degenerate.

To help the reader better understand what's
going on,
we attached SageMath code in the Appendix \ref{sec:sage}.

\begin{proof}
Recall the relator of the Lyndon-Demu\v{s}kin group is
$$
R={x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}.
$$
Since we are working mod $\varpi$,
we have for any $p>5$, any $g\in G_{K'}$,
$\phi(\bar r(g))^p \equiv \operatorname{id}$ mod $\varpi$ (See Appendix \ref{sec:sage} for the verification).
In particular, the relator $R$ reduces to
$$
(x_0, x_1)\dots(x_{n}, x_{n+1})
$$
when we compute mod $\varpi$.
(When $p=5$, things are still good,
and can be confirmed by running
the SageMath code in the appendix.)

We regard cochains in
$C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))$
as a $(U^{\operatorname{ad}}({\mathbb{F}}))$-valued function
on the free group with generators
$\{x_0, \dots, x_{n+1}\}$,

Now we let $c$ be the ``universal''
mod $\varpi$
1-cochain.
That is, we let
$$
\left\{
\begin{matrix}
\lambda_{0,0}, &\lambda_{1,0} , &\dots, &\lambda_{n+1,0},\\
\lambda_{0,1}, &\lambda_{1,1} , &\dots, &\lambda_{n+1,1},\\
\lambda_{0,2}, &\lambda_{1,2} , &\dots, &\lambda_{n+1,2},\\
\lambda_{0,3}, &\lambda_{1,3} , &\dots, &\lambda_{n+1,3}
\end{matrix}
\right\}
$$
be indeterminants, and set
$$c:= \sum \lambda_{i,j}x_i^*E_j\in
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))\otimes {\mathbb{Z}}[\lambda_{i,j}].$$

The cup product
$$
c\cup c = Q(c) \in C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))\otimes {\mathbb{Z}}[\lambda_{i,j}] = Z(U)({\mathbb{F}})\otimes {\mathbb{Z}}[\lambda_{i,j}] \cong {\mathbb{F}}[\lambda_{i,j}]
$$ will be a quadratic form
in variables $\{\lambda_{i,j}\}$,
and the matrix of this quadratic form
is nothing but the matrix
$[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$.
Recall that $c\cup c =Q(c)$
is defined to be
the projection of $\widetilde{c}(R)$ onto
the center of the Lie algebra $\operatorname{Lie} U$,
where
$\widetilde{c}\in C^1_{\operatorname{LD}}(U({\mathbb{F}}))$
is the unique extension of $c$ to
a $U({\mathbb{F}})$-valued cochain
as is explained in Section \ref{sec:LD}.

Write $[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$ as
a block matrix
$$
\renewcommand{\kbldelim}{(
\renewcommand{\kbrdelim}{)
[\cup_{{\mathbb{F}}}]_{\mathscr{B}}=
\kbordermatrix{
    & \beta &\omit& \beta+\alpha &\omit&\beta+2\alpha &\omit&\beta+3\alpha\\
\beta &M_{11}&\omit\vrule& M_{12} &\omit\vrule& M_{13} &\omit\vrule& M_{14} \\
\cline{2-8}
\beta+\alpha&M_{21} &\omit\vrule& M_{22} &\omit\vrule& M_{23} &\omit\vrule& M_{24} \\
\cline{2-8}
\beta+2\alpha&M_{31} &\omit\vrule& M_{32} &\omit\vrule& M_{33} &\omit\vrule& M_{34} \\
\cline{2-8}
\beta+3\alpha&M_{41} &\omit\vrule& M_{42} &\omit\vrule& M_{43} &\omit\vrule& M_{44}
}
$$
where each $M_{ij}$ is an $(n+2)\times(n+2)$ matrix.
We say the blocks $M_{24}$, $M_{33}$,
$M_{34}$, $M_{42}$, $M_{43}$, $M_{44}$
are \textit{strictly below the anti-diagonal},
and we call $M_{41}$, $M_{32}$, $M_{23}$
and $M_{14}$ the anti-diagonal blocks.
\begin{figure}[h!]
\begin{minipage}{.49\linewidth}
\centering
$$
\renewcommand{\kbldelim}{(
\renewcommand{\kbrdelim}{)
\kbordermatrix{
    & \beta &\omit& \beta+\alpha &\omit&\beta+2\alpha &\omit&\beta+3\alpha\\
\beta &&\omit\vrule&  &\omit\vrule&  &\omit\vrule&  \\
\cline{2-8}
\beta+\alpha& &\omit\vrule&  &\omit\vrule&  &\omit\vrule& M_{24} \\
\cline{2-8}
\beta+2\alpha& &\omit\vrule&  &\omit\vrule& M_{33} &\omit\vrule& M_{34} \\
\cline{2-8}
\beta+3\alpha& &\omit\vrule& M_{42} &\omit\vrule& M_{43} &\omit\vrule& M_{44}
}
$$
\caption{Strictly below anti-diagonal}
\end{minipage}
\begin{minipage}{.45\linewidth}
$$
\renewcommand{\kbldelim}{(
\renewcommand{\kbrdelim}{)
\kbordermatrix{
    & \beta &\omit& \beta+\alpha &\omit&\beta+2\alpha &\omit&\beta+3\alpha\\
\beta &&\omit\vrule&  &\omit\vrule&  &\omit\vrule& M_{14} \\
\cline{2-8}
\beta+\alpha& &\omit\vrule&  &\omit\vrule& M_{23} &\omit\vrule&  \\
\cline{2-8}
\beta+2\alpha& &\omit\vrule& M_{32} &\omit\vrule&  &\omit\vrule&  \\
\cline{2-8}
\beta+3\alpha&M_{41} &\omit\vrule&  &\omit\vrule&  &\omit\vrule&
}
$$
\caption{Anti-diagonal blocks}
\end{minipage}
\end{figure}

\textbf{Sublemma}
Let $g=g_1g_2\dots g_s$.
Write $\phi_i$ for $\phi(\bar r(g_1,\dots,g_{i-1}))$.
We have
$$\widetilde{c}(g) = \sum \phi_i \widetilde{c}(g_i)
+ \frac{1}{2}\sum_{i<j}[\phi_i \widetilde{c}(g_i), \phi_j \widetilde{c}(g_j)].$$

\begin{quotation}
\begin{proof}
An immediate consequence of the
Baker–Campbell–Hausdorff formula.
\end{proof}
\end{quotation}

\vspace{3mm}

Note that
$\phi(\bar {r}((x_i, x_j)) = \operatorname{id}$,
so
\begin{eqnarray}
\widetilde{c}(R) &=& \widetilde{c}({x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})})
\nonumber\\
&=&\sum \widetilde{c}((x_{2k},x_{2k+1}))
+ \frac{1}{2}\sum_{j<k}
[\widetilde{c}((x_{2j}, x_{2j+1}), \widetilde{c}( (x_{2k}, x_{2k+1})]\nonumber
\end{eqnarray}
We have
$$
\widetilde{c}( (x_{2k}, x_{2k+1}))
= -\phi(x_{2k}^{-1})(\phi(x_{2k+1})-1)\widetilde{c}(x_{2k})
+ \phi(x_{2k}^{-1}x_{2k+1}^{-1})(\phi(x_{2k})-1)\widetilde{c}(x_{2k+1})
+ Z_{k}
=Y_k+ Z_k
$$
where $Z_k$ is a sum of Lie brackets
(see below), and
lies in the center of the $\operatorname{Lie} U$.
Note that
$[Y_j, Y_k]$ only contributes to the part
of $[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$
which lies strictly below the anti-diagonal,
because
$(\phi(x_{2k})-1)$ and $(\phi(x_{2k+1})-1)$
moved the appearance of the inderterminant
$\lambda_{i,j}$
from the root group $U_{\beta+j\alpha}$
to the root group $U_{\beta+(j+1)\alpha}$.

So it remains to analyze
$\sum Z_k$.
We have
\begin{eqnarray}
2 Z_k &=&
[-\phi(x_{2k}^{-1}) \widetilde{c}(x_{2k}),
-\phi(x_{2k}^{-1}x_{2k+1}^{-1})\widetilde{c}(x_{2k+1})] \nonumber
\\&+&
[-\phi(x_{2k}^{-1}) \widetilde{c}(x_{2k}),
+\phi(x_{2k}^{-1}x_{2k+1}^{-1})\widetilde{c}(x_{2k})]\nonumber\\
&+&
[-\phi(x_{2k}^{-1}) \widetilde{c}(x_{2k}),
+\phi(x_{2k}^{-1}x_{2k+1}^{-1}x_{2k})\widetilde{c}(x_{2k+1})] \nonumber\\
&+&
[-\phi(x_{2k}^{-1}x_{2k+1}^{-1}) \widetilde{c}(x_{2k+1}),
+\phi(x_{2k}^{-1}x_{2k+1}^{-1})\widetilde{c}(x_{2k})]\nonumber\\
&+&
[-\phi(x_{2k}^{-1}x_{2k+1}^{-1}) \widetilde{c}(x_{2k+1}),
+\phi(x_{2k}^{-1}x_{2k+1}^{-1}x_{2k})\widetilde{c}(x_{2k+1})] \nonumber\\
&+&
[\phi(x_{2k}^{-1}x_{2k+1}^{-1}) \widetilde{c}(x_{2k}),
+\phi(x_{2k}^{-1}x_{2k+1}^{-1}x_{2k})\widetilde{c}(x_{2k+1})] \nonumber
\end{eqnarray}
Write
\begin{eqnarray}
2Z_k' &:=&
[-\widetilde{c}(x_{2k}), -\widetilde{c}(x_{2k+1})]\nonumber\\
&+&
[-\widetilde{c}(x_{2k}), \widetilde{c}(x_{2k})]\nonumber\\
&+&
[-\widetilde{c}(x_{2k}), \widetilde{c}(x_{2k+1})]\nonumber\\
&+&
[-\widetilde{c}(x_{2k+1}), \widetilde{c}(x_{2k})]\nonumber\\
&+&
[-\widetilde{c}(x_{2k+1}), \widetilde{c}(x_{2k+1})]\nonumber\\
&+&
[\widetilde{c}(x_{2k}), \widetilde{c}(x_{2k+1})]\nonumber
\end{eqnarray}
$Z_k'$ is obtained by replacing
all Galois action in $Z_k$
by the trivial action.
$Z_k -Z_k'$ only contributes
to the part of $[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$
with lies strictly below the anti-diagonal
for a similar reason (a ``shifting'' effect).
It is easy to see that
$$Z_k' = [\widetilde{c}(x_{2k}), \widetilde{c}(x_{2k+1})] =
\pm\lambda_{2k,0}\lambda_{2k+1,3}
\pm\lambda_{2k+1,0}\lambda_{2k,3}
\pm 3\lambda_{2k,1}\lambda_{2k+1,2}
\pm 3\lambda_{2k+1,2}\lambda_{2k,1}.
$$
As a consequence of these computations,
we see that each of the anti-diagonal blocks of $[\cup_{\bf}]_{\mathscr{B}}$
are constant matrices:
$$
\pm M_{41}= \pm M_{14}=
\begin{bmatrix}
\begin{bmatrix}
& -1/2 \\
1/2 &
\end{bmatrix}
&
&
&\\
&
\begin{bmatrix}
& -1/2 \\
1/2 &
\end{bmatrix}
& & \\
& & \dots & \\
& & &
\begin{bmatrix}
& -1/2 \\
1/2 &
\end{bmatrix}
\end{bmatrix}
$$
and
$$
\pm M_{32}= \pm M_{23}=
\begin{bmatrix}
\begin{bmatrix}
& -3/2 \\
3/2 &
\end{bmatrix}
&
&
&\\
&
\begin{bmatrix}
& -3/2 \\
3/2 &
\end{bmatrix}
& & \\
& & \dots & \\
& & &
\begin{bmatrix}
& -1/2 \\
1/2 &
\end{bmatrix}
\end{bmatrix}.
$$

So $[\cup_{{\mathbb{F}}}]_{\mathscr{B}}$
is an invertible matrix.
\end{proof}

The long root parabolic case is much simpler.

\subsubsection{Definition}
\label{def:delta-flat}
Let $A$ be an $\mathcal{O}_E$-algebra.
Endow $U(\mathcal{O}_E)$ with a Lyndon-Demu\v{s}kin $G_{K'}$-action where $K'$ is a $p$-adic field.
Write $K_{\operatorname{LD}}(U(A))$ for the $A$-submodule
$$
B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A)) + \ker(\cup_A)
$$
of $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A))$
where $\cup_A$ is the cup product
$$
\cup_A:Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))\otimes_{\mathcal{O}_E}A \times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))\otimes_{\mathcal{O}_E}A \to C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))\otimes_{\mathcal{O}_E}A.
$$

The Lyndon-Demu\v{s}kin complex
$
C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))
$
is said to be \textit{$\delta$-flat} if
$\dim_{{\mathbb{F}}}K_{\operatorname{LD}}(U({\mathbb{F}})) =\dim_E K_{\operatorname{LD}}(U(E))$.
\vspace{3mm}

\subsubsection{Definition}
\label{def:mildly-regular}
Let $K'$ be a $p$-adic field.
A Lyndon-Demu\v{s}kin action $G_{K'}\to \operatorname{Aut}(U(\mathcal{O}_E))$
is said to be \textit{mildly regular}
if the following are satisfied:
\begin{itemize}
\item[(MR1)] $H^0(G_{K'}, U^{\operatorname{ad}}(E)) = 0$;
\item[(MR2)] The bilinear pairing
$$
\cup_{{\mathbb{F}}}:
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\times
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\to C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))
$$
is non-degenerate.
\end{itemize}

\paragraph{\bf Remark}
In practice $U$ is the unipotent radical of a parabolic subgroup of a reductive group and (MR2) is equivalent to ``$p$ being not too small''.
We worked out the $G_2$-case in Appendix \ref{sec:delta}, and showed that if $p>5$, (MR2) always holds.
The same proof but with more complicated notations should work for general reductive groups.

In general, (MR2) can be checked by computer algebra systems because
it is a finite field vector space question
for a finite number of small $p$'s.
We include an algorithm (written in SageMath) in Appendix \ref{sec:sage}.

The following proposition is a summary of Appendix \ref{sec:delta}:

\vspace{3mm}

\text{\bf Proposition}
\label{prop:summary-appendix}
If $U$ is the unipotent radical of the short root parabolic of $G_2$ or the quotient of the unipotent radical
of the long root parabolic of $G_2$ by its center,
then (MR2) is true when $p\ge 5$.
\vspace{3mm}

\subsubsection{Definition}
\label{def:slightly-less}
Given a tuple of labeled Hodge-Tate weights
$\underline \lambda$,
we say $\underline \lambda$
is slightly less than 0
if for each $\sigma:K\hookrightarrow \bar{\mathbb{Q}}_p$,
$\lambda_{\sigma}$ consists of
non-positive integers,
and for at least one $\sigma$,
$\lambda_\sigma$ consists of negative integers.
(The cyclotomic character has Hodge-Tate weight $-1$.)

\vspace{3mm}
\subsubsection{Proposition}
\label{prop:G2-MR}
Assume $p\ge 5$.
If $U$ is the unipotent radical of the short root parabolic of $G_2$ or the quotient of the unipotent radical
of the long root parabolic of $G_2$ by its center,
then $G_{K'}\to \operatorname{Aut}(U(\mathcal{O}_E))$ is mildly regular
if $U^{\operatorname{ad}}(E)$ is Hodge-Tate of
    labeled Hodge-Tate weights slightly
    less then $0$.

\begin{proof}
If $H^0(G_{K'}, U^{\operatorname{ad}}(E)) \ne 0$,
then for all label $\sigma:K\hookrightarrow \bar{\mathbb{Q}}_p$, $0\in \lambda_\sigma$.

The proposition now follows from
Proposition
\ref{prop:summary-appendix}.
\end{proof}

\subsection{A $\delta$-flatness criterion for Lyndon-Demu\v{s}kin Complexes}~
\vspace{3mm}

The goal of this subsection is to prove:

\subsubsection{Theorem}
\label{thm:delta-criterion}
If the Lyndon-Demu\v{s}kin action $G_{K'} \to \operatorname{Aut}(U(\mathcal{O}_E))$ is mildly regular,
the Lyndon-Demu\v{s}kin complex $C^\bullet_{\operatorname{LD}}(U(\mathcal{O}_E))$
is $\delta$-flat.

\vspace{3mm}

\subsubsection{Generic fiber estimates}

\paragraph{Lemma}
If $H^0(G_{K'}, U^{\operatorname{ad}}(E))=0$,
then $\dim_E B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(E)) = \dim_E U^{\operatorname{ad}}(E)$.

\begin{proof}
Recall $B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(E)) = \operatorname{Im}(d^0: U^{\operatorname{ad}}(E)\to C^1_{\operatorname{LD}}U^{\operatorname{ad}}(E))$, and thus
has dimension at most $\dim_E U^{\operatorname{ad}}(E)$.
If $\dim_E B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(E)) < \dim_E U^{\operatorname{ad}}(E)$,
then $\ker d^0$ is non-trivial, that it, $U^{\operatorname{ad}}(E)$ admits a $G_{K'}$-fixed point.
\end{proof}

\paragraph{Lemma}
\label{lem:char-0-ker-estimate}
If $H^0(G_{K'}, U^{\operatorname{ad}}(E))=0$,
$\dim_E K_{\operatorname{LD}}(U(E)) \ge \dim_E U^{\operatorname{ad}}(E)$.

\begin{proof}
Note that $B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(E))\subset K_{\operatorname{LD}}(U(E))$
by definition.
\end{proof}

\subsubsection{Special fiber estimates}

\paragraph{Lemma}
The image of
$Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E)) \to
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))$
has codimension at most $\dim_{E} U^{\operatorname{ad}}(E)$.

\begin{proof}
Say $\dim_{{\mathbb{F}}} C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))=
\operatorname{rank}_{\mathcal{O}_E}C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))=N$.

Since $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
is the kernel of
$C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))
\to C^2_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$,
and $\operatorname{rank}_{\mathcal{O}_E}C^2_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))=\dim_E U^{\operatorname{ad}}(E)$,
we have
$$
\operatorname{rank}_{\mathcal{O}_E} Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))\ge N-\dim_E U^{\operatorname{ad}}(E).
$$
Since $C^2_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
is torsion-free,
$Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
is saturated in $C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$,
and is thus a direct summand.
In particular,
the image of $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
in $C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))$
has dimension $\ge N-\dim_E U^{\operatorname{ad}}(E)$.
\end{proof}

\paragraph{Lemma}
\label{lem:char-p-ker-estimate}
If
$$
\cup_{{\mathbb{F}}}:
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\times
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))
\to C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))
$$
is non-degenerate, then
the kernel of
$$
\cup_{{\mathbb{F}}}:
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\to C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))
$$
has dimension at most $\dim_E U^{\operatorname{ad}}(E)$.

\vspace{3mm}
\text{\bf Remark}
Note that $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))\ne Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$ in general.

\begin{proof}
For ease of notation, write
$C$ for $C^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))$,
and write
$Z$ for the image of
$Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
in $C$.
Note that $Z\cong Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$ by the proof of the above lemma.

Let $K\subset Z$ be the kernel of $\cup_{{\mathbb{F}}}$.
Since the cup product on $C$ is non-degenerate, $C = Z^{\perp}\oplus Z^{\perp\perp}$, $K\subset Z^{\perp}$,
and $Z = Z^{\perp\perp}\oplus K$.
Since the cup product is non-degenerate
when restricted to both $Z^{\perp}$
and $Z^{\perp\perp}$,
we have $\dim Z^{\perp} \ge 2 \dim K$,
and hence
\begin{eqnarray}
\dim Z &=& \dim K + \dim Z^{\perp\perp}\nonumber\\
&=&\dim K + (\dim C-\dim Z^{\perp})\nonumber\\
&\le& \dim K +\dim C -2\dim K\nonumber\\
&=& \dim C-\dim K\nonumber
\end{eqnarray}
So $\dim K\le \dim C-\dim Z\le \dim_E U^{\operatorname{ad}}(E)$, by the lemma above.
\end{proof}

\subsubsection{Proof of the $\delta$-flatness criterion \ref{thm:delta-criterion}}

\begin{proof}
By Lemma
\ref{lem:char-0-ker-estimate},
we have $\dim_E K_{\operatorname{LD}}(U(E)) \ge \dim_E U^{\operatorname{ad}}(E)$.
By Lemma
\ref{lem:char-p-ker-estimate},
we have $\dim_{{\mathbb{F}}} K_{\operatorname{LD}}(U({\mathbb{F}})) \le \dim_E U^{\operatorname{ad}}(E)$.

Since $C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))$ is torsion-free,
and $K_{\operatorname{LD}}(U(\mathcal{O}_E))\otimes {\mathbb{F}} \subset K_{\operatorname{LD}}(U({\mathbb{F}}))$
we have
$$
\dim_E K_{\operatorname{LD}}(U(\mathcal{O}_E)) \le
\dim_{{\mathbb{F}}} K_{\operatorname{LD}}(U({\mathbb{F}})).
$$
So we are done.
\end{proof}

\subsection{Nontriviality of cup products}~

\paragraph{Theorem}
\label{thm:nontrivial}
Let $K'/K$ be a finite Galois extension of $p$-adic fields of prime-to-$p$ degree.
Let $r :G_K \to \operatorname{Aut}(U(\mathcal{O}_E))$ be a continuous group homomorphism.

If $r|_{G_{K'}}$ is Lyndon-Demu\v{s}kin and mildly regular, then
either
\begin{itemize}
\item
$H^2(G_K, Z(U)({\mathbb{F}})) = 0$;
\item
$H^2(G_K, U^{\operatorname{ad}}({\mathbb{F}})) = 0$; or
\item the symmetric bilinear pairing
$$
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E)) \otimes {\mathbb{F}}
\times
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E)) \otimes {\mathbb{F}}
\to H^2(G_K, Z(U)(\mathcal{O}_E)) \otimes {\mathbb{F}}
$$
is non-trivial.
\end{itemize}

\noindent
\text{\bf Remark}
Note that $H^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E) \cong H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))$, and
$H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))^{G_K}=H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))$.
The symmetric pairing in the theorem
is the restriction to $H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))$
of the symmetric pairing
defined in Lemma \ref{lem:h1-cup}.

\begin{proof}
Assume $H^2(G_K, Z(U)({\mathbb{F}})) \ne 0$
and $H^2(G_K, U^{\operatorname{ad}}({\mathbb{F}})) \ne 0$.
Consider the diagram
$$
\xymatrix{
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))
\times
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))
\ar[r]\ar@{^{(}->}[d] &
H^2(G_K, Z(U)(\mathcal{O}_E))\ar[d]^{\cong}
\\
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))
\times
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))
\ar[r] &
H^2(G_{K'}, Z(U)(\mathcal{O}_E))
\\
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))
\times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))\ar[u]
\ar[r] &
C^2(Z(U)(\mathcal{O}_E))\ar[u]
}
$$
By Lemma \ref{lem:char-p-ker-estimate}, the kernel of
$$
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\times
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\to
H^2(G_{K'}, Z(U)({\mathbb{F}}))
$$
has ${\mathbb{F}}$-dimension at most $\dim_E U^{\operatorname{ad}}(E)$.
Write $\Delta$ for $G_{K}/G_{K'}$, which acts on $H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))$
with fixed-point subspace $H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))$.

By an averaging argument, the kernel
of
$$
H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\times
H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\to
H^2(G_{K}, Z(U)({\mathbb{F}}))
$$
is contained in the kernel of
$$
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\times
H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi
\to
H^2(G_{K'}, Z(U)({\mathbb{F}}))
$$
and thus has ${\mathbb{F}}$-dimension at most $\dim_E U^{\operatorname{ad}}(E)$.
(Let $[c]\in H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$ and suppose
$[c]\cup [d]=0$ for all $[d] \in H^1(G_{K}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$.
Let $[c']\in H^1(G_{K'}, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$.
Then $\sum_{\sigma\in \Delta}\sigma([c]\cup [c'])= [c]\cup \sum_{\sigma\in \Delta}[c'] = 0$.
Since $H^2(G_K, Z(U)({\mathbb{F}})) \ne 0$, we have
$H^2(G_K, Z(U)({\mathbb{F}})) = H^2(G_{K'}, Z(U)({\mathbb{F}}))$ and thus
$\sum_{\sigma\in \Delta}\sigma([c]\cup [c']) = \#\Delta \sigma([c]\cup [c'])$.)

By the local Euler characteristic,
\begin{eqnarray}
\dim_E H^1(G_K, U^{\operatorname{ad}}(E))
&=&
\dim_E H^2(G_K, U^{\operatorname{ad}}(E))
+\dim_E H^0(G_K, U^{\operatorname{ad}}(E))
+ \dim_EU^{\operatorname{ad}}(E)[K:\mathbb{Q}_p]\nonumber\\
&\ge&
\dim_E H^2(G_K, U^{\operatorname{ad}}(E))
+ \dim_EU^{\operatorname{ad}}(E)\nonumber
\end{eqnarray}
Since $H^2(G_K, U^{\operatorname{ad}}({\mathbb{F}}))\ne 0$,
$H^2(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))$ is non-trivial.
So either we have
$\dim_E H^2(G_K, U^{\operatorname{ad}}(E)) > 0$,
or $H^2(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))$
has non-trivial torsion.
If $H^2(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))$
has non-trivial torsion, then
again by the local Euler characteristic (mod $\varpi$ version),
$H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))$
also has non-trivial torsion.
In either case,
$\dim_{{\mathbb{F}}}H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi\ge \dim_EU^{\operatorname{ad}}(E)+1$.
So the kernel of the cup product is a proper subspace of
$H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$.
\end{proof}

The theorem above is used in the following scenerio.

\paragraph{Lemma}
\label{lem:K-primed}
Let $L$ be a split reductive group over ${\mathbb{F}}$.
Let $r:G_K\to L({\mathbb{F}})$ be a Galois representation valued in $L$.
Let $r^{ss}$ be the semi-simplification of $r$.
Write $G_{K'}$ for the kernel of $r^{ss}$.
Then the degree $[K':K]$ divides $(q-1)^r \# W_L$
where
\begin{itemize}
\item $r$ is the rank of $L$,
\item $q$ is a power of $p$, and
\item $\# W_L$ is the cardinality of the Weyl group of $L$.
\end{itemize}

\begin{proof}
By \cite{Lin19}, $r^{ss}$ is tamely ramified and factors through the
normalizer of a maximal torus of $L$ (after possibly extending the base field).
\end{proof}

In particular, if $L=\operatorname{GL}_2$ and $p>3$,
the kernel of $r^{ss}$ defines a Galois extension $K'/K$
of prime-to-$p$ degree;
and $r|_{G_{K'}}$ is Lyndon-Demu\v{s}kin since it has trivial semi-simplification.

\subsection{Obstruction theory for crystalline lifting}
~
\vspace{3mm}

If $\bar\rho(G_K)$ is an irreducible subgroup of
$G(\bar{\mathbb{F}}_p)$ (that is, it is not contained in any proper parabolic subgroup of $G(\bar{\mathbb{F}}_p)$),
then by our previous work \cite{Lin19},
$\bar\rho$ always admits a crystalline lift.
So we assume $\bar\rho$ factors through a
proper maximal parabolic $P$.
Let $P = L\rtimes U_P$ be the Levi decomposition.
Let $\bar r:G_K\to L(\bar{\mathbb{F}}_p)$
be the Levi factor of $\bar\rho$.
Then $\bar\rho$ defines a 1-cocycle
$[\bar c] \in H^1(G_K, U_P(\bar{\mathbb{F}}_p))$.
What we will actually do is to
construct a lift $[c]\in H^1(G_K, U_P(\bar{\mathbb{Z}}_p))$
of $[\bar c]$.

In the $GL_N$-case, all maximal parabolics have abelian unipotent radical, so it
suffices to consider abelian cohomology.
When $G$ is not $GL_N$,
parabolic subgroups with
abelian unipotent radical are rare.
For example, when $G$ is the
exceptional group $G_2$,
all parabolics have non-abelian unipotent radical.

In this paper, we consider the case
where $U_P$ admits a quotient $U$ such that
\begin{itemize}
\item The adjoint group $U^{\operatorname{ad}}:=U/Z(U)$
is abelian, and
\item The center $Z(U)$ is isomorphic to $\mathbb{G}_a$.
\end{itemize}
which turns out to be sufficient when $G$ is
of type $B_l$, $C_l$, $D_l$ or $G_2$.

Let $\operatorname{Spec} R$ be an irreducible component of a crystalline lifting ring $\operatorname{Spec} R^{\operatorname{crys},\underline{\lambda}}_{\bar r}$ (Definition \ref{def:crys-lifting})
of $\bar r$.
Let $r^{\operatorname{univ}}:G_K\to L(R)$
be the universal family.
The Levi factor group acts on $U$
via conjugation
$\phi:L\to\operatorname{Aut}(U)$.
Write
$\phi^{\operatorname{ad}}:L\to\operatorname{GL}(U^{\operatorname{ad}})$
and $\phi^z:L\to\operatorname{GL}(Z(U))$
for the graded pieces of $\phi$.

The theorem we prove is:

\begin{thm}[\ref{thm:heisenberg-lift}]
\label{thm:A}
Let $[\bar c]\in H^1(G_K, U({\mathbb{F}}))$
be a characteristic $p$ cocycle.

Assume
\begin{itemize}
\item[ {[1a]} ]
$H^2(G_K, \phi^{\operatorname{ad}}(r^{\operatorname{univ}}))$ is sufficiently generically regular (Definition \ref{def:sgr});
\item[ {[1b]} ]
$H^2(G_K, \phi^{z}(r^{\operatorname{univ}}))$ is sufficiently generically regular;
\item[ {[2]} ] $p\ne 2$;
\item[ {[3]} ]
There exists a
finite Galois extension $K'/K$ of prime-to-$p$ degree
such that
$\phi(\bar r)|_{G_{K'}}$
is Lyndon-Demu\v{s}kin (Definition \ref{def:ld}); and
\item[ {[4]} ]
There exists a $\bar{\mathbb{Z}}_p$-point
of $\operatorname{Spec} R$ which is mildly regular (Definition \ref{def:mildly-regular})
when restricted to $G_{K'}$.
\end{itemize}
Then there exists a $\bar{\mathbb{Z}}_p$-point of
$\operatorname{Spec} R$ which gives rise to
a Galois representation
$r^{\circ}:G_K\to L(\bar{\mathbb{Z}}_p)$ such that
if we endow $U(\bar{\mathbb{Z}}_p)$ with the
    $G_K$-action
    $G_K\xrightarrow{r^{\circ}} L(\bar{\mathbb{Z}}_p)\xrightarrow{\phi} \operatorname{Aut}(U(\bar{\mathbb{Z}}_p))$,
the cocycle $[\bar c]$ has a characteristic $0$
lift $[c]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$.
\end{thm}

\noindent \text{\bf Remark}
[3] is automatically satisfied if $p$ is sufficiently large;
and [4] is automatically satisfied if $p$ is sufficiently large and the labeled Hodge-Tate weights
$\phi^{\operatorname{ad}}(\underline \lambda)$ are
slightly less then $0$ (Definition \ref{def:slightly-less}).

\subsubsection{Example: $G=\operatorname{GL}_3$}
~

Let $\bar \rho:G_K\to \operatorname{GL}_3(\bar{\mathbb{F}}_p)$
be a completely reducible Galois representation.
There are two ways of encoding the
data of $\bar\rho$ as a $1$-cocycle in
Galois cohomology.

(I) Use the fact $\bar\rho$ factors through
a maximal parabolic
$$
P=
\begin{bmatrix}
* &* &* \\
* &* &*\\
0 &0 &*
\end{bmatrix}
=
\begin{bmatrix}
* &* &0 \\
* &* &0\\
0 &0 &*
\end{bmatrix}
\ltimes
\begin{bmatrix}
1 &0 &* \\
0 &1 &*\\
0 &0 &1
\end{bmatrix}
=L\ltimes A
$$
where $A\cong \mathbb{G}_a^{\oplus 2}$
is a rank-$2$ abelian group.
Let $\bar r:G_K\xrightarrow{\bar\rho}P(\bar{\mathbb{F}}_p)\to L(\bar{\mathbb{F}}_p)$
be the Levi factor of $\bar\rho$.
The information of $\bar\rho$
is encoded in a $1$-cocycle
$[\bar c]\in H^1(G_K, \phi(\bar r))=:H^1(G_K, A(\bar{\mathbb{F}}_p))$.
We first construct a lift $r^{\circ}:G_K\to\operatorname{GL}_2(\bar{\mathbb{Z}}_p)$
of $\bar r$.
Then we construct a lift $[c]\in H^1(G_K, A(\bar{\mathbb{Z}}_p))$ of $[\bar c]$.

(II) Use the fact $\bar\rho$ factors through a Borel
(minimal parabolic)
$$
B=
\begin{bmatrix}
* &* &* \\
0 &* &*\\
0 &0 &*
\end{bmatrix}
=
\begin{bmatrix}
* &0 &0 \\
0 &* &0\\
0 &0 &*
\end{bmatrix}
\ltimes
\begin{bmatrix}
1 &* &* \\
0 &1 &*\\
0 &0 &1
\end{bmatrix}
=T\ltimes H
$$
where the Levi group
$T$ is a maximal torus,
and the unipotent radical
$H$ is the Heisenberg group.
Let $\bar r:G_K\to T(\bar{\mathbb{F}}_p)$
be the Levi factor of $\bar\rho$.
To reconstruct $\bar\rho$
from $\bar r$,
we only need the information
of a $1$-cocycle
$[\bar c]\in H^1(G_K, H(\bar{\mathbb{F}}_p))$.
We first construct a lift of $\bar r$,
and then construct
a lift of $\bar c$.
Now $H^1(G_K, H(\bar{\mathbb{F}}_p))$
is non-abelian Galois cohomology.

We make use of the graded
structure of $\operatorname{Lie} H$ when we
construct a lift of $[\bar c]$.
We have a short exact sequence
$$
1\to
\begin{bmatrix}
1 &0 &* \\
0 &1 &0\\
0 &0 &1
\end{bmatrix}
\to H \to
\begin{bmatrix}
1 &* & \\
0 &1 &*\\
0 &0 &1
\end{bmatrix}
\to 1.
$$
We will first construct a lift
modulo $Z(H)$, and then extend
the lift modulo $Z(H)$
to a cocycle on the whole
unipotent radical $H$.

Theorem \ref{thm:A} applies
in this situation,
so we have a new proof
for the group $\operatorname{GL}_3$.

\begin{comment}
Note that in the $\operatorname{GL}_3$ case,
the assumption [4] of Theorem \ref{thm:A}
(non-triviality of the cup product)
is an immediate consequence of
the Tate local duality.
In general, the Lie-theoretical
structure of $U$ comes into play,
and assumption [4] of Theorem \ref{thm:A}
only holds when $p$
is larger than
Lie structural constants of $U$.

\subsubsection{}
Now we explain the assumptions.

\textbf{[1a], [1b]}:
A coherent sheaf $\mathcal{F}$ over $\operatorname{Spec} R$ is said to be sufficiently generically
regular, if for any integer $s > 0$,
the locus
$\{x\in \operatorname{Spec} R| \dim \kappa(x)\otimes\mathcal{F}_x \ge s\}$
has codimension $\ge (s+1)$ in $\operatorname{Spec} R$.

The onomatology comes from the following application:
if $[C^0\to C^1\xrightarrow{d^2} C^2]$
    is a cochain complex computing
    $H^{\bullet}$, then
    the sheaf $H^2(C^{\bullet})$
    is sufficiently generically regular
    if the differential $d^2$
        is generically very close to being
        full-rank.
The assumption [1a] and [1b]
were first considered in \cite{EG19}.

\textbf{[2]}
We have a short exact sequence of
groups
$0\to Z(U)\to U\to U^{\operatorname{ad}}\to 0$.
Since $Z(U)$ is a central, normal subgroup, we have a long exact sequence of pointed sets
$$
H^1(G_K, Z(U))\to H^1(G_K, U)\to H^1(G_K, U^{\operatorname{ad}})\xrightarrow{\delta} H^2(G_K, Z(U)).
$$
Note that $\delta$ is \textit{not}
a group homomorphism!
In general, $\delta$ is a (non-linear)
polynomial map.
We will choose suitable cochain complexes
$C^{\bullet}$
computing Galois cohomology such that
the boundary map can be upgraded
to a map on the cocycle group level:
$$
Z^1(G_K, U^{\operatorname{ad}}(R)) \xrightarrow{\delta}
C^2(G_K, Z(U)(R))
$$
where $Z^1:= \ker (C^1\to C^2)$.
The assumption [2] of Theorem \ref{thm:A}
is demanding $\delta$ to be flat over $\operatorname{Spec} R$.

\subsubsection{}
The assumptions [2] and [4]
are difficult to check in general.
However, there is a special case when
these things can be checked via
explict computations,
namely, the Lyndon-Demu\v{s}kin case.

Let $A$ be a $\bar{\mathbb{Z}}_p$-algebra.
A Galois representation
$\bar r:G_K\to L(A)$
is said to be Lyndon-Demu\v{s}kin
if
\begin{itemize}
\item $K$ contains the group $\mu_p$
of p-th root of unity, and
\item
The image $\bar r(G_K)\subset L(A)$
is a pro-$p$ group.
\end{itemize}

When $\bar r$ is Lyndon-Demu\v{s}kin,
$\bar r:G_K \to L(A)$
factors through the Demu\v{s}kin
group, which has explicit generators
and relations.
The result of Lyndon \cite{Ly50}
constructs an explicit minimal
cochain complex
$[C^0_{\operatorname{LD}}\to C^1_{\operatorname{LD}}\to C^2_{\operatorname{LD}}]$
computing
$H^{\bullet}(G_K, \bar r)$.
In particular, we are able to explicity
write down the polynomial defining
the boundary map $\delta$, and
prove its flatness.

In the general case,
we can choose a finite Galois,
prime-to-$p$ extension $K'/K$
such that
$
\bar r|_{G_K'}
$
is Lyndon-Demu\v{s}kin.
The observation is,
when the boundary map $\delta$ is
non-trivial,
the only cohomological obstruction
comes from the pro-$p$ part of
the Galois group.
We have the following obstruction theory:

\begin{thm}
\label{thm:B}
Let $E/\mathbb{Q}_p$ be a finite extension
with ring of integers $\mathcal{O}_E$,
and residue field ${\mathbb{F}}$.
The quotient $U\to U^{\operatorname{ad}}$
induces a map $\operatorname{ad}:H^1(G_K, U(\mathcal{O}_E))\to H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))$.
Assume
\begin{itemize}
\item
$C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$
is $\delta$-flat;
\item
$p\ne 2$;
\item
the cup product
$$
\cup:
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))
\times
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))
\to H^2(G_K, Z(U)(\mathcal{O}_E))
$$
is non-trivial.
\end{itemize}
Let $[\bar c]\in H^1(G_K,U({\mathbb{F}}))$ be a characteristic $p$ cocycle.
If
$[\operatorname{ad}(\bar c)|_{G_{K'}}]\in H^1(G_{K'}, U^{\operatorname{ad}}({\mathbb{F}}))$ admits
a characteristic $0$ lift,
then $[\bar c]$
 admits a characteristic $0$
 lift
 $[c]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$.
\end{thm}
\end{comment}

\subsubsection{}
We have a short exact sequence of
groups
$0\to Z(U)\to U\to U^{\operatorname{ad}}\to 0$.
Since $Z(U)$ is a central, normal subgroup, we have a long exact sequence of pointed sets
$$
H^1(G_K, Z(U))\to H^1(G_K, U)\to H^1(G_K, U^{\operatorname{ad}})\xrightarrow{\delta} H^2(G_K, Z(U)).
$$
Note that $\delta$ is a quadratic form, and
there is an associated
bilinear form
$$
\cup: H^1(G_K, U^{\operatorname{ad}}) \times H^1(G_K, U^{\operatorname{ad}})
\to H^2(G_K, Z(U))
$$
defined by $x\cup y = (\delta(x+y)-\delta(x)-\delta(y))/2$.

The technical heart of this paper is an analysis of $\cup$
on the cochain/cocycle level.
So we need a finite cochain complex computing
Galois cohomology which interacts nicely with
the bilinear form $\cup$.
Thanks to the theory of Demu\v{s}kin groups,
there is an explicitly defined cochain complex
(the so-called Lyndon-Demu\v{s}kin complex)
which computes $H^\bullet(G_{K'},U^{\operatorname{ad}})$
and $H^\bullet(G_{K'},Z(U))$
after a finite Galois extension $K'/K$.
When $[K':K]$ is prime to $p$,
we can fully understand cup products
on the cochain/cocycle level
via Lyndon-Demu\v{s}kin complexes
endowed with $G_K/G_{K'}$-action.

We have the following nice obstruction theory:

\begin{thm} [\ref{cor:obstruction-theory}]
\label{thm:B}
Assume $p\ne 2$.
Let $L$ be a reductive group over $\mathcal{O}_E$ and fix
an algebraic group homomorphism $L\to\operatorname{Aut}(U)$.
Let $r :G_K \to L(\mathcal{O}_E)$ be a Galois representation.

If there exists a
finite Galois extension $K'/K$ of prime-to-$p$ degree
such that
$r|_{G_{K'}}$ is Lyndon-Demu\v{s}kin and mildly regular, then
either
\begin{itemize}
\item[(I)]
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta} H^2(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))
$$
where $\delta$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p}
H^1(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{F}}_p)) \to
H^2(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$, or
\item[(II)]
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta'} H^2(G_{K}, Z(U)(\bar{\mathbb{Z}}_p))
$$
where $\delta'$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p'}
H^1(G_{K}, Z(U)(\bar{\mathbb{F}}_p)) \to
H^2(G_{K}, Z(U)(\bar{\mathbb{Z}}_p))$.
\end{itemize}
\end{thm}

\vspace{3mm}

\subsection{The existence of crystalline lifts for
$G_2$}~
\vspace{3mm}

The exceptional group $G_2$
has (up to conjugacy) two maximal parabolics:
the short root parabolic,
and the long root parabolic.
When $\bar\rho:G_K\to G_2(\bar{\mathbb{F}}_p)$
factors through the short root parabolic,
we can directly apply Theorem \ref{thm:A}
to construct a crystalline lift
of $\bar\rho$.
When $\bar\rho:G_K\to G_2(\bar{\mathbb{F}}_p)$
factors through the long root parabolic,
we can apply Theorem \ref{thm:A}
to construct a lift modulo the
center of the unipotent radical $U$.
If we assume furthermore
that
$\bar\rho$ does not factor through the
short root parabolic,
then by Tate local duality,
$H^2(G_K, Z(U)({\mathbb{F}}))=0$,
and it is unobstructed to extend
the lift to the whole unipotent radical.
Putting everything together, we have
the following theorem:

\begin{thm} [\ref{thm:existence-crys-lift-G2}]
\label{thm:C}
Assume $p>3$.
Every mod $\varpi$ Galois representation
valued in the exceptional group $G_2$
$$
\bar\rho:G_K\to G_2(\bar{\mathbb{F}}_p)
$$
admits a crystalline lift
$\rho^{\circ}:G_K\to G_2(\bar{\mathbb{Z}}_p)$.

Moreover, if $\bar\rho$ factors through
a maximal parabolic $P=L\ltimes U$
and the Levi factor $\bar r_{\bar\rho}:G_K\to L(\bar{\mathbb{F}}_p)$ of $\bar\rho$
admits a Hodge-Tate regular and crystalline lift $r_1:G_K\to L(\bar{\mathbb{Z}}_p)$ such that
the adjoint representation $G_K \xrightarrow{r_1} L(\bar{\mathbb{Z}}_p) \to \operatorname{GL}(\operatorname{Lie} (U(\bar{\mathbb{Z}}_p)))$ has Hodge-Tate weights
slightly less than $\underline 0$,
then $\rho^{\circ}$ can be chosen such that it factors through
the maximal parabolic $P$ and its Levi factor $r_{\rho^{\circ}}$
lies on the same irreducible component of the spectrum of the crystalline
lifting ring that $r_1$ does.
\end{thm}
~

We remark that the ``moreover'' part of Theorem \ref{thm:C}
fails when $p=3$.
It is possible to construct an explicit counterexample using
Jannsen-Wingberg theory.

~

\subsection{Crystalline lifting for classical groups}
\label{par:classical-groups}
~
\vspace{3mm}

Our obstruction theory is sufficient
for constructing crystalline lifts
of mod $\varpi$ representations valued in classical groups.

A maximal parabolic $P$ of a (split) classical group $G=G(V, \langle, \rangle)$
of type $B_l$, $C_l$ or $D_l$
is the stablizer of an isotropic subspace $F\subset V$.

Let $U$ be the unipotent radical of $P$.
The Levi factor $L$ of $P$ acts on $U$ by conjugation.
Let $\lambda$ be the similitude character of $G$.
Fix an isomorphism
$\iota:F\cong F^{\perp\perp}/F$
such that $\langle x,\iota(x) \rangle=1$ for all $x$.
Then $\iota \otimes \lambda^{-1}$
is $L$-equivariant.

It is easy to see $U^{\operatorname{ad}}:=U/Z(U)$ is abelian, and there
exists an $L$-equivariant isomorphism
$$Z(U)=\operatorname{Hom}_{\text{Vector space scheme}}(F, F^{\perp\perp}/F) \otimes \lambda^{-1}.$$

Note that $\iota$ induces an abelian group scheme
morphism $\operatorname{tr}_\iota: Z(U) \to \mathbb{G}_a\otimes \lambda^{-1}$
which is $L$-equivariant.
The quotient group $(U/\ker \operatorname{tr}_\iota)$
is a Heisenberg group, and thus our obstruction theory applies to it.

Let $\bar \rho:G_K\to P({\mathbb{F}})$ be a mod $\varpi$
Galois representation with Levi factor
$\bar r:G_K \to L({\mathbb{F}})$.
We only need to consider the case where
$\bar\rho$ is irreducible when restricted to the
isotropic subspace $F$
(otherwise replace $F$ by a smaller isotropic subspace).
In this case, $\operatorname{tr}_\iota$ induces an isomorphism
$$
H^2(G_K, Z(U)({\mathbb{F}})) \cong H^2(G_K, \lambda^{-1}\otimes{\mathbb{F}})
$$
by Schur's lemma and local Tate duality.
By the long exact sequence of Galois cohomology,
for any crystalline lift $r^{\circ}:G_K\to L(\bar{\mathbb{Z}}_p)$ of $\bar r$, we have
$$
H^2(G_K, U(\bar{\mathbb{Z}}_p)) \cong H^2(G_K, (U/\ker\operatorname{tr}_{\iota})(\bar{\mathbb{Z}}_p)).
$$
and thus the existence of crystalline lifts of $\bar\rho$
is equivalent to the existence of crystalline lifts
of $\bar\rho$ modulo $\ker \operatorname{tr}_\iota$
by the main theorem of \cite{Lin21}.
We call $(P/\ker \operatorname{tr}_\iota)$ the \textit{Heisenberg quotient} of $P$.

So Theorem (\ref{thm:A}) and Theorem (\ref{thm:B})
suffice for classical groups.
To establish the existence of crystalline lifts
of mod $\varpi$ representations valued in
classical groups, we only need to establish
a codimension estimate on the moduli stack
of $(\phi, \Gamma)$-modules valued
in classical groups in the manner of section \ref{sec:codim}.
Our method requires $p$ to be greater than
the cardinality of the Weyl groups
of proper Levi subgroups of $G$
(due to Lemma \ref{lem:K-primed}, although the assumption on $p$ can possibly be
relaxed by Jannsen-Wingberg theory).

\begin{thm}
Let $G$ be a split classical group of type $B_l$, $C_l$
or $D_l$.
The existence of crystalline lifts for $G$
follows from the the existence of crystalline lifts
of Galois representations valued
in the Heisenberg quotients of maximal parabolics of $G$.
\end{thm}

\begin{proof}
Combine \cite{Lin19} and the discussion above.
\end{proof}

The moduli stack of \'etale $\phi$-modules
for general reductive groups is constructed in
\cite{Lin21B}.
The moduli stack of $(\phi,\Gamma)$-modules
has not been constructed yet.
The author has verified codimension estimates
for many small rank groups (for example $\operatorname{GSp}_4$ and $\operatorname{GSp}_6$).

\vspace{3mm}

\subsection{Towards general reductive groups}
To resolve the most general case, one has to analyze the integral structure
of higher Massey products.
We hope to come back at this in a future work.

~

\subsection{Organization}

In section \ref{sec:LD}, we review
the results of Lyndon and Demu\v{s}kin
and establish some notations.

Section \ref{sec:FC}
and Section \ref{sec:manipulate}
form the technical heart of this paper.

Section \ref{sec:MACHINE}
and Section \ref{sec:codim}
are mild generalizations of results
from \cite{EG19}.
The proof is almost unchanged and
we often just sketch the ideas of the proof
and invite the readers to look at the proofs
of \cite{EG19}.

We prove the main theorem in Section \ref{sec:main}.

\begin{comment}
\vspace{3mm}

We believe Theorem \ref{thm:A}
can be applied to construct
crystalline lifts of mod $\varpi$
Galois representations
valued in $\operatorname{GSp}_{2N}$,
$\operatorname{GO}(N,N)$ or $\operatorname{GO}(N,N+1)$,
which factors through the Klingen
parabolic.

If we unwrap all the technical
aspects of
Theorem \ref{thm:A},
we'll find at the very heart of
Theorem \ref{thm:A}
the following simple linear algebra fact:

\begin{quotation}
Assume we have the following
vectoriel equation in $\overrightarrow{x}$:
$$
\overrightarrow{a}^T \overrightarrow{x}
+ \overrightarrow{x}^{T} Q
\overrightarrow{x} = 0
$$
where $\overrightarrow{x}\in \bar{\mathbb{Z}}_p^{\oplus N}$ is a $\bar{\mathbb{Z}}_p$-valued $N$-dimensional vector,
$\overrightarrow{a}^T$ is a linear functional,
and $Q$ is a quadratic form.
The a mod $\varpi$ solution
admits a characteristic $0$ lift
if either
\begin{itemize}
\item
    $\overrightarrow{a}\ne 0$ mod $\varpi$, or
\item
    $Q$ is flat.
\end{itemize}
\end{quotation}
If we want to consider a general
nilpotent group of class $2$,
essentially we need to answer
the following linear algebra question:
given a system of vectoriel equations

$$
\left\{
\begin{matrix}
\overrightarrow{a}_1^T \overrightarrow{x}
+ \overrightarrow{x}^{T} Q_1
\overrightarrow{x} &=& 0 \\
\overrightarrow{a}_2^T \overrightarrow{x}
+ \overrightarrow{x}^{T} Q_2
\overrightarrow{x} &=& 0 \\
\dots & = & 0 \\
\overrightarrow{a}_M^T \overrightarrow{x}
+ \overrightarrow{x}^{T} Q_M
\overrightarrow{x} &=& 0
\end{matrix}
\right.
$$
or equivalently, a matrix equation
$$
A \overrightarrow{x} + f_Q(\overrightarrow{x})=0
$$
where $A$ is an $M\times N$ matrix,
and $f_Q$ is a vector-valued, homogeneous
quadratic function,
when does a characteristic $p$
solution lift?

\end{comment}

\subsubsection{Theorem}
Let $G_K(p)$ be the maximal pro-$p$ quotient
of $G_K$. Then $G_K(p)$
is the pro-$p$ completion of the
following one-relator group
$$
\langle x_0,\cdots,x_{n+1}|{x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}\rangle
$$
where $n=[K:\mathbb{Q}_p]$, and $q=p^s$ is the largest power of $p$
such that $K$ contains the $q$-th roots of unity.

\subsubsection{Definition}
\label{def:ld}
A continuous $G_K$-module $A$ is
said to be \textit{Lyndon-Demu\v{s}kin}
if the image of $G_K\to\operatorname{Aut}(A)$
    is a pro-$p$ group.

\subsection{Comparing cohomology of Demu\v{s}kin groups
and Galois cohomology}~

\vspace{3mm}

Let $\Gamma^{\operatorname{disc}}$
be the discrete group
with one relator
$$
\langle
x_0, \dots, x_n, x_{n+1}|{x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}
\rangle.
$$

Let $K/\mathbb{Q}_p$ be a $p$-adic field
containing the group of $p$-th root of
 unity.
Let $A$ be a Lyndon-Demu\v{s}kin $G_K$-module.
Write $H^{\bullet}(\Gamma^{\operatorname{disc}}, A)$
for the usual group cohomology,
and write
$H^{\bullet}(G_K, A)$
for the continuous profinite cohomology.

Note that there is a functorial map
$$
\text{($\dagger$)}\hspace{2mm}H^{\bullet}(G_K, A) \to H^{\bullet}(\Gamma^{\operatorname{disc}}, A)
$$
induced from the forgetful functor
$\operatorname{Mod}_{\operatorname{cont}}(G_K(p))\to \operatorname{Mod}(\Gamma^{\operatorname{disc}})$.

\subsubsection{Lemma}
Let ${\mathbb{F}}_p$ be the $G_K$-module with
trivial $G_K$-action.
Then
($\dagger$) induces isomorphisms:

(1) $H^1(G_K, {\mathbb{F}}_p)=H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)$;

(2) $H^2(G_K, {\mathbb{F}}_p)=H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)$;

\begin{proof}
(1)
We have
$$H^1(G_K, {\mathbb{F}}_p) = \operatorname{Hom}_{\operatorname{cont}}(G_K, {\mathbb{F}}_p);$$
$$H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)=
\operatorname{Hom}(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p).$$
Since $H^1(G_K, {\mathbb{F}}_p)$ classifies continuous extension classes of two trivial $G_K$-modules, ($\dagger$) is injective.
By local Euler characteristic,
$\dim H^1(G_K, {\mathbb{F}})=[K:\mathbb{Q}_p]+\dim H^0(G_K, {\mathbb{F}})+\dim H^2(G_K, {\mathbb{F}})=n+2
=\dim H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}})$.
So ($\dagger$) is an isomorphism.

(2)
We have a commutative diagram
$$
\xymatrix{
    H^1(G_K, {\mathbb{F}}_p)
    \times H^1(G_K, {\mathbb{F}}_p)
    \ar@<-6ex>[d]
    \ar@<+9ex>[d]\ar[r]^{\hspace{9mm}\cup}
    &
    H^2(G_K, {\mathbb{F}}_p)\ar[d]\\
    H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)
    \times H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)
    \ar[r]^{\hspace{9mm}\cup}
    &
    H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)
}
$$
Note that the first row
is a non-degenerate pairing,
and $H^2(G_K, {\mathbb{F}})\cong {\mathbb{F}}$
by local Tate duality.
By Lyndon's theorem or
Corollary \ref{cor:h2-disc},
we have $H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}})\cong {\mathbb{F}}$.
So it remains to show the cup product
of the second row is non-trivial.
Let $[c_1], [c_2]\in H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)$.
$[c_1]\cup[c_2] = 0$ if and only
if there exists a group homomorphism
    $$
    \Gamma^{\operatorname{disc}}\to
\begin{bmatrix}
1 & c_1 & * \\
 & 1 & c_2 \\
 & & 1
\end{bmatrix}
    $$
    for some $*$.
        Define $c_i:\Gamma^{\operatorname{disc}}\to{\mathbb{F}}_p$ by sending $x_i$ to $1$ and other generators to $0$, $i=0,1$.
        Then it is clear $[c_1]\cup[c_2]\ne 0$.
\end{proof}

\subsubsection{Corollary}
Let $A$ be a finite ${\mathbb{F}}_p$-vector
space endowed with
Lyndon-Demu\v{s}kin $G_K$-action.
Then there is a canonical isomorphism
$H^{\bullet}(G_K, A) = H^{\bullet}(\Gamma^{\operatorname{disc}}, A)$.

\begin{proof}
Let $G_K(p)$ be the maximal pro-$p$
quotient of $G_K$.
Then $A$ is a $G_K(p)$-module.
Since $G_K(p)$ is a pro-$p$ group,
$A$ must contain the trivial representation ${\mathbb{F}}_p$.
In particular, there is a short exact sequence
$$
0\to {\mathbb{F}}_p\to A \to A'\to 0
$$
which induces the long exact sequence
$$
\xymatrix{
H^0(G_K, A')\ar[r]\ar[d]&
H^1(G_K, {\mathbb{F}}_p) \ar[r]\ar[d]&
H^1(G_K, A) \ar[r]\ar[d]&
H^1(G_K, A') \ar[r]\ar[d]&
H^2(G_K, {\mathbb{F}}_p) \ar[d]\\
H^0(\Gamma^{\operatorname{disc}}, A')\ar[r]&
H^1(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p) \ar[r]&
H^1(\Gamma^{\operatorname{disc}}, A) \ar[r]&
H^1(\Gamma^{\operatorname{disc}}, A') \ar[r]&
H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)\\
}
$$
We apply induction on the length
of $A$.
By the Five Lemma, we have
$H^1(G_K, A)=H^1(\Gamma^{\operatorname{disc}}, A)$.

We also have the long exact sequence
$$
\xymatrix{
H^1(G_K, A')\ar[r]\ar[d]&
H^2(G_K, {\mathbb{F}}_p) \ar[r]\ar[d]&
H^2(G_K, A) \ar[r]\ar[d]&
H^2(G_K, A') \ar[r]\ar[d]&
H^3(G_K, {\mathbb{F}}_p) \ar[d]\\
H^1(\Gamma^{\operatorname{disc}}, A')\ar[r]&
H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p) \ar[r]&
H^2(\Gamma^{\operatorname{disc}}, A) \ar[r]&
H^2(\Gamma^{\operatorname{disc}}, A') \ar[r]&
H^3(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)\\
}
$$
By Lyndon's theorem,
$H^3(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)=0$.
By local Tate duality,
$H^3(G_K, {\mathbb{F}}_p)=0$.
Again by the Five Lemma, we have
$H^2(G_K, A)=H^2(\Gamma^{\operatorname{disc}}, A)$.
\end{proof}

By induction on the order of $A$,
($\dagger$) is an isomorphism for
any finite $p$-power torsion group $A$.

\subsubsection{Corollary}
\label{cor:cont-disc}
Let $A$ be a finite ${\mathbb{Z}}_p$-module
endowed with Lyndon-Demu\v{s}kin $G_K$-action.
Then there is a canonical isomorphism
$
H^{\bullet}(G_K, A)=H^{\bullet}(\Gamma^{\operatorname{disc}}, A)
$.

\begin{proof}
We have a short exact sequence
for each $k>0$,
$$0\to \invlim{i}^1H^{k-1}(G_K, A/p^i A)
\to H^k(G, A)\to \invlim{i} H^k(G_K, A/p^iA)\to 0.$$
The first term
is $0$ due to the finiteness
of the cohomology of
torsion $G_K$-modules.
So $H^k(G_K, A)=\invlim{i}H^k(G_K, A/p^iA)$,
and the corollary is reduced to the $p$-power torsion case.

We can do the same thing for
the discrete cohomology.
Since any finite ${\mathbb{Z}}_p$-module
is $p$-adically complete,
the Lyndon-Demu\v{s}kin complex
(see the last subsection of Section \ref{sec:LD})
computing
$H^{\bullet}(\Gamma^{\operatorname{disc}}, A)$
is the inverse limit
of the Lyndon-Dem\"iskin complex
mod $p^i$.
So $H^k(\Gamma^{\operatorname{disc}}, A)=\invlim{i}H^k(\Gamma^{\operatorname{disc}}, A/p^i)$.
\end{proof}

The lemma above tells us that,
for our purposes, the cohomology groups of $G_K(p)$
can be computed via the discrete model.
So we can make use of the fine machineries of
combinatorial group theory.

\subsection{Discrete group cohomology of Demu\v{s}kin groups} ~

\vspace{3mm}

The main reference of this subsection is \cite{Ly50}.

\vspace{3mm}

\paragraph{Derivations}

A derivation of a group $G$ is a left $G$-module $M$,
together with a map
$D: G\to M$ such that $D(uv) = Du+uDv$.

Say $F$ is a free group with generators $x_1$,\dots $x_m$.
Denote by $dFJ$ the module of universal derivations.
Then $dFJ$ is the free $\mathbb{Z}[F]$-module
with basis $\{dx_i|i=1,\dots,m\}$.

Let $u\in F$.
We can write $du\in dFJ$ as a linear combination of the basis elements:
$
du = \sum \frac{\partial u}{\partial x_i}
dx_i
$
where $\frac{\partial u}{\partial x_i}\in \mathbb{Z}[F]$.

\vspace{3mm}

\paragraph{Theorem} (Lyndon)
Let $
G = \langle x_1,\dots,x_m | R \rangle
$ be a one-relator group
where $R=Q^q$ for no $q>1$.
Let $K$ be any left $G$-module. Then
$$
H^2(G,K) \cong
K/ (\frac{\partial R}{\partial x_1},\dots
\frac{\partial R}{\partial x_m})K
$$
and
$
H^n(G,K) = 0
$
for all $n>2$.

\vspace{3mm}

\paragraph{Corollary}
\label{cor:h2-disc}
We have
$H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)={\mathbb{F}}_p$.

\begin{proof}
We have the following computation:
\begin{eqnarray}
\frac{\partial R}{\partial x_0}
&=&
1+x_0+\cdots+x_0^{q-2} + x_0^{q-1}x_1^{-1}
\nonumber\\
\frac{\partial R}{\partial x_1}
&=&
x_0^{q-1}x_1^{-1}(x_0-1)
\nonumber\\
\frac{\partial R}{\partial x_2}
&=&
x_0^q(x_0,x_1)x_2^{-1}(x_3-1)
\nonumber\\
\frac{\partial R}{\partial x_3}
&=&
x_0^q(x_0,x_1)x_2^{-1}x_3^{-1}(x_2-1)
\nonumber\\
\vdots& & \vdots\nonumber\\
\frac{\partial R}{\partial x_{2k}}
&=&
x_0^q(x_0,x_1)\cdots(x_{2k-2},x_{2k-1})
x_{2k}^{-1}(x_{2k+1}-1)
\nonumber\\
\frac{\partial R}{\partial x_{2k+1}}
&=&
x_0^q(x_0,x_1)\cdots(x_{2k-2},x_{2k-1})
x_{2k}^{-1}x_{2k+1}^{-1}(x_{2k}-1)
\nonumber\\
\vdots&& \vdots\nonumber
\end{eqnarray}

Since
$H^2(\Gamma^{\operatorname{disc}}, {\mathbb{F}}_p)=
\frac{{\mathbb{F}}_p}{(\partial R/\partial x_0, \cdots, \partial R/x_{n+1})}$,
it suffices to show
$$
\frac{\partial R}{\partial x_0}{\mathbb{F}}_p=\dots=
\frac{\partial R}{\partial x_{n+1}}{\mathbb{F}}_p=0.
$$
Since ${\mathbb{F}}_p$ is a trivial $G_K$-module,
it is clear
$\frac{\partial R}{\partial x_1}{\mathbb{F}}_p=\dots
\frac{\partial R}{\partial x_{n+1}}{\mathbb{F}}_p
=0$.
We also have
$
\frac{\partial R}{\partial x_0}=
1+1+\cdots+1=q=0
$ mod $p$.
\end{proof}

\subsubsection{Proposition}
\label{prop:coh}
Let $A$ be a $G_K$-module
whose underlying abelian group
is a finitely generated $\mathbb{Z}_p$-module such that
the image of $G_K$ in $\operatorname{Aut}(A)$ is a pro-$p$ group.
Then
$$
H^2(G_K,A)\cong
A/ (\frac{\partial R}{\partial x_0},\dots,
\frac{\partial R}{\partial x_{n+1}})A
$$
where
$
R =
{x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}
$.

\begin{proof}
Combine Lemma \ref{cor:cont-disc} and Lyndon's theorem.
\end{proof}

\vspace{3mm}

\subsection{Lyndon-Demu\v{s}kin Complex}~
\label{ss:LDC}

\subsubsection{Abelian coefficient case}
Let $A$ be a $G_K$-module
whose underlying abelian group
is a finitely generated $\mathbb{Z}_p$-module such that
the the image of $G_K$ in $\operatorname{Aut}(A)$ is a pro-$p$ group.

Then there is an explicit co-chain complex
computing the Galois cohomology $H^{\bullet}(G_K,A)$.

Define
$C^{\bullet}_{\operatorname{LD}}(A)
=
[C^0_{\operatorname{LD}}(A)\xrightarrow{d^1} C^1_{\operatorname{LD}}(A)
\xrightarrow{d^2} C^2_{\operatorname{LD}}(A)]$
as
the following cochain complex supported
on degrees [0,2]
$$
A \xrightarrow{
\begin{bmatrix}
1-x_0\\
\dots\\
1-x_{n+1} \\
\end{bmatrix}
}
A^{\oplus (n+2)} \xrightarrow{
\begin{bmatrix}
\partial R/\partial x_0\\
\dots\\
\partial R/\partial x_{n+1}\\
\end{bmatrix}^{T}
}A.
$$

Then by \cite{Ly50}
$$
H^{\bullet}(C^{\bullet}_{LD}(A))
=H^{\bullet}(G_K, A).
$$

The idea of Lyndon Demu\v{s}kin
complex is simple.
A $1$-cochain $c\in C^1_{\operatorname{LD}}(A)$
is simply a set-theoretical function
$$
c: \{x_0, \dots, x_{n+1}\}
\to A.
$$
We can extend $c$ to be a function
on the free group
$$
c:\langle x_0, \dots, x_{n+1}\rangle
\to A
$$
by setting
$c(gh):=c(g)+g\cdot c(h)$
for any $g,h$ in the free group
    with $(n+2)$ generators.
Let
$$
R={x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}
$$
be the single relation defining the
Demu\v{s}kin group.
The differential operator
$d^2:C^1_{\operatorname{LD}}(A)\to C^2_{\operatorname{LD}}(A)$
is nothing but the evaluation of the
extended map $c$ at the relation $R$,
that is,
$d^2(c) = c(R)$.
So a $1$-cochain $c$ is a $1$-cocycle
if and only if its evaluation at
    $R$ is $0$.

\subsubsection{Nilpotent coefficients}

Let $E/\mathbb{Q}_p$ be a finite extension
with ring of integers $\mathcal{O}_E$,
residue field ${\mathbb{F}}$, and uniformizer $\varpi$.

Let $U$ be a nilpotent  (smooth connected) linear algebraic group
over $\operatorname{Spec} \mathcal{O}_E$.
Write
$$
{1} = U_0 \subset U_1 \cdots \subset U_k
= U
$$
for the upper central series of $U$.

Assume $p>k$.
There is a canonical isomorphism of
schemes
$
U \cong \operatorname{Lie} U
$
sending $g\mapsto \log g$.
To define the logarithm function,
it is convenient to choose
an embedding $U\hookrightarrow{\operatorname{GL}_N}$,
and define $\log$ using the commutative diagram
$$
\xymatrix{
    U\ar[d]\ar[r] & \operatorname{GL}_N \ar[d]^{\log}\\
    \operatorname{Lie} U \ar[r] & \operatorname{Mat}_{N\times N}
}
$$

We assume $k=2$ from now on
because it suffices for our applications.

Fix a Galois action
$G_K\to \operatorname{Aut}(U(\mathcal{O}_E))$
such that the image group is a pro-$p$
subgroup of $\operatorname{Aut}(U(\mathcal{O}_E))$.

Let $A$ be an $\mathcal{O}_E$-algebra.
Recall that a \textit{non-abelian crossed homomorphism} valued in $U(A)$
is a map $c:G_K\to U(A)$ such that
$$
c(gh) = c(g)(g\cdot c(h))
$$
for all $g,h\in G_K$.
Set $\mathfrak{c}:=\log (c): G_K \to \operatorname{Lie} U(A)$.
By the Baker-Campbell-Hausdorff formula,
$$
\text{($\dagger$)}\hspace{5mm}\mathfrak{c}(gh) = \mathfrak{c}(g) +
g\cdot \mathfrak{c}(h) + \frac{1}{2}[
\mathfrak{c}(g), g\cdot\mathfrak{c}(h)].
$$
Our definition
of the Lyndon-Demu\v{s}kin cochain complex
is motivated by ($\dagger$).

\vspace{3mm}

\paragraph{Definition}
Let $A$ be an $\mathcal{O}_E$-algebra.
The Lyndon-Demu\v{s}kin complex with nilpotent coefficients is defined to be the following cochain complex
$C_{\operatorname{LD}}^{\bullet}(U(A))$
supported on degrees [0,2]:
$$
\operatorname{Lie} U(A) \xrightarrow{d^1} (\operatorname{Lie} U(A))^{\oplus n+2}
\xrightarrow{d^2} \operatorname{Lie} U(A)
$$
where $d^1$ is defined by
$$
d^1(v)
= (-v + x_i\cdot v + \frac{1}{2}[-v, x_i\cdot v])_{i=0,\ldots,n+1}.
$$
We need some preparations
before we define $d^2$.
An element
$c = (\alpha_0, \cdots, \alpha_{n+1})\in C^1_{\operatorname{LD}}(U(A))$
can be regarded as a function on the free group with $(n+2)$ generators
$$
c: \langle x_0, \cdots, x_{n+1} \rangle \to \operatorname{Lie} U(A)
$$ by setting $c(x_i)=\alpha_i$ for each $i$
and extending it to the whole free group
by
$$c(gh):=c(g)+g\cdot c(h)+\frac{1}{2}[c(g), g\cdot c(h)]$$
We define $d^2$ as
$$
d^2 (c):= c(R) = c({x_0^q(x_0,x_1)(x_2,x_3)\dots(x_n,x_{n+1})}).
$$

\paragraph{Remark}
\label{rem:ld-underlying-group}
(1)
When $U$ is an abelian group,
then we recover the definition
in the previous section;

(2)
The main reason we define $C^{\bullet}_{\operatorname{LD}}(U(A))$ this way
is because we want to compare it with
$C^{\bullet}_{\operatorname{LD}}(\operatorname{Lie} U(A))$.

Note that
$C^{\bullet}_{\operatorname{LD}}(\operatorname{Lie} U(A))$
and
$C^{\bullet}_{\operatorname{LD}}(U(A))$
have the same underlying group,
but their differential $d^{\bullet}$
is different.

(3) Note that $d^2(c) = 0$
if and only if $c$ defines a crossed homomorphism $\mathfrak{c}:G_K\to \operatorname{Lie} U(A)$
    in the sense of ($\dagger$).

(4) The differential maps are generally non-linear.

\vspace{3mm}

\paragraph{Definition}
We define $Z_{\operatorname{LD}}^{i}:=(d^i)^{-1}(0)$,
and $B_{\operatorname{LD}}^i := d^i(C_{\operatorname{LD}}^{i-1})$ for $i=0,1,2$.

\vspace{3mm}
\paragraph{Proposition}
We have $$H^0(G_K, U)\cong Z^0_{\operatorname{LD}}(U(A))$$
and a surjection of pointed sets
$$
Z^1_{\operatorname{LD}}(U(A)) \to H^1(G_K, U(A)).
$$

\begin{proof}
Immediate from definitions.
\end{proof}

\vspace{3mm}

$\operatorname{Lie} U$ has a lower central series
filtration.
Let $Z(U)$ be the center of $U$.
Write $U^{\operatorname{ad}}$ for $U/Z(U)$.
Since $U$ is nilpotent of class $2$,
$U$ is isomporphic to its graded
Lie algebra
$\operatorname{Lie} U\cong \operatorname{gr}^{\bullet}(\operatorname{Lie} U)$.
We will fix a grading
$\operatorname{Lie} U \cong Z(U) \oplus U^{\operatorname{ad}}$
of the Lie algebra $\operatorname{Lie} U$
once for all.
In particular, we fixed
a projection
$\operatorname{pr}:\operatorname{Lie} U \to Z(U)$.

\subsubsection{Cup products}

Let $c\in C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A))$.
Let $\widetilde{c} \in C^1_{\operatorname{LD}}(U(A))$
be the (unique) lift of $c$ such that
$
\operatorname{pr}(\widetilde{c}(x_0))=\dots
\operatorname{pr}(\widetilde{c}(x_{n+1}))=
0$.
Define $$Q(c):= \operatorname{pr}(d^2(\widetilde{c}))
=\operatorname{pr}(\widetilde{c}(R))
\in C^2_{\operatorname{LD}}(Z(U)(A)).$$

It is not hard to see
$Q(-)$ is a quadratic form
(we fully expand $\widetilde{c}(R)$
using the Baker-Campbell-Hausdorff formula,
and only keep the terms which are Lie brackets).

We define
\begin{eqnarray}
C_{\operatorname{LD}}^1(U^{\operatorname{ad}}(A))\times
C_{\operatorname{LD}}^1(U^{\operatorname{ad}}(A)) &\xrightarrow{\cup}&
C_{\operatorname{LD}}^2(Z(U)(A))\nonumber\\
x\cup y &:= & \frac{1}{2}(Q(x+y)-Q(x)-Q(y))\nonumber
\end{eqnarray}
which is a symmetric bilinear form.

\noindent
\text{\bf Remark}
Alternatively, we can choose an arbitrary lift
$\widetilde{c}$ of $c$.
Now $\operatorname{pr}(d^2(\widetilde{c}))$ is an inhomogeneous
polynomial of degree two.
We recover $Q$ by taking the homogeneous part
of degree two.

\vspace{3mm}

\paragraph{Lemma}
\label{lem:non-abelian-h1}
Under the
 identification
 $
 C^1_{\operatorname{LD}}(U(A))=
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A)) \oplus C^1_{\operatorname{LD}}(Z(U)(A))
$, we have
$$
Z^1_{\operatorname{LD}}(U(A)) =
\{(x, y)\in
C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A)) \oplus C^1_{\operatorname{LD}}(Z(U)(A))|
d^2x = 0,~x\cup x + d^2 y = 0
\}.
$$

\begin{proof}
It is obvious from the definition
of $d^2$
and $Q$.
The projection of $d^2(x,y)$ to $C^1_{\operatorname{LD}}(U^{\operatorname{ad}}(A))$ is $d^2x$; and
the projection of $d^2(x,y)$ to $C^1_{\operatorname{LD}}(Z(U)(A))$ is $x\cup x + d^2y$.
\end{proof}

Write $H^1_{\operatorname{LD}}(U^{\operatorname{ad}})(A)$
for $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})(A)/B^1_{\operatorname{LD}}(U^{\operatorname{ad}})(A)$.
    \vspace{3mm}

\paragraph{Lemma}
\label{lem:h1-cup}
The pairing $\cup$ on the cochain level
induces a symmetric pairing on the cohomology level
\begin{eqnarray}
H_{\operatorname{LD}}^1(U^{\operatorname{ad}}(A))\times
H_{\operatorname{LD}}^1(U^{\operatorname{ad}}(A)) &\xrightarrow{\cup}&
H_{\operatorname{LD}}^2(Z(U)(A)).\nonumber
\end{eqnarray}

\begin{proof}
It suffices to show for all
$x\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})(A)$
and $y\in B^1_{\operatorname{LD}}(U^{\operatorname{ad}})(A)$,
$Q(x+y)-Q(x)\in B^2_{\operatorname{LD}}(Z(U)(A))$.

Let $\widetilde{x}\in C^1_{\operatorname{LD}}(U(A))$
be the unique extension of $x$
such that $\operatorname{pr} \widetilde{x}= 0$.
The cocycle $\widetilde{x}$
represents a group homomorphism
$\rho_{\widetilde{x}}: \langle x_0,\cdots,x_{n+1}\rangle \to U(A)\rtimes \langle x_0,\cdots,x_{n+1}|R\rangle$
such that $\rho_{\widetilde{x}}(R)=1$ mod $Z(U)(A)$.
There exists $n\in U(A)$
such that
$n \rho_{\widetilde{x}} n^{-1}$
is represented by a cocycle $(x+y,f)$ extending $x+y$.
We have
$n \rho_{\widetilde{x}}(R) n^{-1} \rho_{\widetilde{x}}(R)^{-1}=1\in U(A)\rtimes \langle x_0,\cdots,x_{n+1}|R\rangle$
since $\rho_{\widetilde{x}}(R)$ lies in the center of $U(A)$.
Since $Q(x+y)-d^2(f)=n \rho_{\widetilde{x}}(R) n^{-1}$
and $Q(x)=\rho_{\widetilde{x}}(R)$,
we have $Q(x+y)-Q(x)=d^2f\in B^2_{\operatorname{LD}}(Z(U)(A))$.
\end{proof}

\vspace{3mm}
Recall $Z^1_{\operatorname{LD}}(U(A))$ and
$Z^1_{\operatorname{LD}}(\operatorname{Lie} U(A))$ are both subsets of $C^1_{\operatorname{LD}}(U(A))$.
\paragraph{Lemma}
\label{lem:incl-into-lie-u}
If $Z(U)({\mathbb{F}})\cong {\mathbb{F}}$, then
$$
Z^1_{\operatorname{LD}}(U({\mathbb{F}})) \subset
Z^1_{\operatorname{LD}}(\operatorname{Lie} U({\mathbb{F}}))
$$
that is, the non-abelian cocycles
with $U({\mathbb{F}})$-coefficients
are automatically
abelian cocycles with $(\operatorname{Lie} U({\mathbb{F}}))$-coefficients.

\begin{proof}
We have remarked in \ref{rem:ld-underlying-group}(2) that
$C^1_{\operatorname{LD}}(U({\mathbb{F}}))$ and $C^1_{\operatorname{LD}}(\operatorname{Lie} U({\mathbb{F}}))$
have the same underlying space.
By Lemma
\ref{lem:non-abelian-h1},
an element of $Z^1_{\operatorname{LD}}(U({\mathbb{F}}))$
is a pair $(x,y)$ such that $d^2x=0$
and $x\cup x+d^2 y = 0$.
By our assumption,
$C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}})) = H^2(G_K, Z(U)({\mathbb{F}}))$
and thus $B^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))=0$.
So $d^2y=0$ automatically,
and $(x,y)$ defines an element
of $Z^1_{\operatorname{LD}}(\operatorname{Lie} U({\mathbb{F}}))$.
\end{proof}

\subsubsection{Crystalline lifting rings}
\label{def:crys-lifting}
Let $L$ be a connected reductive group over $\mathcal{O}_E$,
and $\bar r : G_K \to L({\mathbb{F}})$ be a mod $\varpi$
representation.
Let $\underline{\lambda}$ be a Hodge type.
The crystalline lifting ring $R^{\operatorname{crys}, \underline{\lambda},\mathcal{O}}_{\bar r}$
of $\bar r$ of $p$-adic Hodge type $\underline{\lambda}$
is constructed in \cite[Theorem 3.3.8]{BG19}.
It is an $\mathcal{O}$-flat quotient of the universal lifting ring,
and has generic fiber equidimensional of dimension $\dim_E L + \dim_E \operatorname{Res}_{K\otimes E/K} L/P_{\underline\lambda}$
where $P_{\underline\lambda}$ is the parabolic subgroup determined by the $p$-adic Hodge type $\underline{\lambda}$.
If $\underline{\lambda}$ is a regular $p$-adic Hodge type, $P_{\underline\lambda}$
is a Borel subgroup.

\vspace{3mm}

\subsection{A geometric argument of
Emerton-Gee}~

\subsubsection{Definition}
\label{def:sgr}
Let $\mathcal{F}$ be a coherent sheaf
over a scheme $X$.
We say $\mathcal{F}$ is \textit{sufficiently generically regular}
(= SGR) if for each $s \ge 0$,
the locus
$$
X_s := \{x\in \operatorname{Spec} R|\dim \kappa(x)\otimes_R \mathcal{F} \ge s\}
$$
has codimension $\ge s+1$ in $\operatorname{Spec} R$.

\vspace{3mm}

\subsubsection{Theorem}
\label{thm:abelian-lift}
Let $X=\operatorname{Spec} R$ be an irreducible component of a crystalline lifting ring of $\bar r$.
Let $r^{\operatorname{univ}}:G_K\to L(R)$
be the universal family of Galois representations on
$X$.
Assume $X[1/p] \ne \emptyset$.
Let $F:L \to \operatorname{GL}(V)$ be an algebraic representation
where $V$ is a vector space scheme over $\mathcal{O}_E$.

Assume $H^2(G_K, F(r^{\operatorname{univ}}))$ is SGR.
Given any $[\bar {c}]\in H^1(G_K, F(\bar r))$,
there exists a
$\bar{\mathbb{Z}}_p$-point of $X$ giving rise
to a Galois representation
$r^{\circ}: G_K \to L(\bar{\mathbb{Z}}_p)$,
such that
the 1-cocycle $[\bar {{c}}]$
admits a lift
$[{c}] \in H^1(G_K, F(r^{\circ}))$.

\begin{proof}
The proof is almost identical to
that of \cite[Theorem 6.3.2]{EG19}.

Instead of repeating their argument,
we would like to explain the main ideas
behind the proof, and why we need
the sufficiently generically regular
condition.

We have a complex of finitely generated
projective modules concentrated on degree
[0, 2]
$$
C^0\to C^1\xrightarrow{d} C^2
$$
which computes the Galois cohomology
$H^{\bullet}(G_K, F(r^{\operatorname{univ}}))$.
Let $Z^1 := \ker (d)$ and $B^2:= \operatorname{Im}(d)$.
A mod $\varpi$ cocycle $[\bar c]$
is represented by an element $\bar c$ in the
kernel of $C^1/\varpi \to C^2/\varpi$.
We fix an arbitrary lift
$\widetilde{c}\in C^1$ of $\bar c$.
We can do a formal blowup
$\operatorname{Spec} \widetilde{R}\to\operatorname{Spec} R$,
so that the pull-back of
$B^2$ on $\operatorname{Spec} \widetilde{R}$
a locally free sheaf.
To make the exposition short,
we simply assume $B^2$ is locally free
over $\operatorname{Spec} R$,
but we should not think of $\operatorname{Spec} R$
as a local ring anymore,
because after formal blow-up, there are more points in the special fiber.
Now we have a sequence of locally free sheaf of modules
$$
C^1\to B^2 \to C^2.
$$
The key here is we want to regard this
as a sequence of vector bundles
instead of sheaf of modules.
Write $\mathscr{V}(\mathcal{F})$
for $\underline{\operatorname{Spec}}(\operatorname{Sym}\mathcal{F}^{\vee})$, the vector bundle associated
    to the coherent sheaf $\mathcal{F}$.
So we have a sequence of scheme morphisms
$$
\begin{tikzcd}
\mathscr{V}(C^1)\arrow{r}{f}\arrow[bend left=20]{rr}{d}
&
\mathscr{V}(B^2)\arrow{r}
&
\mathscr{V}(C^2)
\\&\operatorname{Spec} R \arrow{lu}{s}\arrow{u}{f\circ s}\arrow{ur}{d\circ s}&
\end{tikzcd}
$$
The element $\widetilde{c}$ of $C^1$ defines
a section
$s:\operatorname{Spec} R\to \mathscr{V}(C^1)$
such that
the section $d\circ s:\operatorname{Spec} R\to \mathscr{V}(C^2)$
intersects with the identity section
$e_{\mathscr{V}(C^2)}:\operatorname{Spec} R\to \mathscr{V}(C^2)$.

It turns out $\bar c\in \ker(C^1/\varpi\to C^2/\varpi)$ admits a lift
in $Z^1$, as long as the section
$f\circ s$ intersects with
the identity section $e_{\mathscr{V}(B^2)}$ of
$\mathscr{V}(B^2)$.
The intersection $(d\circ s)\cap e_{\mathscr{V}(C^2)}$ should
occur above a codimension $1$ locus
of $\operatorname{Spec} R$.
If the support of $H^2=C^2/B^2$ is
small (that is, has big codimension),
then the intersection should
happen at some point $x\in\operatorname{Spec} R$
outside of the support of $H^2$,
and we are done.
Of course, we oversimplified
the situation, see \cite{EG19}
for a complete account.
\end{proof}

\subsection{A non-abelian lifting theorem}
~

\subsubsection{Theorem}
\label{thm:heisenberg-lift}
Let $U$ be a nilpotent linear algebraic group of class $2$
whose center is isomorphic to $\mathbb{G}_a$.
Write $Z(U)$ for the center of $U$ and $U^{\operatorname{ad}}$
for $U/Z(U)$.
Fix an algebraic group homomorphism
$\phi:L \to \operatorname{Aut}(U)$ with graded pieces
$\phi^{\operatorname{ad}}: L\to \operatorname{GL}(U^{\operatorname{ad}})$
and $\phi^z: L \to \operatorname{GL}(Z(U))$.

Fix a mod $\varpi$ representation $\bar r:G_K \to L({\mathbb{F}})$.
Let $[\bar c]\in H^1(G_K, U({\mathbb{F}}))$
be a characteristic $p$ cocycle.

Let $\operatorname{Spec} R$ be an irreducible component of a crystalline lifting ring of $\bar r$.

Assume
\begin{itemize}
\item[ {[1a]} ]
$H^2(G_K, \phi^{\operatorname{ad}}(r^{\operatorname{univ}}))$ is SGR;
\item[ {[1b]} ]
$H^2(G_K, \phi^{z}(r^{\operatorname{univ}}))$ is SGR;
\item[ {[2]} ] $p\ne 2$;
\item[ {[3]} ]
There exists a
finite Galois extension $K'/K$ of prime-to-$p$ degree
such that
$\phi(\bar r)|_{G_{K'}}$
is Lyndon-Demu\v{s}kin; and
\item[ {[4]} ]
There exists a $\bar{\mathbb{Z}}_p$-point
of $\operatorname{Spec} R$ which is mildly regular
when restricted to $G_{K'}$.
(In particular, $\operatorname{Spec} R[1/p]\ne 0$.)

\end{itemize}
Then there exists a $\bar{\mathbb{Z}}_p$-point of
$\operatorname{Spec} R$ which gives rise to
a Galois representation
$r^{\circ}:G_K\to L(\bar{\mathbb{Z}}_p)$ such that
if we endow $U(\bar{\mathbb{Z}}_p)$ with the
$G_K$-action
$G_K\xrightarrow{r^{\circ}} L(\bar{\mathbb{Z}}_p)\xrightarrow{\phi} \operatorname{Aut}(U(\bar{\mathbb{Z}}_p))$,
the cocycle $[\bar c]$ has a characteristic $0$
lift $[c]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$.

\begin{proof}
Combine
Theorem \ref{thm:abelian-lift}
and Corollary \ref{cor:obstruction-theory}.
\end{proof}

We explain how the above theorem will be used.
Let $G$ be a connected reductive group over
$\mathcal{O}_E$.
Let $\bar\rho: G_K\to G({\mathbb{F}})$
be a mod $\varpi$ representation.
Assume $\bar\rho$ factors through
a parabolic $P\subset G$, with
Levi decomposition $P = L\ltimes U$.
Denote by
$\phi:L\to \operatorname{Aut}(U)$ the conjugation action.
We assume $U$ is nilpotent of
class $2$,
so $U^{\operatorname{ad}}$ is an abelian group.
Write
$\bar r$ for the Levi factor of $\bar\rho$.
$$
\xymatrix{
    & P(\bar{\mathbb{F}}_p) \ar[d] \\
     G_K \ar[ur]^{\bar\rho}
    \ar[r]^{\bar r} & L(\bar{\mathbb{F}}_p)
}
$$
Then $\bar\rho$ defines a cohomology class
$[\bar c]\in H^1(G_K, \phi(\bar r))$,
and the theorem above can be used to lift
$[\bar c]$.

\vspace{3mm}

\subsection{An unobstructed lifting theorem}
~

The following result will be used
in the proof of the main theorem.

\subsubsection{Proposition}
\label{prop:unob-lift}
Let $V$ be a unipotent linear algebraic group such that
$V(\bar{\mathbb{Z}}_p)$ is equipped with a continuous $G_K$-action.
Let $[\bar c]\in H^1(G_K, V(\bar{\mathbb{F}}_p))$
be a characteristic $p$ cocycle.
Let $Z(V)$ be the center of $V$,
and write $V^{\operatorname{ad}}$ for $V/Z(V)$.
The quotient $V\to V^{\operatorname{ad}}$ induces
a map $\operatorname{ad}:H^1(G_K, V)\to H^1(G_K, V^{\operatorname{ad}})$.
Assume
$H^2(G_K, Z(V)(\bar{\mathbb{F}}_p))=0$.

If $\operatorname{ad}([\bar c])$ admits a lift
in $H^1(G_K, V^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$,
then $[\bar c]$ admits a lift in
$H^1(G_K, V(\bar{\mathbb{Z}}_p))$.

\begin{proof}
By \cite[Proposition 43]{Se02},
since $Z(V)$ is a central normal subgroup
of $V$, there exists a long exact sequence
of pointed sets
$$
\xymatrix{
H^1(G_K, V(\bar{\mathbb{Z}}_p))
\ar[d]\ar[r]^{\operatorname{ad}} &
H^1(G_K, V^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))
\ar[r]^{\delta}\ar[d] &
H^2(G_K, Z(V)(\bar{\mathbb{Z}}_p)) \ar[d] \\
H^1(G_K, V(\bar{\mathbb{F}}_p)
\ar[r]^{\operatorname{ad}} &
H^1(G_K, V^{\operatorname{ad}}(\bar{\mathbb{F}}_p))\ar[r] &
H^2(G_K, Z(V)(\bar{\mathbb{F}}_p))
}
$$
By Nakayama's Lemma, we have
$H^2(G_K, Z(V)(\bar{\mathbb{Z}}_p))=0$.
In particular, there exists
$[c']\in H^1(G_K, V(\bar{\mathbb{Z}}_p)$
such that $\operatorname{ad}([\bar c]) = \operatorname{ad}([c'])$
mod $\varpi$.
Write $[\bar {c}']$ for $[c']$ mod $\varpi$.
Say $[\bar c] = [\bar {c}'] + [\bar f]$
for some $[\bar f]\in H^1(G_K, Z(V)(\bar{\mathbb{F}}_p))$
    (recall that $H^1(G_K, V)$ is a $H^1(G_K, Z(V))$-torsor).
Since $H^1(G_K, Z(V)(\bar{\mathbb{Z}}_p))=0$,
there exists a lift $[f]$ of $\bar f$.
The cocycle $[c]:= [c'] + [f]$
is a lift of $[\bar c]$.
\end{proof}

\subsection{Theorem}
\label{thm:existence-crys-lift-G2}
Assume $p > 3$.
Let $K/\mathbb{Q}_p$ be a $p$-adic field.
Let $\bar\rho:G_K\to G_2(\bar{\mathbb{F}}_p)$
be a mod $\varpi$ Galois representation.
Then $\bar\rho$ admits
a crystalline lift
$
\rho^{\circ}:G_K\to G_2(\bar{\mathbb{Z}}_p)
$
of $\bar\rho$.

Moreover, if $\bar\rho$ factors through
a maximal parabolic and the Levi factor $\bar r_{\bar\rho}$ of $\bar\rho$
admits a Hodge-Tate regular and crystalline lift $r_1$ such that
the adjoint representation $\phi^{\operatorname{Lie}}(r_1)$ has Hodge-Tate weights
slightly less than $\underline 0$,
then $\rho^{\circ}$ can be chosen such that it factors through
the same maximal parabolic and its Levi factor $r_{\rho^{\circ}}$
lies on the same irreducible component of the spectrum of the crystalline
lifting ring that $r_1$ does.

\begin{proof}

If $\bar\rho$ is irreducible, then
$\bar\rho$ admits a crystalline lift
by \cite{Lin19}.

The exceptional group $G_2$ has two maximal
parabolic subgroups: the short root parabolic,
and the long root parabolic.

If $\bar\rho$ is reducible, then it factors through either parabolic subgroups.

\subsubsection{The short root parabolic case}
\label{case:short-root}
~
\vspace{3mm}

Let $P\subset G_2$ be the short root parabolic.
Recall that $P$ has a Levi decomposition
$P = L \ltimes U$.
Fix an isomorphism
$L\cong \operatorname{GL}_2$.

By Lemma \ref{lem:K-primed},
there exists a finite Galois extension
$K'/K$, of prime-to-p degree
such that $\bar r|_{K'}$ is Lyndon-Demu\v{s}kin.

Write $Z(U)$ for center of $U$,
and write $U^{\operatorname{ad}}$ for $U/Z(U)$.
Write $\phi:L\to\operatorname{Aut}(U)$ for the conjugation action,
with graded pieces
$\phi^{\operatorname{ad}}:L\to \operatorname{GL}(U^{\operatorname{ad}})$
and $\phi^{z}:L\to\operatorname{GL}(Z(U))$.
Write $\phi^{\operatorname{Lie}}$ for $\phi^{\operatorname{ad}}\oplus \phi^{z}$.
\vspace{3mm}

\paragraph{Lemma}
\label{lem:lift-r0}
Assume $p>2$.
There exists a Hodge-Tate regular crystalline lifting
$r^{\circ}: G_K\to L(\bar{\mathbb{Z}}_p)$
of the Levi factor $\bar r$,
such that
the adoint representation
$
\phi^{\operatorname{Lie}}(r^\circ):
G_K\xrightarrow{r^{\circ}}
L(\bar{\mathbb{Z}}_p)
\to \operatorname{GL}(\operatorname{Lie} U(\bar{\mathbb{Z}}_p))
$
has labeled Hodge-Tate weights
slightly less that $\underline{0}$.

\begin{proof}
It is well-known Hodge-Tate regular crystalline lifts of $\bar r$ exists.
We have
$\phi^{\operatorname{Lie}}(r^\circ) = \frac{1}{{\det r^\circ}^2}\operatorname{sym}^3(r^\circ) \oplus
\frac{1}{\det r^\circ}$.
So by replacing $r^\circ$ by a Tate twist,
we can ensure $\phi^{\operatorname{Lie}}(r^\circ)$ labeled Hodge-Tate weights
slightly less that $\underline{0}$.

\begin{comment}
If $\bar r$ is reducible,
we write $\bar r$ as an extension $1 \to \bar \chi_1 \to \bar r \to \chi_2 \to 1$.
By choosing suitable crystalline liftings $\chi^\circ_i$
of $\bar\chi_i$,
we can and do choose $r^\circ$ by lifing the extension:
$1 \to \chi_1^\circ \to r^\circ \to\chi_2^\circ \to 1$.
(See, for example, \cite[Theorem 6.3.2]{EG19}.)

If $\bar r$ is irreducible,
we write $\bar r$ as an induction of a character $\operatorname{Ind}_{G_{K_2}}^{G_K}\bar \chi$ where $K_2/K$ is the unramified extension of degree two.
By choosing a crystalline lift $\chi^\circ$
of $\bar \chi$,
we set $r^\circ=\operatorname{Ind}_{G_{K_2}}^{G_K} \chi^\circ$.
For consistency of notation, write $\chi_1^\circ$
for $\chi^\circ$, and write $\chi_2^\circ$ for $\sigma(\chi^\circ)$ where $\sigma$ is the non-trivial involution
in $\operatorname{Gal}(K_2/K)$.

In either case, $r^\circ|_{G_{K'}}$ is an extension of characters $\chi_1^\circ$ and $\chi_2^\circ$.

To show (ii), it suffices to
\begin{itemize}
\item[(1)] $\chi_1^\circ$ has infinite image,
\item[(2)] $\chi_2^\circ$ has infinite image,
\item[(3)] $\chi_1^{\circ 2}\chi_2^{\circ-1}$ has infinite image, and
\item[(4)] $\chi_2^{\circ 2}\chi_1^{\circ-1}$ has infinite image.
\end{itemize}
In the reducible case, the choice of both $\chi^\circ_1$ and $\chi^\circ_2$ is flexible and it is trivial
to guarantee (1234).
In the irreducible case,
(1) is equivalent to (2), and (3) is equivalent to (4).
Since $\chi_1 = \sigma(\chi_2)$ where $\sigma$ is the non-trivial involution
in $\operatorname{Gal}(K_2/K)$,
$\chi_1^{\circ 2}\chi_2^{\circ-1}$ has finite image
implies $\chi_1^{\circ 3}$ has finite image.
So it suffices to ensure $\chi_1^{\circ 3}$ has infinite image.
We only need to do Tate twist because the
cyclotomic character has infinite image.
\end{comment}
\end{proof}

Let $\operatorname{Spec} R$ be an irreducible component (with non-empty generic fiber)
of a crystalline lifting
ring $R^{\operatorname{crys},\underline{\lambda}}_{\bar r}$
of regular labeled Hodge-Tate weights $\underline \lambda$
such that
the labeled Hodge-Tate weights $\phi^{\operatorname{Lie}}(\underline{\lambda})$ are
slightly less 0.
By the lemma above, such a $\operatorname{Spec} R$ exists.

Let $r^{\operatorname{univ}}:G_K \to L(R)$
be the universal Galois representation.

The mod $\varpi$ Galois
representation $\bar r$ defines
a Galois action $\phi(\bar r):G_K\to \operatorname{Aut}(U(\bar{\mathbb{F}}_p))$ on $U(\bar{\mathbb{F}}_p)$.
By \ref{par:non-ab-h1},
the datum of $\bar \rho:G_K \to G_2(\bar{\mathbb{F}}_p)$
is encoded in a non-abelian cocycle
$[\bar c]\in H^1(G_K, U(\bar{\mathbb{F}}_p))$.

The strategy for lifting $\bar\rho$
is as follows.
We choose a suitable $\bar{\mathbb{Z}}_p$-point
$x$ of $\operatorname{Spec} R$ which defines
a lift $r_x:G_K\to L(\bar{\mathbb{Z}}_p)$
of $\bar r$, and endow $U(\bar{\mathbb{Z}}_p)$
with the Galois action
$\phi(r_x):G_K\xrightarrow{r_x}L(\bar{\mathbb{Z}}_p)
\to \operatorname{Aut}(U(\bar{\mathbb{Z}}_p))$.
There is a map of pointed set
$
H^1(G_K, U(\bar{\mathbb{Z}}_p)) \to H^1(G_K, U(\bar{\mathbb{F}}_p))
$.
If the cohomology class $[\bar c]$
admits a lift $[c]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$,
then $\bar\rho$ admits
a lift $\rho:G_K\to G_2(\bar{\mathbb{Z}}_p)$ whose datum is encoded in $[c]$.
Such a lift $\rho$ is crystalline by the main result of \cite{Lin21},
since $\phi^{\operatorname{Lie}}(r^\circ)$ has labeled Hodge-Tate weights
slightly less than $\underline{0}$.

By Theorem \ref{thm:heisenberg-lift},
to lift the non-abelian 1-cocycle $[\bar c]$,
it suffices to verify the following:
\begin{itemize}
\item[ {[1a]} ]
$H^2(G_K, \operatorname{sym}^3(r^{\operatorname{univ}})/\det^2(r^{\operatorname{univ}}))$ is SGR;
\item[ {[1b]} ]
$H^2(G_K, 1/\det(r^{\operatorname{univ}}))$ is SGR;
\item[ {[2]} ] $p\ne 2$;
\item[ {[3]} ]
There exists a
finite Galois extension $K'/K$ of prime-tp-$p$ degree
such that
$\phi(\bar r)|_{G_{K'}}$
is Lyndon-Demu\v{s}kin; and
\item[ {[4]} ]
There exists a $\bar{\mathbb{Z}}_p$-point
of $\operatorname{Spec} R$ which is mildly regular
when restricted to $G_{K'}$.
\end{itemize}
\vspace{3mm}

[1a, 1b] is verified by Theorem \ref{thm:codim-ad}.
Note that since the Hodge type of $\operatorname{Spec} R$ is chosen so that
$\operatorname{sym}^3(r_x)/\det(r_x)^2$
has labeled Hodge-Tate weights
slightly less than $\underline{0}$,
$H^2(G_K, \operatorname{sym}^3(r_x)/\det(r_x)^2)$
is torsion for any characteristic $0$
point $x$ of $\operatorname{Spec} R$.
[3] follows from Lemma \ref{lem:K-primed},
and [4] follows from Proposition \ref{prop:G2-MR}.

\vspace{3mm}

\subsubsection{The long root parabolic case}
~
\vspace{3mm}

Let $Q\subset G_2$ be the long root parabolic.
$Q$ has a Levi decomposition
$Q=L'\ltimes V$.
Fix an isomorphism $\operatorname{std}:L'\xrightarrow{\cong}\operatorname{GL}_2$.
Write $\det$ for the composition
$L'\xrightarrow{\operatorname{std}} \operatorname{GL}_2 \xrightarrow{\det}\operatorname{GL}_1$.

Let $\{1\}=V_0\subset V_1\subset V_2\subset V_3=V$ be the upper central series of
$V$.
Then the conjugation action of $L'$
on each graded piece is given by
\begin{itemize}
\item $V_3/V_2 \cong \det\otimes \operatorname{std}$;
\item $V_2/V_1 \cong \det$;
\item $V_1 \cong \operatorname{std}$.
\end{itemize}

Suppose $\bar\rho$ factors through the
long root parabolic $Q$, but not
the short root parabolic $P$.
Then the Levi factor
$$
\bar r: G_K\xrightarrow{\bar\rho}Q(\bar{\mathbb{F}}_p)
\to L'(\bar{\mathbb{F}}_p)
$$
is necessarily an irreducible representation.
If we endow each graded piece of $V(\bar{\mathbb{F}}_p)$
with the Galois action
$G_K\xrightarrow{\bar r}L(\bar{\mathbb{Z}}_p)\to \operatorname{GL}(V_{i+1}(\bar{\mathbb{F}}_p)/V_i(\bar{\mathbb{F}}_p))$, then we have,
by local Tate duality,
$$
H^2(G_K, V_3(\bar{\mathbb{F}}_p)/V_2(\bar{\mathbb{F}}_p))
=H^2(G_K, \bar r \otimes \det \bar r)=0
$$
$$
H^2(G_K, V_1(\bar{\mathbb{F}}_p))
=H^2(G_K, \bar r)=0
$$
So the only cohomological obstruction
occurs in the second graded piece.

The datum of $\bar \rho$
is encoded in a non-abelian cocycle
$[\bar c]\in H^1(G_K, V(\bar{\mathbb{F}}_p))$.
Just as is done in the short root parabolic case, it suffices to lift the cocycle
$[\bar c]$.
By Proposition \ref{prop:unob-lift},
since the only cohomological obstruction
lies in the second graded piece, it suffices to lift
$\operatorname{ad}([\bar c]) \in H^1(G_K, (V/V_1)(\bar{\mathbb{F}}_p))$.

Write $U'$ for $V/V_1$.
Recall that $U'$ is a nilpotent group of class $2$
with rank-$1$ center, and we can directly
appeal to Theorem \ref{thm:heisenberg-lift}.
We repeat the procedure worked out
in the short root case \ref{case:short-root}.

Let $r^\circ$ be a lift of $\bar r$ such that $r^\circ$
is Hodge-Tate regular and crystalline and the Hodge-Tate weights of $r^\circ$
are strictly less than $\underline{0}$.

Let $\operatorname{Spec} R$ be the irreducible component of the crystalline lifting ring
of $\bar r$ containing $r^\circ$.
Write $r^{\operatorname{univ}}:G_K \to \operatorname{GL}_2(R)$ for the universal family.

Write $Z(U')$ for the center of $U'$, and
write $U^{'\operatorname{ad}}$ for $U'/Z(U')$.
Write $\phi^{\operatorname{ad}}$ for the conjugate action $L'\to \operatorname{Aut}(U^{'\operatorname{ad}})$
and write $\phi^{z}$ for the conjugate action $L' \to \operatorname{Aut}(Z(U'))$.

Note that $\phi^{\operatorname{ad}}(r^{\operatorname{univ}}) = r^{\operatorname{univ}}$
and $\phi^{z}(r^{\operatorname{univ}}) = \det r^{\operatorname{univ}}$.

We have the following check list:
\begin{itemize}
\item[ {[1a]} ]
$H^2(G_K, r^{\operatorname{univ}})$ is SGR;
\item[ {[1b]} ]
$H^2(G_K, 1/\det(r^{\operatorname{univ}}))$ is SGR;
\item[ {[2]} ] $p\ne 2$;
\item[ {[3]} ]
There exists a
finite Galois extension $K'/K$ of prime-tp-$p$ degree
such that
$\phi(\bar r)|_{G_{K'}}$
is Lyndon-Demu\v{s}kin; and
\item[ {[4]} ]
There exists a $\bar{\mathbb{Z}}_p$-point
of $\operatorname{Spec} R$ which is mildly regular
when restricted to $G_{K'}$.
\end{itemize}
[1a] is \cite[Theorem 6.1.1]{EG19}.
[1b] is Theorem \ref{thm:codim-z}.
[3] follows from Lemma \ref{lem:K-primed},
and [4] follows from Proposition \ref{prop:G2-MR}.
\end{proof}

\subsection{Parabolics of $G_2$}~

Let $G_2$ be the
Chevalley group over $\mathcal{O}_E$
of type $G_2$.

Let $E/\mathbb{Q}_p$ be a finite extension
with ring of integers $\mathcal{O}_E$,
residue field ${\mathbb{F}}$ and uniformizer
$\varpi$.

We remind the reader of the root
system of $G_2$:
\begin{center}
\begin{tikzpicture}
    \foreach\ang in {60,120,...,360}{
     \draw[->,blue!80!black,thick] (0,0) -- (\ang:2cm);
    }
    \foreach\ang in {30,90,...,330}{
     \draw[->,blue!80!black,thick] (0,0) -- (\ang:3cm);
    }
    \draw[magenta,->](1,0) arc(0:150:1cm)node[pos=0.1,right,scale=0.5]{$5\pi/6$};
    \node[anchor=south west,scale=0.6] at (2,0) {$\alpha$};
    \node[anchor=south west,scale=0.6] at (-2.9,1.6) {$\beta$};
    \node[anchor=south west,scale=0.6] at (-.9,1.6) {$\beta+\alpha$};
    \node[anchor=south west,scale=0.6] at (.9,1.6) {$\beta+2\alpha$};
    \node[anchor=south west,scale=0.6] at (2.5,1.6) {$\beta+3\alpha$};
    \node[anchor=south west,scale=0.6] at (0.2,2.8) {$2\beta+3\alpha$};
    \node[anchor=north,scale=0.6] at (0.7,-3.2) {\huge Root system of $G_{2}$};
  \end{tikzpicture}
\end{center}

\subsubsection{The short root parabolic}

Let $P\subset G_2$ be the short root parabolic,
which admits a Levi decomposition
$P=L\ltimes U$.
The Levi factor $L$ is a copy of $\operatorname{GL}_2$
and the unipotent radical $U$ is a nilpotent group of class $2$.
Write $U^{\operatorname{ad}}$ for $U/Z(U)$.

Fix an isomorphism $\operatorname{std}:L\cong \operatorname{GL}_2$.
We have
\begin{itemize}
\item $Z(U)\cong \mathbb{G}_a$, and
\item $U^{\operatorname{ad}}\cong \mathbb{G}_a^{\oplus 4}$.
\end{itemize}
Write $\operatorname{Lie} U = Z(U)\oplus U^{\operatorname{ad}}$.
The Levi factor acts on $U$ by conjugation.
We have an isomorphism of $L$-modules
$$
\operatorname{Lie} U \cong \frac{1}{{\det}^2}\operatorname{sym}^3(\operatorname{std}) \oplus
\frac{1}{\det}
$$
where $\det:L\to \mathbb{G}_m$ is the determinant
character, and $\operatorname{std}:L\xrightarrow{\cong} \operatorname{GL}_2$
is the fixed isomorphism.
The above short exact sequence
can be upgraded to a short exact sequence of
groups with $L$-actions
$$
0\to \frac{1}{\det}\to U
\to \frac{1}{{\det}^2}\operatorname{sym}^3(\operatorname{std}) \to 0.
$$

\subsubsection{The long root parabolic}

Let $Q\subset G_2$ be the long root parabolic,
which admits a Levi decomposition
$Q=L'\ltimes V$ where
$L'\cong \operatorname{GL}_2$ and $V$ is a nilpotent group of class $3$.
Fix an isomorphism $\operatorname{std}:L'\xrightarrow{\cong}\operatorname{GL}_2$.
Write $\det$ for the composition
$L'\xrightarrow{\operatorname{std}} \operatorname{GL}_2 \xrightarrow{\det}\operatorname{GL}_1$.

Write $U'$ for $V/Z(V)$.
Then $U'$ is a nilpotent group of class $2$ whose
center is isomorphic to $\mathbb{G}_a$.
The conjugation action of $L'$ on $U'$ is given by
$U'/Z(U') \cong \operatorname{std}$,
and $Z(U') \cong \det$,
as $L'$-modules.

\vspace{3mm}

\subsection{Non-abelian inflation-restriction}
\vspace{3mm}

Let $R$ be either $\mathcal{O}_E$ or ${\mathbb{F}}$.
For ease of notation, write
$U$ for $U(R)$.

\vspace{3mm}

\paragraph{Non-abelian Galois cohomology}
We recall a few facts about the non-abelian version
of Galois cohomology.
Let $\Gamma$ be a (profinite) group
Let
$$
0\to A\to B\to C\to 0
$$
be a short exact sequence of groups with
continuous $\Gamma$-action.
If $A\to B$ is \textit{central}, that is, $A$ is contained in the center of $B$,
then we have a long exact sequence (\cite[Proposition 43, 5.7]{Se02})
\begin{eqnarray}
\begin{split}
1 &\to A^\Gamma \to B^\Gamma \to C^\Gamma \\
& \xrightarrow{} H^1(\Gamma, A)
\to H^1(\Gamma, B) \to H^1(\Gamma, C) \\
& \xrightarrow{\delta} H^2(\Gamma, A)
\end{split}\nonumber
\end{eqnarray}
Let $H \subset G$ be a closed normal subgroup.
Then there is an exact sequence (\cite[5.8]{Se02})
$$
1\to H^1(\Gamma/H, A^H)
\to H^1(\Gamma, A) \to H^1(H, A)^{\Gamma/H}.
$$
If $A$ is an abelian group, then the sequence above can be upgraded
to the inflation-restriction exact sequence:
$$
1\to H^1(\Gamma/H, A^H)
\to H^1(\Gamma, A) \to H^1(H, A)^{\Gamma/H} \to H^2(\Gamma, A^H).
$$

\vspace{3mm}
\paragraph{Theorem} \cite[Theorem 3.15]{Ko02}
Let $\Gamma$ be a profinite group,
$H$ a normal subgroup of finite index,
and $A$ an (abelian) $G$-module whose elements have finite order
coprime to $(\Gamma:H)$. Then
$$
H^n(\Gamma/H, A^H) = 0
$$
for all $n\ge 1$, and the restriction
$$
H^n(\Gamma, A)\to H^n(H, A)^{\Gamma/H}
$$
is an isomorphism.

\vspace{3mm}

The fact above implies the following diagram with exact columns
$$
\xymatrix{
    H^1(\Gamma, Z(U)) \ar[r]^{\cong}_{\operatorname{res}} \ar[d] &
    H^1(H, Z(U))^{\Delta} \ar[d] \\
    H^1(\Gamma, U) \ar@{^{(}->}[r]_{\operatorname{res}} \ar[d]^{\alpha_1} &
    H^1(H, U)^{\Delta} \ar[d]^{\alpha_2} \\
    H^1(\Gamma, U^{\operatorname{ad}})
    \ar[r]^{\cong}_{\operatorname{res}} \ar[d]^{\delta_1} &
    H^1(H, U^{\operatorname{ad}})^{\Delta} \ar[d]^{\delta_2} \\
    H^2(\Gamma, Z(U)) \ar@{^{(}->}[r] &
    H^2(H, Z(U))
}
$$
\vspace{3mm}
\paragraph{Proposition}
\label{prop:inf-res}
The restriction map of non-abelian $1$-cocycles
$$
H^1(\Gamma, U) \to H^1(H, U)^{\Delta}
$$
is a bijection.

\begin{proof}
Diagram chasing.
Let $[c] \in H^1(H, U)^{\Delta}$.
Since $\delta_1(\operatorname{res}^{-1}(\alpha_2[c])) = \delta_2(\alpha_2[c]) = 0$,
there exists $[b]\in H^1(\Gamma, U)$ such that
$\alpha_1(\operatorname{res}([b])) = \alpha_2([c])$.
Since $\alpha_2^{-1}(\alpha_2([c]))$ is a $H^1(H, Z(U))^{\Delta}$-torsor,
we can twist $[b]$ to make $\operatorname{res}([b]) = [c]$.
\end{proof}

\vspace{3mm}

\paragraph{Representation-theoretic interpretation of non-abelian $1$-cocycles}
\label{par:non-ab-h1}
Let $P$ be a group which is a semi-direct product $L\ltimes U$.
Let $q_L: P\to L$ be the quotient map.
Fix a section $L \to P$ of $q_L$, which allows us to identify
(set-theoretically) $P$ with $U \times L$.
For $g\in \Gamma$, write $g = g_Ug_L$ such that $g_U\in U\times \{1\}$
and $g_L\in \{1\}\times L$.
Let $\Gamma$ be a profinite group.
Let $\bar\tau: \Gamma \to L$ be a group homomorphism.
Let $\tau: \Gamma \to P$ be a lifting of $\bar\tau$.
Set $c:= q_U\circ \tau: \Gamma\to U$.
Then
\begin{eqnarray}
c(gh) &=& q_U(\tau(g)\tau(h))=q_U(\tau(g)_U\tau(g)_L\tau(h)_U\tau(h)_L)\nonumber\\
&=&q_U(\tau(g)_U\tau(g)_L\tau(h)_U\tau(g)_L^{-1}\tau(gh)_L)\nonumber\\
&=&c(g) (\tau(g)_L c(h)\tau(g)^{-1}_L)\nonumber\\
&=:&c(g) (\tau(g)_L\cdot c(h))\nonumber
\end{eqnarray}
is a (non-abelian) crossed homomorphism.
So $H^1(\Gamma, U)$ classifies liftings $\tau$ of $\bar\tau$ up to equivalence.

\vspace{3mm}

\subsubsection{Lifting characteristic $p$ cocycles via
inflation-restriction}
~

Let $[\bar c] \in H^1(\Gamma, U({\mathbb{F}}))$
be a characteristic $p$ cocycle.
Assume the restriction $[\bar c|_H]
\in H^1(H, U({\mathbb{F}}))$
has a characteristic $0$
lift $[c_h]\in H^1(H, U(\mathcal{O}_E))$.
We want to build a lift $[c]\in H^1(\Gamma, U(\mathcal{O}_E))$ of $[\bar c]$
using
$[c_h]$.

Note that when $U$ is an abelian group,
this can be easily achieved by
taking the average
$$
[c] := \frac{1}{\# \Delta}\sum_{g\in \Delta}g\cdot [c_h].
$$
Here we identify $H^1(\Gamma, U(\mathcal{O}_E))$
with a subset of $H^1(H, U(\mathcal{O}_E))$
via Proposition
\ref{prop:inf-res}.

Such a trick does not work anymore when
$U$ is non-abelian. Nonetheless,
we have the following:

\vspace{3mm}

\paragraph{Lemma}
\label{lem:non-ab-inf-res-lift}
If
there exists $[c_h]\in H^1(H, U(\mathcal{O}_E))$
and $[d]\in H^1(\Gamma, U^{\operatorname{ad}}(\mathcal{O}_E))$
such that
\begin{itemize}
\item
$\alpha_2([c_h])=\operatorname{res} ([d])$ and
\item
$[c_h|_H]$ mod $\varpi=[\bar c|_H]$
\end{itemize}
 then there exists
$[c]\in H^1(\Gamma, U(\mathcal{O}_E))$
which is a lifting of $[\bar c]$.

$$
\xymatrix{
    &H^1(\Gamma, Z(U)) \ar@{^{(}->}[r]_{\operatorname{res}} \ar[d] &
    H^1(H, Z(U)) \ar[d] \\
    &H^1(\Gamma, U) \ar@{^{(}->}[r]_{\operatorname{res}} \ar[d]^{\alpha_1} &
    H^1(H, U)\ar[d]^{\alpha_2}
& \hspace{-10mm} \ni [c_h]
    \\
    [d]\in \hspace{-10mm}&H^1(\Gamma, U^{\operatorname{ad}})
    \ar[r]_{\operatorname{res}} \ar[d]^{\delta_1} &
    H^1(H, U^{\operatorname{ad}}) \ar[d]^{\delta_2} \\
    &H^2(\Gamma, Z(U)) \ar@{^{(}->}[r] &
    H^2(H, Z(U))
}
$$

\begin{proof}
Since
$$
\delta_1([d]) = \delta_2(\alpha_2([c_h])),
$$
$[d] = \alpha_1([c'])$ for some
$[c']\in H^1(\Gamma, U(\mathcal{O}_E))$.
Since $\operatorname{res}([c'])$ and $[c_h]\in H^1(H, U(\mathcal{O}_E))$
have the same image in $H^1(H,U^{\operatorname{ad}}(\mathcal{O}_E))$ (via $\alpha_2$),
it makes sense to talk about the difference
$\operatorname{res}([c'])-[c_h] \in H^1(H, Z(U)(\mathcal{O}_E))$.
\footnote{$H^1(H, U(\mathcal{O}_E))$
is a $H^1(H, Z(U)(\mathcal{O}_E))$-principle
homogeneous space.
}
Consider the following diagram
$$
\xymatrix{
H^1(\Gamma, Z(U)(\mathcal{O}_E))
\ar[r] \ar@{^{(}->}[d]^{\operatorname{res}}&
H^1(\Gamma, Z(U)({\mathbb{F}}))
\ar[r]^{\delta} \ar@{^{(}->}[d]^{\operatorname{res}}&
H^2(\Gamma, Z(U)(\mathcal{O}_E)) \ar@{^{(}->}[d]\\
H^1(H, Z(U)(\mathcal{O}_E))
\ar[r] &
H^1(H, Z(U)({\mathbb{F}}))
\ar[r]^{\delta} &
H^2(H, Z(U)(\mathcal{O}_E))
}
$$
Let $[\bar c']\in H^1(\Gamma, Z(U)({\mathbb{F}}))$
be the reduction mod $\varpi$ of $[c']$.
Since $\operatorname{res}([\bar c'])-[\bar c_h]$
has a lift, $$\delta(\operatorname{res}([\bar c']-[\bar c_h]))=0\in H^2(H, Z(U)({\mathbb{F}})).$$
Therefore
$$\delta([\bar c']-[\bar c])
= \delta(\operatorname{res}([\bar c']-[\bar c]))
= \delta(\operatorname{res}([\bar c']-[\bar c_h]))=0.$$
and $[\bar c']-[\bar c]$
has a characertistic $0$ lift $[x]$,
and $[c]:=[c']-[x]$ is a lift of $[\bar c]$.
\end{proof}

The purpose of the whole Section \ref{sec:manipulate}
is to prove an upgrade of the above lemma, (that is, Theorem \ref{thm:non-abelian-obstruction}).

\subsection{External Galois action on the
Lyndon-Demu\v{s}kin cocycle group}
\label{ss:external-Galois}
~

\vspace{3mm}

The earlier subsection shows there is
an identification
$$
H^1(\Gamma, U(\mathcal{O}_E)) \cong H^1(H, U(\mathcal{O}_E))^{\Delta}.
$$
The goal of this subsection is to
upgrade this identification
to the cochain level.

Since the Galois action
$$
\phi(r^{\circ})|_{G_{K'}}:G_{K'} \to
U(\mathcal{O}_E)
$$
is Lyndon-Demu\v{s}kin.
We have a Lyndon-Demu\v{s}kin
complex $C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$
computing $H^{\bullet}(H, U(\mathcal{O}_E))$.
Recall that a $1$-cocycle
$c\in C^1_{\operatorname{LD}}(U(\mathcal{O}_E))$
is the same as a function
$$
\mathfrak{c}: \langle x_0, \cdots, x_{n+1}\rangle \to (\operatorname{Lie} U)(\mathcal{O}_E)
$$
such that
$$
\mathfrak{c}(gh) = \mathfrak{c}(g) +
g\cdot \mathfrak{c}(h) + \frac{1}{2}[
\mathfrak{c}(g), g\cdot\mathfrak{c}(h)]
$$
for all $g,h$; or, equivalently, a function
$$
c: \langle x_0, \cdots, x_{n+1}\rangle \to  U(\mathcal{O}_E)
$$
such that
$$
    c(gh) = c(g)(g\cdot c(h))
$$
for all $g,h$.

A cochain $c:\langle x_0, \cdots, x_{n+1}\rangle\to U(\mathcal{O}_E)$
lies in
$Z^1_{\operatorname{LD}}(U(\mathcal{O}_E))$
if and only if it factors through
    the (discrete) Demu\v{s}kin group
    $\langle x_0, \cdots, x_{n+1} | R\rangle$.

Let $c\in Z^1_{\operatorname{LD}}(\mathcal{O}_E)$,
regarded as a function
$\langle x_0, \dots, x_{n+1}|R\rangle
\to U(\mathcal{O}_E)$.
Since $U(\mathcal{O}_E)$ is a pro-$p$ group,
the crossed homomorphism
necessarily
factors through the pro-$p$ completion,
that is, we have a commutative diagram
$$
\xymatrix{
    &\langle x_0, \dots, x_{n+1}|R
    \rangle \ar[d]^{\pi}\ar[r]^{\hspace{5mm}c}
    & U(\mathcal{O}_E) \\
    G_{K'}(p)\ar@{=}[r] &\widehat{
    \langle x_0, \dots, x_{n+1}|R\rangle
    }^p\ar[ru]^{\widehat{c}}
}
$$

Since we have identified
the pro-$p$ quotient of
    $G_{K'}$ with the pro-$p$ completion of $\langle x_0, \cdots, x_{n+1} | R\rangle$,
 we can define,
 for each $g\in G_K$, an
     automorphism $\alpha_g$ of $Z^1_{\operatorname{LD}}(U(\mathcal{O}_E))$ via
$$
\alpha_g(c) := (h\mapsto g\cdot \widehat{c}(g^{-1}\pi(h)g)).
$$
So we defined an action of $G_K$
on $Z^1_{\operatorname{LD}}(U(\mathcal{O}_E))$.

For ease of notation, write
$g\cdot c$ for $\alpha_g(c)$.
Note that
$(g\cdot c)(h) = (\alpha_g(c))(h)$
is different from $g\cdot c(h)$.
We apologize for the confusing notation.

\vspace{3mm}
\paragraph{Remark}
We don't know whether or not
we can define a $G_K$-action
on the whole cochain group $C^1_{\operatorname{LD}}(U(\mathcal{O}_E))$.
It seems to involve some subtle
combinatorial group theory.

\vspace{3mm}

\paragraph{Guess}
The cup product
$$
\cup:Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E)) \times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E)) \to C^2_{\operatorname{LD}}(Z(U(\mathcal{O}_E)))
$$
is compatible with $G_K$-action.

\vspace{3mm}
This Guess would hold, for
example, if for each $g\in G_K$,
the conjugation by $g$
$$
\phi_g : G_{K'} \to G_{K'}
$$
can be lifted to an automorphism of
free pro-$p$ groups on $(n+2)$-generators
$$
\phi_g:\langle x_0, \cdots, x_{n+1}\rangle
\to
\langle x_0, \cdots, x_{n+1}\rangle.
$$
This is closely related to the so-called \textit{Dehn-Nielsen} theorem.
Classically, Dehn-Nielsen is saying all automorphism of the fundamental group
of the genus $g$ closed surface $M_g$ is induced by a homeomorphism.
The algebraic version of Dehn-Nielsen can be formualted as,
under the usual presentation of $F=\langle a_1,b_1,\cdots,a_g,b_g\rangle\to\langle a_1,b_1,\cdots,a_g,b_g|[a_1,b_1]\cdots[a_g,b_g]\rangle\cong\pi_1(M_g)$,
all automorphism of $\pi_1(M_g)$ is induced from an automorphism of the free group $F$.

\vspace{3mm}

\paragraph{Conjecture} Dehn-Nielsen holds for $\operatorname{Spec} K$.

\vspace{3mm}

Assume $Z(U(\mathcal{O}_E))\cong \mathcal{O}_E$
from now on.

\vspace{3mm}
\begin{comment}
\paragraph{Lemma}
\label{lem:G_K-kernel-cup}
If $C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$ is
$\delta$-flat and $p>2$, then the $G_K$
action on
$Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$ sends
the kernel of
$$
\cup:Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E)) \times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E)) \to C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))
$$
to the kernel itself.

\begin{proof}
Fix $g\in G_K$.

\vspace{3mm}
{\bf Claim}
$x\cup x = 0$ if and only if
$(g\cdot x) \cup (g\cdot x)=0$.

\begin{quotation}
\begin{proof}
 Identification
 $C^1_{\operatorname{LD}}(U)$ with
$C^1_{\operatorname{LD}}(U^{\operatorname{ad}}) \oplus C^1_{\operatorname{LD}}(Z(U))$.
We have
$$
\{x\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})|x\cup x = 0\} = Z^1_{\operatorname{LD}}(U) \cap C^1_{\operatorname{LD}}(U^{\operatorname{ad}})
$$
by Lemma \ref{lem:non-abelian-h1}.
It is clear that $g\cdot (C^1_{\operatorname{LD}}(U^{\operatorname{ad}}) \cap Z^1_{\operatorname{LD}}(U)) = C^1_{\operatorname{LD}}(U^{\operatorname{ad}}) \cap Z^1_{\operatorname{LD}}(U)$.
\end{proof}
\end{quotation}

First, we tensor over ${\mathbb{F}}$.
By the theory of symmetric bilinear forms over a field,
$Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})$ has an orthogonal basis
$\{\bar e_i\}_{i=1, m_1+m_2}$, such that
$$
\bar e_i\cup \bar e_j =
\begin{cases}
\delta_{i,j} & i,j \le m_1\\
0 & \text{otherwise}
\end{cases}
$$
Since the cup product is flat,
we can lift $\{\bar e_i\}$
to a basis $\{e_i\}$ of $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
such that $\{e_i\}_{i=m_1+1}^{m_2+m_1}$
is a basis of the kernel of the cup product.
Fix $g\in G_K$.
We want to show $\{g\cdot e_i\}_{i=m_1+1}^{m_2+m_1}$
is also a basis of the kernel of the cup product.

We do this by a counting argument.
We tensor over $\mathcal{O}_E/\varpi^s$,
where $s\ge 1$ and $\varpi$ is a uniformizer.

{\bf Claim}
Let $v,v_1,\cdots,v_n$ be elements of $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E/\varpi^s))$.
Assume $v \cup v \ne 0$ mod $\varpi$, and $v_i\cup v_j = 0$ for $1\le i,j \le n$.
Then
$v \in \operatorname{span} \langle v_1,\cdots,v_n\rangle^{\perp}$
if and only if
$$
\#\{x \in \operatorname{span}\langle v, v_1,\cdots,v_n \rangle| x\cup x = 0 \}
= (\#\mathcal{O}_E/\varpi^s)^{n}.
$$

\begin{quotation}
\begin{proof}
Note that
$\operatorname{span} \langle v_1,\cdots,v_n\rangle \subset\{x \in \operatorname{span}\langle v, v_1,\cdots,v_n \rangle| x\cup x = 0 \}
$, and thus
$\#\{x \in \operatorname{span}\langle v, v_1,\cdots,v_n \rangle| x\cup x = 0 \}
\ge \# \operatorname{span} \langle v_1,\cdots,v_n\rangle
= (\#\mathcal{O}_E/\varpi^s)^{n}$.

If $v \in \operatorname{span} \langle v_1,\cdots,v_n\rangle^{\perp}$, then the equality above clearly holds.
If $v \notin \operatorname{span} \langle v_1,\cdots,v_n\rangle^{\perp}$, then there exists $v'\in \operatorname{span}\langle v, v_1,\cdots,v_n \rangle$ such that $v\cup v'\ne 0$.
Write $\lambda$ for $-2\frac{v\cup v'}{v\cup v}\in \mathcal{O}_E/\varpi^s$.
Since $(\lambda v) \cup v = -2{v\cup v'} \ne 0$, we have $\lambda v\ne 0$.
We have
$(v'+ \lambda v) \cup (v'+\lambda v) = 2\lambda v'\cup v + \lambda^2 v \cup v = 0$,
and thus
$\#\{x \in \operatorname{span}\langle v, v_1,\cdots,v_n \rangle| x\cup x = 0\}
> (\#\mathcal{O}_E/\varpi^s)^{n}$.
\end{proof}
\end{quotation}

So counting shows
$g\cdot e_1$ is orthogonal
to $\{g \cdot e_i\}_{i=m_1+1}^{m_2+m_1}$
mod $\varpi^s$.
Likewise,
$g\cdot e_k$ is orthogonal
to $\{g \cdot e_i\}_{i=m_1+1}^{m_2+m_1}$
mod $\varpi^s$,
for all $k=1,\cdots,m_1+m_2$ and all $s\ge 1$.
Hence $\{g\cdot e_i\}_{i=m_1+1}^{m_2+m_1}$
is a basis of the kernel of the cup product,
and the action of $G_K$ sends
the kernel of $\cup$
to the kernel of $\cup$.
\end{proof}
\end{comment}

\subsubsection{}

Recall that
$$
H^1(H, U^{\operatorname{ad}})^{\Delta} = H^1(G_K, U^{\operatorname{ad}}).
$$
Define
\begin{eqnarray}
(Z^1_{LD})^{\Delta}
&:=& \{x\in Z^1_{\operatorname{LD}}| \text{image of }x
\text{ in }H^1\text{ is contained
in }(H^1)^{\Delta}\}\nonumber\\
&=& \{x\in Z^1_{\operatorname{LD}}|g\cdot x-x\in B^1_{\operatorname{LD}}\text{ for all }g\in G_K\}\nonumber
\end{eqnarray}
Since $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$
is a submodule of
a finite flat module,
it is finite flat.

\begin{comment}
\subsubsection{Lemma}
\label{lem:Delta-flat}
Assume $C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$
is $\delta$-flat.
If $H^2(G_K, Z(U)({\mathbb{F}}))\ne 0$, then
the cup product
$$
\cup:Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta} \times
Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta} \to C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))
$$
is also flat.

\vspace{3mm}
\text{\bf Remark}
We make two observations before proving
this lemma.
First, the cup product on the cohomology level
$$
H^1(H, U^{\operatorname{ad}}(\mathcal{O}_E))
\times
H^1(H, U^{\operatorname{ad}}(\mathcal{O}_E))
\to H^2(H, Z(U)(\mathcal{O}_E))
$$
is compatible with $\Delta$-action.
Second, the $1$-coboundaries
$ B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
are always contained in the kernel
of the cup product on the cocycle level.

\begin{proof}
Pick $\bar x\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}/\varpi$
such that $\bar x \cup \bar y =0\mod\varpi$ for all $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$.
Write $[\bar x]$ for the image of
$\bar x$ in $H^1(H, U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$.
For any $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})$, we have
\begin{eqnarray}
[\bar x]\cup [\bar y]
&=& \frac{1}{\# \Delta}\sum_{g\in \Delta}
g\cdot ([\bar x]\cup [\bar y]) \hspace{10mm}\text{(since $H^2(H, Z(U)(\mathcal{O}_E)) = H^2(H, Z(U)(\mathcal{O}_E))^\Delta$)}\nonumber\\
&=& \frac{1}{\# \Delta}\sum_{g\in \Delta}
[g\cdot \bar x]\cup [g\cdot\bar y]\nonumber\\
&=& \frac{1}{\# \Delta}\sum_{g\in \Delta}
[ \bar x]\cup [g\cdot\bar y]\hspace{10mm}\text{(since $\bar x \in Z^1(U^{\operatorname{ad}}(\mathcal{O}_E))^\Delta/\varpi$)}\nonumber\\
&=& [\bar x]\cup\frac{1}{\# \Delta}\sum_{g\in \Delta}
[g\cdot\bar y]\nonumber\\
&=&0\hspace{40mm}\text{(since $\frac{1}{\# \Delta}\sum_{g\in \Delta}
[g\cdot\bar y] \in Z^1(U^{\operatorname{ad}}(\mathcal{O}_E))^\Delta/\varpi$)}\nonumber
\end{eqnarray}
Since $C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))$ has rank $1$,
$H^2(H, Z(U)(\mathcal{O}_E))$ is a principle $\mathcal{O}_E$-module; by Nakayama Lemma, we must have
$H^2(G_K, Z(U)(\mathcal{O}_E)) = H^2(H, Z(U)(\mathcal{O}_E))^{\Delta}=H^2(H, Z(U)(\mathcal{O}_E))$.

Since
$H^2(G_K, Z(U)({\mathbb{F}}))\ne 0$,
$H^2(G_K, Z(U)({\mathbb{F}})) =
C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))$,
and therefore
$\bar x \cup \bar y=0$ for all $y$.
By the $\delta$-flatness of $C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$, $\bar x$ has a lift $x\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$ which is in the kernel
of the cup product.
We choose a system of representatives
$\{g_i\}\subset G_K$ of $\Delta$.
Set $\widetilde{x} := \frac{1}{\#\Delta}\sum_{i}g_i\cdot x$.
Then $\widetilde{x} \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$ and by the previous lemma,
$\widetilde{x}\cup y = 0$ for all $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$.
Since $\bar b=\bar x-\widetilde{x}\mod\varpi \in B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))/\varpi$, we can
choose a lift $b\in B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$ of $\bar b$,
and $(\widetilde{x}-b)$ is a lift
of $\bar x$ which annihilates the cup product.
\end{proof}

\vspace{3mm}

\end{comment}

\subsection{Constructing non-abelian cocycles}~

\vspace{3mm}

We keep all notations from the previous subsections.

Assume $Z(U)(\mathcal{O}_E) = \mathcal{O}_E$
from now on.

We fix some notations.
The quotient
$U\to U/Z(U)=U^{\operatorname{ad}}$
induces maps
$\operatorname{ad}: Z^1_{\operatorname{LD}}(U(\mathcal{O}_E))\to Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$.

\vspace{3mm}
\begin{comment}
\subsubsection{Lemma}
\label{lem:cup-0-lift}
Assume $C^{\bullet}_{\operatorname{LD}}(U(\mathcal{O}_E))$
is $\delta$-flat,
and $H^2(G_K, Z(U)({\mathbb{F}}))\ne 0$.

Let $\bar c \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))^{\Delta}$.
Assume $\bar c \cup \bar c =0\in
C^2_{\operatorname{LD}}(Z(U)({\mathbb{F}}))$.
If there exists a lift
$c'\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$ of
$\bar c$,
then there is a  lift
$c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})(\mathcal{O}_E)^{\Delta}$
of $\bar c$
such that $c\cup c=0\in C^2_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))$.

\begin{proof}
Choose a system of representatives
$\{g_i\}\subset G_K$ of $\Delta$.

The $\Delta$-average
$$
c'^{\Delta}:=\frac{1}{\#\Delta}\sum g_i\cdot c'
$$
lies in $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$.
Since $\bar c \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))^{\Delta}$,
$\bar b:=c'^{\Delta}-c'$
mod $\varpi$ lies in $B^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))$.
Let $b\in B^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))$
be a lift of $\bar b$.
Set $c^\Delta:=(c'^{\Delta}-b)\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$.

Since $c^\Delta$ is a lift of $\bar c$, we have
$
c^\Delta\cup c^\Delta = 0
$ mod $\varpi$.

There are two possibilities:
\begin{itemize}
\item[(i)]
For all $y\in Z^1_{\operatorname{LD}}(U^{ad}(\mathcal{O}_E))^{\Delta}$,
$c^\Delta\cup y = 0$ mod $\varpi$;
\item[(ii)]
There exists $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$ such that
$c^\Delta\cup y \ne 0$ mod $\varpi$.
\end{itemize}

In case (i),
by Lemma \ref{lem:Delta-flat},
there exists $c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$ congruent to $c^\Delta$
mod $\varpi$ such that
$c\cup y = 0$ for all $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$.
In particular, $c\cup c=0$,

In case (ii),
we prove by induction, and assume there exists
$c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$
congruent to $c^\Delta$ mod $\varpi^s$ such that
$c\cup c=0$ mod $\varpi^s$ for $s>0$.
(We can take $c=c^\Delta$ when $s=1$.)
Choose $y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$
such that $c^\Delta\cup y\ne 0$ mod $\varpi$.
We have
$$
(c+\lambda \varpi^{s}y)\cup
(c+\lambda \varpi^{s}y)=
c\cup c + 2\lambda \varpi^{s} c\cup y
+ \lambda^2 \varpi^{2s}y\cup y.
$$
The above expression is congruent to $0$
mod $\varpi^{s+1}$
for a suitably chosen $p$-adic unit $\lambda\in \mathbb{Z}_p^{\times}$.
\end{proof}

Recall by Lemma \ref{lem:non-abelian-h1},
Since we have an identification
$$
    \{(x,y)\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})\times C^1_{\operatorname{LD}}(Z(U))|x\cup x+d^2(y)=0\}
    =Z^1_{\operatorname{LD}}(U).
$$
We'll be using this identification
in the rest of this subsection.

\end{comment}

\subsubsection{Lemma}
\label{lem:cup-0-lift}
Assume
$p\ne 2$ and
the cup product
$$
\text{($\dagger$)}\hspace{10mm} \cup:
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E)) \otimes{\mathbb{F}}
\times
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E)) \otimes {\mathbb{F}}
\to H^2(G_K, Z(U)({\mathbb{F}}))
$$
is non-trivial.

Let $(\bar c, \bar f)\in Z^1_{\operatorname{LD}}(U({\mathbb{F}}))$.
Assume $\bar c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))^{\Delta}$.
If $\bar c$ admits a characteristic $0$
lift $c'\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}})(\mathcal{O}_E)$,
then $(\bar c, \bar f)$ admits
a lift $(c, f)\in Z^1_{\operatorname{LD}}(U(\bar{\mathbb{Z}}_p))$
such that $c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^{\Delta}$.

\begin{proof}
Pick an arbitrary lift $f\in C^1_{\operatorname{LD}}(Z(U)(\mathcal{O}_E))$ of $\bar f$.
Choose a system of representatives
$\{g_i\}\subset G_K$ of $\Delta$.
By replacing $c'$ by the $\Delta$-average $\frac{1}{\#\Delta}\sum g_i\cdot c'$ + some coboundary,
we assume $c'\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^{\Delta}$.

Let $\lambda\in {\mathbb{Z}}_p^{\times}$ be a scalar.

Since the symmetric bilinear pairing ($\dagger$) is
non-trivial, there exists
$y\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\mathcal{O}_E))^{\Delta}$ such that
$y\cup y\ne 0$ mod $\varpi$.
Consider
$$
(c'+ \lambda y)\cup (c'+\lambda y) + d^2(f)
=c'\cup c' + d^2(f) + 2 \lambda c'\cup y + \lambda^2 y\cup y
$$
which is a degree two polynomial in $\lambda$
whose Newton polygon has vertices
$(0,+),(1,+\text{~or~}0),(2,0)$
and thus has at least one solution $\lambda_0$ with positive $p$-adic valuation.
Set $(c,f):=(c'+\lambda_0 y, f)$.

We have $(c,f)\in Z^1_{\operatorname{LD}}(U(\bar{\mathbb{Z}}_p))$ by Lemma \ref{lem:non-abelian-h1} and $c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^{\Delta}$.
\end{proof}

\vspace{3mm}

\subsubsection{Theorem}
\label{thm:non-abelian-obstruction}
Assume  $p\ne 2$ and
the cup product
$$
\cup:
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))\otimes {\mathbb{F}}
\times
H^1(G_K, U^{\operatorname{ad}}(\mathcal{O}_E))\otimes {\mathbb{F}}
\to H^2(G_K, Z(U)({\mathbb{F}}))
$$
is non-trivial.

Let $[(\bar c, \bar f)]\in H^1(G_K,U({\mathbb{F}}))$ be a characteristic $p$ cocycle.
If
$[\bar c|_{G_{K'}}]\in H^1(G_{K'}, U^{\operatorname{ad}}({\mathbb{F}}))$ admits
a characteristic $0$ lift in $H^1(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$,
then $[(\bar c, \bar f)]$
 admits a characteristic $0$
 lift
 $[(c, f)]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$.

\begin{proof}
We choose a cocycle
$(\bar c, \bar f)\in Z^1_{\operatorname{LD}}(U({\mathbb{F}}))$ which defines the cohomology class
$[(\bar c, \bar f)]$.
Clearly $\bar c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}({\mathbb{F}}))^{\Delta}$.
Say $[d]\in H^1(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$
is a lift of $[\bar c]$,
which is defined  by $d\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$.
Write $\bar d$ for the image of $d$
in  $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{F}}_p))$.
By changing $d$ by a coboundary,
we can assume $\bar d = \bar c$.

Lemma \ref{lem:cup-0-lift}
produces $(c, f)\in Z^1_{\operatorname{LD}}(U(\bar{\mathbb{Z}}_p))$
such that $c\in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^{\Delta}$.
Now the theorem follows from
Lemma \ref{lem:non-ab-inf-res-lift}.
\end{proof}

Theorem \ref{thm:non-abelian-obstruction}
is saying when $U$ is a nilpotent group of class $2$
with rank-$1$ center,
there exists a short exact sequence of
pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta} H^2(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))
$$
under technical assumptions.

Combining Theorem \ref{thm:non-abelian-obstruction}
and Theorem \ref{thm:nontrivial},
we have very nice obstruction theory
for lifting mod $\varpi$ cohomology classes
in the mildly regular case.

\vspace{3mm}
\subsubsection{Theorem}
\label{thm:obstruction-theory}
Assume $p\ne 2$.
Let $r :G_K \to L(\mathcal{O}_E)$ be a continuous group homomorphism.
Let $K'/K$ be a finite Galois extension of
prime-to-$p$ degree
such that
$r|_{G_{K'}}$ is Lyndon-Demu\v{s}kin and mildly regular.

Then either
\begin{itemize}
\item
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta} H^2(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))
$$
where $\delta$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p}
H^1(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{F}}_p)) \to
H^2(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$, or
\item
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta'} H^2(G_{K'}, Z(U)(\bar{\mathbb{Z}}_p))
$$
where $\delta'$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p'}
H^1(G_{K}, Z(U)(\bar{\mathbb{F}}_p)) \to
H^2(G_{K'}, Z(U)(\bar{\mathbb{Z}}_p))$.
\end{itemize}

\begin{proof}
Write $\Delta$ for $G_K/G_{K'}$.
By Theorem \ref{thm:nontrivial}, there are three cases to consider.

\text{\bf Case I}: the cup product
($\dagger$) $H^1(G_K, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p)) \otimes {\mathbb{F}}
\times
H^1(G_K, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p)) \otimes {\mathbb{F}}
\to H^2(G_K, Z(U)(\bar{\mathbb{Z}}_p)) \otimes {\mathbb{F}}$
is non-trivial.
This is a corollary of Theorem \ref{thm:non-abelian-obstruction}.

\text{\bf Case II}: $H^2(G_K, Z(U)({\mathbb{F}}))=0$.
By Nakayama's lemma, $H^2(G_K, Z(U)(\bar{\mathbb{Z}}_p))=0$.

Let $[(\bar c,\bar f)]\in H^1(G_K, U(\bar{\mathbb{F}}_p))$
be a cohomology class defined by
$(\bar c, \bar f)\in Z^1_{\operatorname{LD}}(U(\bar{\mathbb{F}}_p))$.

Set $\delta:H^1(G_K, U(\bar{\mathbb{F}}_p))
\to H^2(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$
to be the composite
$$
H^1(G_K, U(\bar{\mathbb{F}}_p)) \xrightarrow{[(\bar c,\bar f)]\mapsto [\bar c]}
H^1(G_K, U^{\operatorname{ad}}(\bar{\mathbb{F}}_p))
\to H^2(G_{K'}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p)).
$$

If $\delta([(\bar c, \bar f)])=0$,
then there exists a lift $c \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$ of $\bar c$.
By replacing $c$ by the $\Delta$-average of $c$,
we assume $c  \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^\Delta$.
Since $H^2(G_K, Z(U)(\bar{\mathbb{Z}}_p))=0$,
$[c\cup c] = 0$ and thus
there exists $g\in C^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{Z}}_p))^\Delta$
such that
$c \cup c = - d^2(g)$.
Write $\bar g$ for the image of $g$
in $C^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{F}}_p))$.
We have $\bar g - \bar f \in Z^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{F}}_p))^\Delta$.
Since $H^2(G_K, Z(U)(\bar{\mathbb{Z}}_p))=0$,
there exists a lift $h\in Z^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{Z}}_p))^\Delta$
of $\bar f - \bar g$.
It is clear that $[(c, g+h)]\in H^1(G_K, U(\bar{\mathbb{Z}}_p))$
is a lift of $[(\bar c, \bar f)]$.

\text{\bf Case III}: $H^2(G_K, U^{\operatorname{ad}}({\mathbb{F}})) = 0$,
and the cup product ($\dagger$) is trivial.
By Nakayama's lemma, $H^2(G_K, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))=0$.
By Theorem \ref{thm:delta-criterion},
we have (*) $Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p)) = K_{\operatorname{LD}}(U(\bar{\mathbb{Z}}_p))$.

Let $[(\bar c,\bar f)]\in H^1(G_K, U(\bar{\mathbb{F}}_p))$
be a cohomology class defined by
$(\bar c, \bar f)\in Z^1_{\operatorname{LD}}(U(\bar{\mathbb{F}}_p))$.

Since $H^2(G_K, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))=0$,
there exists a lift $c \in Z^1_{\operatorname{LD}}(U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))^\Delta$ of $\bar c$.
By (*) and Lemma \ref{lem:h1-cup}, we have $[c\cup c] =0 \in H^2(G_K, Z(U)(\bar{\mathbb{F}}_p))$.
So there exists $g\in Z^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{Z}}_p))^\Delta$
such that $c\cup c=-d^2(g)$.
Write $\bar g$ for the image of $g$ in
$Z^1_{\operatorname{LD}}(Z(U)(\bar{\mathbb{F}}_p))^\Delta$.
Set $\delta':H^1(G_K, U(\bar{\mathbb{F}}_p))
\to H^2(G_{K'}, Z(U)(\bar{\mathbb{Z}}_p))$
to be the composite
$$
H^1(G_K, U(\bar{\mathbb{F}}_p)) \xrightarrow{[(\bar c, \bar f)]\mapsto [\bar f-\bar g]}
H^1(G_K, Z(U)(\bar{\mathbb{F}}_p))
\to H^2(G_{K'}, Z(U)(\bar{\mathbb{Z}}_p)).
$$
which can be checked to well-defined.
If $\delta'([(\bar c, \bar f)]) = 0$,
there exists a lift $h$ of $\bar f - \bar g$.
The cohomology class $[(c,g + h)]$
is a lift of $[(\bar c, \bar f)]$.
\end{proof}

\subsubsection{Corollary}
\label{cor:obstruction-theory}
Assume $p\ne 2$.
Let $r :G_K \to L(\mathcal{O}_E)$ be a continuous group homomorphism.

If there exists a
finite Galois extension $K'/K$ of prime-to-$p$ degree
such that
$r|_{G_{K'}}$ is Lyndon-Demu\v{s}kin and mildly regular, then
either
\begin{itemize}
\item[(I)]
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta} H^2(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))
$$
where $\delta$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p}
H^1(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{F}}_p)) \to
H^2(G_{K}, U^{\operatorname{ad}}(\bar{\mathbb{Z}}_p))$, or
\item[(II)]
there is a short exact sequence of pointed sets
$$
H^1(G_K, U(\bar{\mathbb{Z}}_p))
\to H^1(G_K, U(\bar{\mathbb{F}}_p))
\xrightarrow{\delta'} H^2(G_{K}, Z(U)(\bar{\mathbb{Z}}_p))
$$
where $\delta'$ has a factorization
$H^1(G_K, U(\bar{\mathbb{F}}_p))\xrightarrow{p'}
H^1(G_{K}, Z(U)(\bar{\mathbb{F}}_p)) \to
H^2(G_{K}, Z(U)(\bar{\mathbb{Z}}_p))$.
\end{itemize}

\begin{proof}
It is an immediate consequence of Theorem \ref{thm:obstruction-theory}.
\end{proof}

\section{Introduction}
\input{G2-INTRO}

\subsection{Acknowledgement}

I would like to thank David Savitt,
for suggesting to me the project of constructing
    crystalline lifts of Galois representations
    valued in general reductive groups,
    and for his excellent advisoring.
    I would like to thank Matthew Emerton
    for teaching me his work \cite{EG19}.
I also want to thank Joel Specter and Xiyuan Wang
for helpful discussions.

\vspace{3mm}

\section{Lyndon-Demu\v{s}kin theory}

\label{sec:LD}
\input{G2-LD}
\vspace{3mm}

\section{$\delta$-Flat Lyndon-Demu\v{s}kin complexes}

\label{sec:FC}
\input{G2-FCRITERION}
\vspace{3mm}

\section{\small Non-abelian obstruction theory via Lyndon-Demu\v{s}kin cocycle group with external Galois action}
\label{sec:manipulate}
\input{G2-OBS}
\vspace{3mm}

\section{The Machinery for lifting non-abelian cocycles}
\label{sec:MACHINE}
\input{G2-MACHINE}
\vspace{3mm}
\section{Codimension estimates of loci cut out by $H^2$}
\label{sec:codim}
\input{G2-CODIM}
\vspace{3mm}

\section{The existence of crystalline lifts for
the exceptional group $G_2$}
\label{sec:main}
\input{G2-NONTRIVIAL}
\input{G2-MAIN}
\vspace{3mm}

\begin{appendix}

\section{Non-denegeracy of mod $\varpi$ cup product
for $G_2$}
\label{sec:input-i}
\input{G2-DELTA}

\section{Sagemath code}
\label{sec:sage}

\subsubsection{Proposition}
Let $V\subset B$ be the unipotent
radical of the Borel of $G_2$.
Let $g\in V(\bar{\mathbb{Z}}_p)$.
If $p > 5$, then $g^p = \operatorname{id}$ mod $\varpi$.

\begin{proof}
Let $P \supset B$ be the short root parabolic.
Let $P = L \ltimes U$ be the Levi decomposition.
Let $\pi:P\to L$ be the quotient.
Say $\pi(g) =
\begin{bmatrix}
1 & l \\
0 & 1
\end{bmatrix}
$.
Fix a projection $P\to U$.
Also fix a projection $U \to Z(U)$.
Say the projection of $g$ onto $U/Z(U) \cong \mathbb{A}^4$
via $P\to U\to U/Z(U)$ is
$(u_0,u_1,u_2,u_3)$.
Say the projection of $g$ onto $Z(U)\cong \mathbb{A}^1$
via $P\to U\to Z(U)$
is $u_4$.

For simplicity, we write $g=(l;u_0,u_1,u_2,u_3;u_4)$.
We have, for any integer $q$,
\begin{eqnarray}
g^q&=&(q l; q u_0, -\frac{1}{2}q(q-1)u_0 l + q u_1, \nonumber\\
&&-\frac{1}{6}q(q-1)(2q-1)u_0 l^2 + q(q-1)u_1 l + q u_2,\nonumber\\
&&-\frac{1}{4}q^2(q-1)^2u_0l^3+\frac{1}{2}q(q-1)(2q-1)u_1l^2
+\frac{3}{2}q(q-1)u_2 l + q u_3, q u_4;\nonumber\\
&&\frac{1}{120}(q-1)q(q+1)(3q^2-2)u_0^2l^3-\frac{1}{2}(q-1)q(q+1)(u_1^2+u_0u_2)l)\nonumber
\end{eqnarray}
It can be computed by hand, and can be verified by computer algebra system.
The Proposition follows from the above computation immediately.
\end{proof}

The following is the SageMath source code for computing
cup product.

\lstinputlisting[language=Python]{cup-LD.sage}

If we compute \hspace{2mm}
    \verb|cup_product_mod_p(5,4,4)|
\hspace{2mm}
in SageMath notebook,
we'll get an anti-lower-triangular matrix
in the sense of Lemma \ref{lem:cup-C-nondeg}.

\end{appendix}

\vspace{3mm}

\addcontentsline{toc}{section}{References}
\printbibliography

\end{document}