Singularity for some schemes defined by matrix equations over $\mathbb Z_p$ Sometimes, in the study of the singularity of integral models of some moduli spaces, one encounter some schemes defined by matrix equations over $\mathbb Z_p$. I wonder whether there are some general methods to study them. 
For instance, $\mathbb Z_p[x,y]/(xy-p)$ is a regular domain. For every positive integer $n$, let's consider the ring $R_n=\mathbb Z_p[A,B]/(AB-p)$, where $A,B$ means $n \times n$ matrices so $Z_p[A,B]$ is the $2n^2$ variables polynomial ring, and we quotient the ideal $(AB-p)$ ($AB$ means matrix multiplication) to get $R_n$. Some natural questions are: is $R_n$ flat over $\mathbb Z_p$? Is $R_n$ a domain ? Is $R_n$ Cohen-macaulay? Is $R_n$ Gorenstein?
Of course, one can also consider rings like $\mathbb Z_p[A,B]/(AB-p, BA-p)$, $Z_p[A,B,C]/(AB-C^2)$, $\mathbb Z_p[A,B]/(AB-BA)$...
A naive expectation is that the singularity will become worse if we enlarge $n$, but will finally "stabilize".
 A: The generic fiber of $R_n$ has dimension $n^2$, so $n^2+1$ if you account for $p$.
The special fiber is given by the equation $AB=0$. If we look at the locus where $B$ has rank $r$, the possible values of $B$ have dimension $n^2 - (n-r)^2$, and the possible values of $A$ have rank $n (n-r)$, for a total dimension of $n^2+r(n-r)$. For any $0< r<n$, this irreducible component cannot lie in the Zariski closure of the generic one, hence the ring is not flat or a domain.
As soon as this is greater than $n^2+1$, we can see that this irreducible component has larger dimension than the generic one. Because the closures of both this irreducible component and the generic one contain zero, the local ring at zero is not equidimensional, hence not Cohen-Macauley (and thus not Gorenstein).
So the singularities are quite bad.
On the other hand for your ring $\mathbb Z_p[A,B]/ (AB-p, BA-p)$, the same argument shows that the irreducible components of the characteristic $p$ fiber all have dimension $n^2$. So perhaps the ring has better properties in this case.
In terms of techniques, I would highlight the technique of breaking the space into locally closed pieces depending on the ranks, conjugacy classes, etc. of the matrices involved and using linear algebra to get a handle on the geometry, in particular the dimensions, of these locally closed pieces. 
