Skip to content

Commit

Permalink
Remove unnecessary validation of Data
Browse files Browse the repository at this point in the history
Close to the release of Alonzo, we improved the format of `Data` to
allow arbitrary-size integers and bytestrings by requiring them to be
encoded in CBOR using indefinite-length bytestrings. This means that the
client-side validation performed by the API was never necessary, and can
be removed.
  • Loading branch information
michaelpj authored and newhoggy committed Mar 17, 2023
1 parent 168b92b commit 2efdd2c
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions cardano-api/src/Cardano/Api/ScriptData.hs
Expand Up @@ -246,13 +246,12 @@ validateScriptData d =
[] -> Right ()
err:_ -> Left err
where
-- collect all errors in a monoidal fold style:
collect (ScriptDataNumber n) =
[ ScriptDataNumberOutOfRange n
| n > fromIntegral (maxBound :: Word64)
|| n < negate (fromIntegral (maxBound :: Word64))
]
collect ScriptDataBytes{} = []
-- Arbitrary size numbers are fine
collect (ScriptDataNumber _) = []

-- Arbitrary sized bytes are fine
collect (ScriptDataBytes _) = []

collect (ScriptDataList xs) =
foldMap collect xs

Expand All @@ -261,36 +260,28 @@ validateScriptData d =
<> collect v)
kvs

-- Constr tags do need to be less than a Word64
collect (ScriptDataConstructor n xs) =
[ ScriptDataConstructorOutOfRange n
| n > fromIntegral (maxBound :: Word64) || n < 0 ]
<> foldMap collect xs

-- | An error in script data due to an out-of-range value.
--
data ScriptDataRangeError =

-- | The number is outside the maximum range of @-2^64-1 .. 2^64-1@.
--
ScriptDataNumberOutOfRange !Integer
newtype ScriptDataRangeError =

-- | The number is outside the maximum range of @-2^64-1 .. 2^64-1@.
--
| ScriptDataConstructorOutOfRange !Integer
ScriptDataConstructorOutOfRange Integer
deriving (Eq, Show)

instance Error ScriptDataRangeError where
displayError (ScriptDataNumberOutOfRange n) =
"Number in script data value "
<> show n
<> " is outside the range -(2^64-1) .. 2^64-1."
displayError (ScriptDataConstructorOutOfRange n) =
"Constructor numbers in script data value "
<> show n
<> " is outside the range 0 .. 2^64-1."



-- ----------------------------------------------------------------------------
-- JSON conversion
--
Expand Down

0 comments on commit 2efdd2c

Please sign in to comment.