kkrt-labs / cairo-vm-ts

A typescript implementation of the Cairo VM
Apache License 2.0
20 stars 13 forks source link

feat: add Output builtin #78

Closed zmalatrax closed 5 months ago

zmalatrax commented 5 months ago

Closes #65

To find the index of the Output segment, we rely on the fact that builtins are always initialized after the Program and Execution segments (rationale for the outputIdx + 2)

Layouts should enforce the builtins order, with output always being the first one. therefore we could simply return runner.vm.memory.segments[2] in getOutput. However layout/builtin order is not enforced atm so programs which uses builtins in a different order, like % builtins bitwise output can run on our VM (whereas the cairo VM in python throws as the builtins are not ordered as expected). This can be updated when implementing layouts.

Python implementation of the Output builtin implements a PublicMemoryPage dictionnary which seems to be only used in the starknetOS & bootloader. There is no need to implement such structure for now imo