codexuc-real-ideal-experiments.py
uc-real-ideal-experiments.py
"""Draw the two experiments used in simulation-based cryptographic security.
Tested with Python 3.14, Matplotlib 3.10.7. Run from the media output directory.
The ideal panel collapses honest I/O forwarding into the functionality box.
"""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch, FancyArrowPatch
fig, axs = plt.subplots(1, 2, figsize=(10, 4.7), facecolor='white')
fig.subplots_adjust(left=.025, right=.975, top=.84, bottom=.17, wspace=.08)
fig.suptitle('Can the same environment distinguish the two executions?', fontsize=15, y=.96)
def box(ax, x, y, label, color):
ax.add_patch(FancyBboxPatch((x-.18,y-.085), .36,.17,
boxstyle='round,pad=0.012', facecolor=color, edgecolor='#344454', lw=1.4))
ax.text(x,y,label,ha='center',va='center',fontsize=11)
def arrow(ax, a, b, label, offset=(0,0), two=True):
ax.add_patch(FancyArrowPatch(a,b,arrowstyle='<->' if two else '-|>',
mutation_scale=12, lw=1.4, color='#344454'))
ax.text((a[0]+b[0])/2+offset[0],(a[1]+b[1])/2+offset[1],label,
ha='center',va='center',fontsize=9.5,backgroundcolor='white')
for ax, title, left, right in zip(axs,
['REAL EXECUTION', 'IDEAL EXECUTION'],
['Honest protocol\nparties', 'Ideal functionality\n$\\mathcal{F}$'],
['Adversary $A$', 'Simulator $S$']):
ax.set(xlim=(0,1),ylim=(0,1)); ax.axis('off')
ax.text(.5,.98,title,ha='center',fontsize=11,weight='bold')
box(ax,.5,.78,'Environment $Z$','#dcecf8')
box(ax,.24,.29,left,'#e4f0df');box(ax,.76,.29,right,'#fff0d5')
arrow(ax,(.40,.68),(.25,.39),'inputs / outputs',(-.1,0))
arrow(ax,(.60,.68),(.75,.39),'interaction',(.09,0))
arrow(ax,(.44,.29),(.56,.29),
'attacks' if title.startswith('REAL') else 'allowed leakage\nand influence',(0,-.16))
arrow(ax,(.5,.87),(.5,.94),'',two=False)
ax.text(.5,1.075,'decision bit',ha='center',fontsize=9)
fig.text(.5,.065,'Compare the distribution of Z\'s decision bit. For each A, one S must work for every allowed Z.',
ha='center',fontsize=10)
fig.savefig('uc-real-ideal-experiments.png', dpi=120, facecolor='white')