-
Notifications
You must be signed in to change notification settings - Fork 513
Add a with-crypto cabal flag to build Plinth/Plutus scripts without system crypto C libraries
#7827
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
Open
zeme-wana
wants to merge
4
commits into
master
Choose a base branch
from
with-crypto-flag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
12 changes: 12 additions & 0 deletions
12
plutus-core/changelog.d/20260702_115332_lorenzo.calegari_with_crypto_flag.md
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ### Added | ||
|
|
||
| - A new `with-crypto` Cabal flag (enabled by default) for `plutus-core`. When | ||
| disabled (`-with-crypto`), `plutus-core` links no system cryptography C library | ||
| (libsodium / libblst / libsecp256k1): the hash builtins are computed by | ||
| `crypton` (byte-identical — see the `crypto-hash-parity-test`), the BLS12-381 | ||
| constants stay as their real hardcoded values, and the signature-verification | ||
| and BLS12-381 group/pairing operations become compile-only stubs. This lets | ||
| Plinth/Plutus scripts *compile* in environments where those C libraries are not | ||
| installed (Cabal otherwise cannot even solve, because `cardano-crypto-class` | ||
| declares them as `pkgconfig-depends`). Those builtins can still be compiled and | ||
| serialised but not *evaluated*; the default build is unaffected. |
This file contains hidden or 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
25 changes: 25 additions & 0 deletions
25
plutus-core/plutus-core/src/PlutusCore/Crypto/BLS12_381/Error.hs
This file contains hidden or 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,6 +1,31 @@ | ||
| module PlutusCore.Crypto.BLS12_381.Error | ||
| where | ||
|
|
||
| import Data.Bits (testBit) | ||
| import Data.ByteString qualified as BS | ||
|
|
||
| data BLS12_381_Error | ||
| = HashToCurveDstTooBig -- DSTs can be at most 255 bytes long. | ||
| | BadCompressedData -- A compressed point failed structural (length/flag) validation. | ||
| deriving stock (Show) | ||
|
|
||
| {-| Structural validation of a compressed BLS12-381 point, shared by the C-free | ||
| G1 and G2 `uncompress` stubs (@expectedLen@ is 48 for G1, 96 for G2). It checks | ||
| exactly what can be checked without field arithmetic: the length, and the three | ||
| metadata bits of the leading byte -- the compression bit must be set, and if the | ||
| infinity bit is set the encoding must be the canonical @0xc0 00..00@. It | ||
| deliberately does NOT verify that the bytes encode a point on the curve or in the | ||
| subgroup (that needs blst), so it is weaker than the real `blsUncompress`; but it | ||
| rejects the malformed inputs the real decoder rejects on structure alone, rather | ||
| than accepting anything. -} | ||
| checkCompressed :: Int -> BS.ByteString -> Either BLS12_381_Error BS.ByteString | ||
| checkCompressed expectedLen bs | ||
| | BS.length bs /= expectedLen = Left BadCompressedData | ||
| | not (testBit b0 7) = Left BadCompressedData -- must be the compressed form | ||
| | testBit b0 6 = -- point at infinity: must be exactly 0xc0 00..00 | ||
| if b0 == 0xc0 && BS.all (== 0) (BS.drop 1 bs) | ||
| then Right bs | ||
| else Left BadCompressedData | ||
| | otherwise = Right bs | ||
| where | ||
| b0 = BS.head bs | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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'd rather not have this duplicate validation logic that's originally in the blst c library.
\_ _ -> Left (CryptoDisabled :: BLS12_381_Error)would be sufficient