-
Notifications
You must be signed in to change notification settings - Fork 481
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
Make NumBytesCostedAsNumWords use Integer instead of Int #6350
Merged
effectfully
merged 6 commits into
master
from
kwxm/costing/fix-NumBytesCostedAsNumWords
Jul 29, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40945ad
Make NumBytesCostedAsNumWords use Integer instead of Int
kwxm 6b7460d
Improve formatting
kwxm b6d9d45
Update tests
kwxm 7a1faff
Update tests
kwxm 21e9952
Fix some budgeting tests
kwxm 5c76623
Forgot about PlutusTx
kwxm 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
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ module Evaluation.Builtins.Conversion ( | |
|
||
import Evaluation.Builtins.Common (typecheckEvaluateCek) | ||
import PlutusCore qualified as PLC | ||
import PlutusCore.Bitwise (integerToByteStringMaximumOutputLength) | ||
import PlutusCore.Bitwise qualified as Bitwise (maximumOutputLength) | ||
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults (defaultBuiltinCostModelForTesting) | ||
import PlutusCore.MkPlc (builtin, mkConstant, mkIterAppNoAnn) | ||
import PlutusPrelude (Word8, def) | ||
|
@@ -47,7 +47,7 @@ i2bProperty1 = do | |
e <- forAllWith ppShow Gen.bool | ||
-- We limit this temporarily due to the limit imposed on lengths for the | ||
-- conversion primitive. | ||
d <- forAllWith ppShow $ Gen.integral (Range.constant 0 integerToByteStringMaximumOutputLength) | ||
d <- forAllWith ppShow $ Gen.integral (Range.constant 0 Bitwise.maximumOutputLength) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should be using the fancy |
||
let actualExp = mkIterAppNoAnn (builtin () PLC.IntegerToByteString) [ | ||
mkConstant @Bool () e, | ||
mkConstant @Integer () d, | ||
|
@@ -68,7 +68,7 @@ i2bProperty2 = do | |
e <- forAllWith ppShow Gen.bool | ||
-- We limit this temporarily due to the limit imposed on lengths for the | ||
-- conversion primitive. | ||
k <- forAllWith ppShow $ Gen.integral (Range.constant 1 integerToByteStringMaximumOutputLength) | ||
k <- forAllWith ppShow $ Gen.integral (Range.constant 1 Bitwise.maximumOutputLength) | ||
j <- forAllWith ppShow $ Gen.integral (Range.constant 0 (k-1)) | ||
let actualExp = mkIterAppNoAnn (builtin () PLC.IntegerToByteString) [ | ||
mkConstant @Bool () e, | ||
|
@@ -406,9 +406,8 @@ i2bCipExamples = [ | |
-- inputs close to the maximum size. | ||
i2bLimitTests ::[TestTree] | ||
i2bLimitTests = | ||
let maxAcceptableInput = 2 ^ (8*integerToByteStringMaximumOutputLength) - 1 | ||
maxAcceptableLength = integerToByteStringMaximumOutputLength -- Just for brevity | ||
maxOutput = fromList (take (fromIntegral integerToByteStringMaximumOutputLength) $ repeat 0xFF) | ||
let maxAcceptableInput = 2 ^ (8*Bitwise.maximumOutputLength) - 1 | ||
maxOutput = fromList (take (fromIntegral Bitwise.maximumOutputLength) $ repeat 0xFF) | ||
makeTests endianness = | ||
let prefix = if endianness | ||
then "Big-endian, " | ||
|
@@ -427,7 +426,7 @@ i2bLimitTests = | |
in evaluateAssertEqual expectedExp actualExp, | ||
-- integerToByteString maxLen maxInput = 0xFF...FF | ||
testCase (prefix ++ "maximum acceptable input, maximum acceptable length argument") $ | ||
let actualExp = mkIntegerToByteStringApp maxAcceptableLength maxAcceptableInput | ||
let actualExp = mkIntegerToByteStringApp Bitwise.maximumOutputLength maxAcceptableInput | ||
expectedExp = mkConstant @ByteString () maxOutput | ||
in evaluateAssertEqual expectedExp actualExp, | ||
-- integerToByteString 0 (maxInput+1) fails | ||
|
@@ -436,16 +435,16 @@ i2bLimitTests = | |
in evaluateShouldFail actualExp, | ||
-- integerToByteString maxLen (maxInput+1) fails | ||
testCase (prefix ++ "input too big, maximum acceptable length argument") $ | ||
let actualExp = mkIntegerToByteStringApp maxAcceptableLength (maxAcceptableInput + 1) | ||
let actualExp = mkIntegerToByteStringApp Bitwise.maximumOutputLength (maxAcceptableInput + 1) | ||
in evaluateShouldFail actualExp, | ||
-- integerToByteString (maxLen-1) maxInput fails | ||
testCase (prefix ++ "maximum acceptable input, length argument not big enough") $ | ||
let actualExp = mkIntegerToByteStringApp (maxAcceptableLength - 1) maxAcceptableInput | ||
let actualExp = mkIntegerToByteStringApp (Bitwise.maximumOutputLength - 1) maxAcceptableInput | ||
in evaluateShouldFail actualExp, | ||
-- integerToByteString _ (maxLen+1) 0 fails, just to make sure that | ||
-- we can't go beyond the supposed limit | ||
testCase (prefix ++ "input zero, length argument over limit") $ | ||
let actualExp = mkIntegerToByteStringApp (maxAcceptableLength + 1) 0 | ||
let actualExp = mkIntegerToByteStringApp (Bitwise.maximumOutputLength + 1) 0 | ||
in evaluateShouldFail actualExp | ||
] | ||
in makeTests True ++ makeTests False | ||
|
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
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.
Create a Note, given that this reasoning is copied multiple times?