Select an example:
loading
packages = ["parsial~=0.1", "richreports~=0.2", "asttokens~=2.4"] [[fetch]] files = ['nada_audit.py']
from js import document from pyodide.ffi import create_proxy, to_js import types import json import ast import inspect import asttokens from nada_audit import * def update(_): messages = [] source = \ document.getElementById('payload').innerHTML \ .replace('&' + 'amp;', '&') \ .replace('&' + 'lt;', '<') \ .replace('&' + 'gt;', '>') # Perform static analyses and render the report. try: messages.append(['Information', 'Auditing.']) lines = source.split('\n') report = audit(source) rlines = report.render().split('\n') js.reportDisplay(to_js(rlines)) messages.append( ['Success', 'Auditing step completed.'] ) except Exception as e: messages.append( ['Error', type(e).__name__ + ": " + str(e)] ) # Perform abstract interpretation to determine inputs # and then simulate the program on the inputs (either # randomly generated or user-supplied). try: messages.append(['Information', 'Executing.']) ins = js.interpreterInputsRetrieve().to_py() context = {} Abstract.initialize({k: v for (k, [v, _]) in ins.items()}) exec(source, context) outs = context['nada_main']() if len(outs) > 0: js.interpreterInputsShow(to_js([[i.name, i.ty_str] for i in outs[0].inputs])) js.interpreterOutputsShow( to_js([[o.name, o.value.value] for o in outs[0].outputs]) ) messages.append( ['Success', 'Execution completed.'] ) except Exception as e: messages.append( ['Error', type(e).__name__ + ": " + str(e)] ) # Display all feedback messages collected during the update. js.feedbackDisplay(to_js(messages)); document.addEventListener('update', create_proxy(update)) pyscript.write('report', 'ready') js.resize() js.update()
Interactive Table
JSON
JSON Schema
Interpreter
Simulator
# The left-hand panel can scrolled and edited. The right-hand
# panel will automatically be updated with the results of the
# type checking and cost calculation static analyses. Green
# represents public Nada expressions/values and blue represents
# secret Nada expressions/values.

# On the right-hand panel, hover over variable names to see a
# count of the total number of *secret* operations that must be
# executed to determine the value of that variable at that point
# in the program. There is no deduplication (as in the current
# implementation).

from nada_audit import *

def nada_main():
    party1 = Party(name="Party1")
    my_int1 = PublicInteger(Input(name="my_int1", party=party1))
    my_int2 = SecretInteger(Input(name="my_int2", party=party1))

    new_int = my_int1 * my_int2

    return [Output(new_int, "my_output", party1)]
from nada_audit import *

def nada_main():
    p1 = Party("Party1")
    p2 = Party("Party2")
    p3 = Party("Party3")
    p4 = Party("Party4")
    a = PublicInteger(Input("a", p1))
    b = SecretInteger(Input("b", p1))
    c = PublicInteger(Input("c", p2))
    d = SecretInteger(Input("d", p2))
    e = PublicInteger(Input("e", p3))
    f = SecretInteger(Input("f", p3))

    g = a * b * c * d * e * f

    return [Output(g, "g", p4)]
from nada_audit import *

def nada_main():
    voters = [Party("Party" + str(v)) for v in range(2)]
    outparty = Party(name="OutParty")

    votes_per_candidate = [
        [
            SecretInteger(
                Input(
                    name="v" + str(v) + "_c" + str(c),
                    party=Party("Party" + str(v))
                )
            )
            for v in range(2)
        ]
        for c in range(4)
    ]

    return [
      Output(sum(votes_per_candidate[c]), "c" + str(c), outparty)
      for c in range(4)
    ]
# In this example, note that empty lists must be accompanied by an explicit
# type annotation.

from nada_audit import *

def nada_main():

    # Create the voter parties and recipient party.
    voters: list[Party] = []
    for v in range(2):
        voters.append(Party("Party" + str(v)))
    outparty = Party(name="OutParty")

    # Gather the inputs (one vote for each candidate from each voter).
    votes_per_candidate: list[list[SecretInteger]] = []
    for c in range(4):
        votes_per_candidate.append([])
        for v in range(2):
            votes_per_candidate[c].append(SecretInteger(
                Input(
                    name="v" + str(v) + "_c" + str(c),
                    party=Party("Party" + str(v))
                )
            ))

    # Calculate the total for each candidate.
    outputs: list[Output] = []
    for c in range(4):
        outputs.append(Output(sum(votes_per_candidate[c]), "c" + str(c), outparty))

    return outputs