quang
2022-1-12 08:03:10

Hi everyone, is there a way to distribute a Racket library without publishing its source code? There is load function to load a rkt file, and load/use-compiled function is used for loading .zo file?


alexharsanyi
2022-1-12 09:41:34

Yes it is possible to distribute a library as binary only, but there are a few things to be aware of: binary code is specific to a Racket version, so you will need to supply binaries for each Racket version you want your library to be used with. Also, if your library uses any extra packages from http://pkgs.racket-lang.org\|pkgs.racket-lang.org, you will need to pin down the versions of the packages you depend on by creating a catalog, since http://pkgs.racket-lang.org\|pkgs.racket-lang.org will only supply the latest version of a package.


quangluongtm
2022-1-12 12:20:23

Dumb question but how can you call a function given only .zo and .dep files?


soegaard2
2022-1-12 13:14:21

The .zo file contains the name of the function and the “machinecode” to evaluate when the function is called.

I am not 100% sure how they work using the new Chez Scheme backend. In the old BC backend the zo-files contained bytecode. The bytecode were instructions for a virtual machine that had operations like “create new function”. Allocate new datum. Etc.


ben.knoble
2022-1-12 13:53:59

One q: why do this? From a security perspective, I have to imagine it’s possible to reasonably decompile things…


soegaard2
2022-1-12 13:55:58

It’s pretty low-level so it would take considerable effort. Just like going from real machine code to source code.

https://docs.racket-lang.org/raco/decompile.html#%28def._%28%28lib._compiler%2Fzo-structs..rkt%29._zo%29%29


ben.knoble
2022-1-12 14:10:05

Sure, but people have disassembled/decompiled retro games and all kinds of other things. I’m just arguing that, with enough dedication, it could be done, so you’re still at risk of exposing some source. Which doesn’t matter if you’re not doing this for security. But if you are… this isn’t really what I would call “secure,” but it depends on your threat model I suppose.


samth
2022-1-12 15:01:50

With Racket CS, the code is machine code, so you’d need different versions per architecture/OS


samth
2022-1-12 15:02:11

You can also distribute zo files with machine-independent byte code (basically fully expanded s-exps)


samth
2022-1-12 15:02:59

The machine code would be relatively tricky to decompile, the Racket BC bytecode much less so, and the machine independent bytecode even easier


sschwarzer
2022-1-12 15:06:48

From the initial question I had assumed that this was for “intellectual property” reasons, not for security. I agree with @ben.knoble that relying on obfuscation by having machine code wouldn’t be effective. So if security comes into play here, the obfuscation could only be an additional obstacle, not the basis for a (not) secure software.


ben.knoble
2022-1-12 15:26:09

Even for IP, probably not a great solution, but I’ll get off my soapbox :slightly_smiling_face:


simonec
2022-1-12 16:00:13

@simonec has joined the channel


dan.ml.901
2022-1-13 01:27:48

For Racket 8.1 can anyone tell me if dynamic-require would be much slower than an equivalent require?


sorawee
2022-1-13 05:28:38

require is done at compile-time, but dynamic-require is done at run-time, so they are not really comparable