As Western leaders prepare a bailout package for embattled Ukraine, they face a startling irony: Thanks to the almost bizarre structure of a bond deal between Ukraine and Russia, billions of those dollars are almost certain to go directly into the coffers of the Putin government.

As CNBC has reported, some aid money is bound to go into Russia as a result of energy trade and other economic factors. But the situation is actually much more acute than just that: An existing agreement between the two countries makes an immediate, direct transfer from Ukraine to Russia legally enforceable.

In December, Russian President Vladimir Putin agreed to lend Ukraine $15 billion. Few details were released at the time, except that Ukraine would issue bonds and Russia would buy them in installments through 2014.

The first and only installment occurred in late December, while then-Ukrainian President Viktor Yanukovych was still in charge in Kiev. The second installment was slated to happen in late February, but it never occurred, because the pro-Russian president had fled Ukraine and a new government was in place.

That first installment was $3 billion—in U.S. dollars, as dictated by the terms of the deal—issued on Dec. 24. It carries a lenient interest rate considering the shattered state of Ukraine's economy: a coupon of only 5 percent, payable semiannually on June 20 and Dec. 20. It is short-term debt, maturing on Dec. 20, 2015.

Startlingly, the notes are governed by U.K. law and subject to the exclusive jurisdiction of British courts. And most crucially, there is an odd and crucial clause in the bonds that has a direct impact on European and American taxpayers, as CNBC learned through a review of the bond agreement:

Yury Kirnichny | AFP | Getty Images

A journalist watches the televised speech of ousted Ukrainian President Viktor Yanukovych on March 11, 2014.

—Paragraph 3 (b) under Covenants:

(b) Debt RatioSo long as the Notes remain outstanding the Issuer shall ensure that the volume of the total state debt and state guaranteed debt should not at any time exceed an amount equal to 60 percent of the annual nominal gross domestic product of Ukraine.

The implications of that clause are that the minute the West or the International Monetary Fund extend a large loan to Ukraine, that country will almost certainly have a debt-to-GDP that exceeds 60 percent, immediately putting the Russian loan into default. That gives Russia the right to demand immediate repayment. And because the bonds are governed by British courts—which, presumably, neither Ukraine nor Russian can manipulate—it would be extremely difficult for Ukraine to avoid making the payment, using its new bailout money.

Investors learning good bond deals need good courts

The country and legal system where a bond is governed is of increasing interest to fixed-income investors and lenders around the world, a lesson learned during the Greek debt crisis. When a bond is issued under a country's local laws, the country's leadership can change the laws anytime. New laws can even be imposed retroactively. That's precisely what happened to the holders of Greek-law bonds during the debt crisis there. In the end, holders of Greek debt took a massive financial hit.

However, holders of the few Greek bonds that were governed under British law were and still are being paid back in full. They've made very healthy profits.

That lesson wasn't lost on investors during Puerto Rico's protracted attempts to borrow billions of dollars this week. Until now, all Puerto Rican debt was issued under Puerto Rican law. But to get a $3.5 billion deal done this week (the largest junk muni bond offering in history, according to those familiar with the deal) the commonwealth had to put the new bonds under jurisdiction of the laws of New York state.

That issue is also central to Argentina's protracted debt fights with Elliott Management. Argentina's leaders have said that as a sovereign nation, the country should not be beholden to hedge funds. But because they issued their bonds under New York law, they are beholden to the courts of the United States.

In opposing loan guarantees for Ukraine during a debate Wednesday in the Senate Foreign Relations Committee, Republican Sen. Rand Paul argued that Russia would ultimately benefit. His amendment to cancel the guarantees was defeated.