YNW Melly and YNW Bortlen are both facing witness tampering charges now, and officials say some of the tampering involved them invoking Rihanna’s name as part of their system of codes.

According to docs, obtained by TMZ Hip Hop, Melly and Bortlen both actively worked behind the scenes to keep key witnesses from cooperating with authorities and testifying in their double-murder trial.

Officials claim Melly is said to have used the phone privileges of another inmate to pass word to the outside … sometimes in calls to Bortlen, who was out on bond at the time.

According to the docs, Melly had apparently lost phone privileges due to disciplinary violations while in custody.

The docs say during some of the calls, there were references made to “Rihanna” and “A$AP Rocky’s baby mama” staying behind in a “Maybach” — which prosecutors believe was code for instructing a particular female witness not to appear at the trial. The docs note that the woman, in fact, did not show up at the trial.

YNW Melly Living Large

YWN MELLY BEFORE THE ARRESTLAUNCH GALLERY

Officials also say Melly developed a sophisticated system for communication — which they say is caught on surveillance video — where he would coordinate the delivery of hand-written messages to various cell blocks through nonspeaking cues.

Melly’s lawyer told TMZ Hip Hop the claims are a “desperate attempt” on the part of prosecutors after they failed to get a conviction during the first go-around.

It’ll be interesting to see how it all plays with the jury when the retrial starts next week.