Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know (or remember) how breaking class laws could cause problems in GHC?

Some time after I asked What happens to you if you break the monad laws? I stumbled across this unexplained phrase on Haskell Wiki, on a page about Safely running untrusted haskell code:

"creating class instances that violate assumed laws (cf EvilIx)"

as an example of an exploit that was possible against lambdabot.

Since lambdabot uses GHC presumably this was a bug (or feature) of GHC making assumptions about class laws. Does anyone remember what those are? And has this ever (or could it possibly) happen acidentally?

(googling for "haskell +Evillx" turns up no hits).

like image 348
Owen Avatar asked Aug 07 '11 02:08

Owen


2 Answers

Arrays use Ix to manage bounds. They trust that Ix does what it says. If it doesn't, you can trick the array mechanisms into accessing memory locations that aren't theirs.

cf EvilIx: http://www.haskell.org/pipermail/haskell-cafe/2006-December/019994.html

like image 79
sclv Avatar answered Sep 20 '22 23:09

sclv


If we think of a monad as modelling side effects, a type claiming to be a monad but not obeying the laws can result in effects occurring in the wrong order or the wrong number of times.

A classic example of this is ListT, the list monad transformer. The original implementation didn't satisy the monad laws. The "ListT Done Right wiki page has some simple examples of usage of ListT in the section called "Examples". You can see the difference between what these programs do when you run them with the original implementation that violates the laws, and when you run them with a replacement that satisfies the laws.

like image 26
Yitz Avatar answered Sep 18 '22 23:09

Yitz