Open sbellem opened 4 years ago
ratelang
ratel.py
module such that it should be extract-able out of the vyper
code base, although some testing objects from the vyper
codebase are useful. So for now it is easier to keep the ratel
code alongside vyper
.RatelCompiler
takes a hybrid vyper/hbmpc contract source code and outputs the vyper expected output & the mpc source code (as a string for now): https://github.com/sbellem/vyper/blob/f9bdabf0a231bcc042811c8a4a4b5c4fd2257359/ratel/ratel.py#L94-L116class RatelCompiler:
# ...
def compile(
self,
contract_source,
*,
vyper_output_formats=None,
vyper_interface_codes=None,
evm_version=DEFAULT_EVM_VERSION,
mpc_output_formats=None
):
"""Compiles the given contract source code."""
if mpc_output_formats:
raise NotImplementedError
else:
mpc_output_formats = ("src_code",)
vyper_code, mpc_code = self._extract_codes(contract_source)
vyper_output = vyper_compiler.compile_code(
vyper_code,
output_formats=vyper_output_formats,
interface_codes=vyper_interface_codes,
evm_version=evm_version,
)
mpc_output = {"src_code": self._mpc_code}
return {"vyper": vyper_output, "mpc": mpc_output}
exec(mpc_src_code, globals())
works to load the mpc application specific code, which means that https://github.com/sbellem/HoneyBadgerMPC/blob/f0180ea12e1a5ee88406bbcce876377815e756e2/apps/masks/mpcserver.py#L392-L425 ##########################################################################
#
# MPC program
#
# IDEA: will come from hbmpc aka ratel contract.
async def _prog(ctx, *, field_element):
logging.info(f"[{ctx.myid}] Running MPC network")
msg_share = ctx.Share(field_element)
opened_value = await msg_share.open()
opened_value_bytes = opened_value.value.to_bytes(32, "big")
logging.info(f"opened_value in bytes: {opened_value_bytes}")
msg = opened_value_bytes.decode().strip("\x00")
return msg
##########################################################################
asyncio.run(
main(
"sid",
myid,
host=host,
mpc_port=mpc_port,
peers=peers,
# node_communicator=node_communicator,
w3=w3,
contract_context=contract_context,
db=db,
http_context={"host": host, "port": http_port},
preprocessor_class=PreProcessor,
httpserver_class=HTTPServer,
mpcprogrunner_class=MPCProgRunner,
prog=_prog,
)
)
could become
##########################################################################
#
# MPC program
#
# IDEA: will come from hbmpc aka ratel contract.
ratel_compiler = RatelCompiler()
out = ratel_compiler.compile(
mpc_contract_code, vyper_output_formats=["abi", "bytecode"],
)
vyper_source = ratel_compiler._vyper_code
# get vyper contract context ...
# ...
mpc_output = out["mpc"]
mpc_src_code = mpc_output["src_code"]
exec(mpc_src_code, globals())
##########################################################################
asyncio.run(
main(
"sid",
myid,
host=host,
mpc_port=mpc_port,
peers=peers,
# node_communicator=node_communicator,
w3=w3,
contract_context=contract_context,
db=db,
http_context={"host": host, "port": http_port},
preprocessor_class=PreProcessor,
httpserver_class=HTTPServer,
mpcprogrunner_class=MPCProgRunner,
prog=_prog,
)
)
Issue to post notes and updates.
To post something, write it as a comment.