lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thank you, Tom and Gé, for your thoughtful responses.  They have given me lots to think about!

In practice, I am struggling to conjure a scenario that produces different results on each run.  Banning __gc metamethods, as Tom suggests, is no trouble, and I've already gone ahead and redefined tostring to prevent it from leaking memory address information.  Without those two things, how else can I actually get non-deterministic behavior?  On all the machines I've tried so far, for instance, the script Gé provided appears to produce identical output on every run.  I understand the Lua specification doesn't guarantee that behavior, but it would be handy to find a simple example that actually produces reliably non-deterministic results (or at least results that change with each executin).  If anyone has any ideas about how to do this, or has done it before, I'd really appreciate your input.

Best,
~Luke

On Tue, Sep 25, 2018 at 6:32 PM Gé Weijers <ge@weijers.org> wrote:


On Sun, Sep 23, 2018 at 9:56 AM Tom Sutcliffe <tomsci@me.com> wrote:

If the GC step and mul parameters are set the same, then the GC will behave _mostly_ identically on any machine running the exact same Lua binary (in particular 32- and 64-bit builds will be different even when still on x86 - different architectures will have different sizes for data structures which will affect collection logic). You would have to control for anything discernibly different about the environment that scripts can detect - any API that could return a different-sized result on different machines (even down to eg localisation of date formats, if those APIs are exposed). And I'm assuming your subset of the language locks down most things that could have side-effects

The interpreter uses a randomized 'seed' for the hash, to make it harder to perform attacks using hash collisions. If you run this script multiple times the results are printed in a different order.

local T = {}
for i = 1, 10 do
T[("X%d"):format(i)] = 1
end
for k in pairs(T) do
print(k)
end

Another problem: you can 'observe' the garbage collector at work by using the __gc metamethod and/or weak tables, and a script's result can easily depend on whether a key or value is present in a weak table or whether the function referenced by __gc executes.

Out of the box Lua is quite non-deterministic 🤔


--
--



--
Luke Horgan
Candidate for BS in Computer Science and Computer Engineering
College of Engineering | Northeastern University
luke-horgan.com | 908-577-7902