A Technical Overview of the 'fenv'

Hey all,

I’ve been messing around with getfenv/setfenv for a while now, going so far as to design an entire framework around the concept despite some of it’s noted drawbacks (and despite it being a bit cursed).

Topic

I’d like to know the full technical details of the effects of modifying the function environment (‘fenv’).
Doing a bit of digging, I’ve found that it’s mostly discouraged for the reasons of:

  • Making the environment ‘tainted’, which would remove the guarantee of being able to access variables like math and Vector3.
  • Disabling certain Luau optimizations
  • Potentially allowing exploiters to access certain variables

Goal

My goal with this post is to hopefully compile everything the community knows about getfenv/setfenv into a single thread, so that any potential confusion regarding the subject matter can be alleviated.

So as such, I pose the following questions:

  • Does using just using getfenv taint the environment (i.e. reading it) taint the environment, or does the function environment actually have to be modified?
  • Is there a variable, or some other way to detect if the environment has been tainted?
  • Is there a way to lock the function environment, so that it cannot be modified?
  • When the function environment is tainted, does this affect only that script, or the entire game?
  • When the function environment changes, what specific optimizations are disabled?
    – How does this effect manifest itself during runtime?
    – How bad are the effects, depending on game complexity?
  • Exploiters (especially creative ones) can already get their hands on any scripts running locally. How would injecting variables into the environment make things worse?

Additional Posts

These topic somewhat address the topic in question, but are not necessarily fully conclusive:

Tags (for searching purposes)

getfenv, setfenv, function environment, fenv
2 Likes