-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monad attacks #154
Merged
Merged
Monad attacks #154
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
65a472d
Start experimenting with attacks in an arbitraty monad
carlhammann 8884a28
Try Attack = MockChainSt -> TxSkel -> Maybe (TxSkel, a)
carlhammann e285b24
Rewrite the dupTokenAttack as a combination of smaller attacks
carlhammann efc7eb9
Add tests for the modified dupTokenAttack
carlhammann 396cf7b
Rewrite the datumHijackingAttack in the new language
carlhammann 41244bd
Better rewriting of the datumHijackingAttack
carlhammann 400c50b
Make attacks return lists, revert the LTL module to main
carlhammann 0c545fe
Move 'somewhere' and 'everywhere' to MockChain.Monad.Staged, in order…
carlhammann 22c747f
Tests for datumHijackingAttack; weird behaviour in mkSelectAttack
carlhammann 095e22e
Found the culprit in mkSelectAttack, added regression test
carlhammann 5b0d8f3
Redefine mkAttack and the datumTamperingAttack
carlhammann ed86ecb
Rewrite permutOutAttack and its tests
carlhammann 23e19f7
Reintroduce non-attack tests, remove tests for '<>' on 'Attack's
carlhammann 2f2797e
Status save on doubleSatAttack
carlhammann 418c254
Make an extra module for attacks that add/remove constraints
carlhammann 067a794
Rewrote the doubleSatAttack
carlhammann 801e8ab
Some better comments at the double satisfaction attack
carlhammann 6790089
Rewrite tests for doubleSatAttack
carlhammann a06d47e
Test the addConstraintsAttack
carlhammann 1bc6e25
Adapt the examples to the new attacks
carlhammann 048d77e
Some attacks to add and remove OutConstraints
carlhammann 0e65615
Make cooked export everything
carlhammann d762ca2
Merge branch 'main' into monad-attacks
carlhammann 44d7020
Address Facundo's and Lucas' comments, first half
carlhammann e3ab421
Rework the test for the doubleSatAttack
carlhammann f3389ac
Address more comments from Facundo an Mathieu
carlhammann faae62a
Make some tests more structured, as suggested by Facundo
carlhammann 9038925
Merge branch 'main' into monad-attacks
carlhammann 8f7193d
Incorporate suggestions from Georg
carlhammann 37a2a60
Update cooked-validators/src/Cooked/Attack/AddConstraints.hs
carlhammann 00301d1
Cleanup from the last commit
carlhammann 2ea04ff
Repair 'sameConstraints', yet again
carlhammann a90c621
Merge branch 'main' into monad-attacks
carlhammann 614d0ac
Rename Attack -> Tweak
carlhammann 4d11868
Merge remote-tracking branch 'origin/monad-attacks' into monad-attacks
carlhammann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,6 @@ | ||
module Cooked.Attack | ||
( module Cooked.Attack.Common, | ||
module Cooked.Attack.DatumHijacking, | ||
module Cooked.Attack.DoubleSat, | ||
module Cooked.Attack.DupToken, | ||
module Cooked.Attack.OutPermutations, | ||
module Cooked.Attack.TamperDatum, | ||
) | ||
where | ||
module Cooked.Attack (module X) where | ||
|
||
import Cooked.Attack.Common | ||
import Cooked.Attack.DatumHijacking | ||
import Cooked.Attack.DoubleSat | ||
import Cooked.Attack.DupToken | ||
import Cooked.Attack.OutPermutations | ||
import Cooked.Attack.TamperDatum | ||
|
||
-- The idea of this module: Turning optics into attacks | ||
------------------------------------------------------- | ||
-- | ||
-- In cooked-validators, a _single transaction attack_ on a smart contract is a | ||
-- function that modifies one transaction: An attacker applies this function to | ||
-- a transaction in an otherwise normal chain of transactions, somehow fools the | ||
-- validator script(s), and profits. So, attacks in cooked-valiadators should | ||
-- modify 'TxSkel's. | ||
-- | ||
-- It would be nice to have a collection of parametric attacks, together with an | ||
-- easy way to add new attacks to that collection. This module and its | ||
-- submodules contain the beginnings of such a collection, and also a hopefully | ||
-- useful mechanisms to extend it. | ||
-- | ||
-- Since most attacks are of the form "look deep into the nested data types | ||
-- within a 'TxSkel' and change something", The idea is to use the optics | ||
-- defined in "Cooked.Tx.Constraints.Optics" and turn them into attacks. | ||
-- | ||
-- Optic attack example: Token duplication | ||
------------------------------------------ | ||
-- | ||
-- There's a 'dupTokenAttack' in "Cooked.Attack.DupToken", and its | ||
-- implementation is quite readable; the purpose of the following is not to | ||
-- explain that function in detail, but to motivate how one should write new | ||
-- attacks using this module. | ||
-- | ||
-- A _token duplication_ attack consists in trying to increase the amount of | ||
-- tokens a transaction mints and paying the surplus to an attacker. A naive | ||
-- idea to implement the token duplication attack would then be | ||
-- | ||
-- > naiveDupTokenAttack :: Wallet -> (Value -> Value) -> TxSkel -> TxSkel | ||
-- > naiveDupTokenAttack attacker increaseValue = | ||
-- > paySurplusTo attacker . over (mintsConstraintT % valueL) increaseValue | ||
-- | ||
-- where @paySurplusTo :: Wallet -> TxSkel -> TxSkel@ is a suitable function | ||
-- that modifies a 'TxSkel' to play any extra minted tokens to a given | ||
-- wallet. | ||
-- | ||
-- This is idea is almost right, save for the type of @naiveDupTokenAttack@: If | ||
-- @increaseValue@ did not in fact _change_ any of the minted values, or if | ||
-- there were no 'MintsConstraint's in the transaction under consideration, we | ||
-- have no way to detect this failure. Also, depending on the current state of | ||
-- the 'MockChain' there might be more than one possibly interesting way to | ||
-- modify the initial transaction. That's why we set | ||
-- | ||
-- > type Attack = MockChainSt -> TxSkel -> [TxSkel] | ||
-- | ||
-- and the module "Cooked.Attack.Common" provides functions like | ||
-- | ||
-- > mkAttack :: Is k A_Traversal => Optic' k is TxSkel a -> (a -> Maybe a) -> Attack | ||
-- | ||
-- which is a kind of "'over' with failure": The list of modified 'TxSkel's | ||
-- returned by @mkAttack optic f state skel@ will be nonempty if and only if | ||
-- | ||
-- - the @optic@ being used in the attack has at least one focus on the input | ||
-- @skel@, and | ||
-- | ||
-- - the function @f@ returns @Just@ on at least one of the foci. | ||
-- | ||
-- In that case, the returned list will contain exactly one modified 'TxSkel', | ||
-- with all foci modified by @f@. | ||
-- | ||
-- There are also other functions like 'mkAttack' that return more than one | ||
-- modification in "Cooked.Attack.Common". | ||
-- | ||
-- Note that we can use 'mkAttack' (or a similar fuction) to write | ||
-- 'dupTokenAttack' in a contract-agnostic manner. Also note that, despite | ||
-- (because?) of the generality of such attacks, they are relatively easy to | ||
-- implement. Our growing collection of optics in "Cooked.Tx.Constraints.Optics" | ||
-- and other helpers will hopefully mean that it will become easier and easier | ||
-- to write attacks. | ||
import Cooked.Attack.DatumHijacking as X | ||
import Cooked.Attack.DoubleSat as X | ||
import Cooked.Attack.DupToken as X | ||
import Cooked.Attack.Tweak as X |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still unsure that the single steps modifications should be called attacks. Why not