Skip to content

Commit bc666ca

Browse files
committed
Remove unnecessary validation of Data
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.
1 parent 1e9fd19 commit bc666ca

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

Diff for: cardano-api/src/Cardano/Api/ScriptData.hs

+8-37
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,11 @@ validateScriptData d =
188188
err:_ -> Left err
189189
where
190190
-- collect all errors in a monoidal fold style:
191-
collect (ScriptDataNumber n) =
192-
[ ScriptDataNumberOutOfRange n
193-
| n > fromIntegral (maxBound :: Word64)
194-
|| n < negate (fromIntegral (maxBound :: Word64))
195-
]
196-
collect (ScriptDataBytes bs) =
197-
[ ScriptDataBytesTooLong len
198-
| let len = BS.length bs
199-
, len > scriptDataByteStringMaxLength
200-
]
191+
192+
-- Arbitrary size numbers are fine
193+
collect (ScriptDataNumber _) = []
194+
-- Arbitrary sized bytes are fine
195+
collect (ScriptDataBytes _) = []
201196
collect (ScriptDataList xs) =
202197
foldMap collect xs
203198

@@ -206,51 +201,27 @@ validateScriptData d =
206201
<> collect v)
207202
kvs
208203

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

214210

215-
-- | The maximum length of a script data byte string value.
216-
scriptDataByteStringMaxLength :: Int
217-
scriptDataByteStringMaxLength = 64
218-
219-
220211
-- | An error in script data due to an out-of-range value.
221212
--
222-
data ScriptDataRangeError =
213+
newtype ScriptDataRangeError =
223214

224215
-- | The number is outside the maximum range of @-2^64-1 .. 2^64-1@.
225216
--
226-
ScriptDataNumberOutOfRange !Integer
227-
228-
-- | The number is outside the maximum range of @-2^64-1 .. 2^64-1@.
229-
--
230-
| ScriptDataConstructorOutOfRange !Integer
231-
232-
-- | The length of a byte string metadatum value exceeds the maximum of
233-
-- 64 bytes.
234-
--
235-
| ScriptDataBytesTooLong !Int
217+
ScriptDataConstructorOutOfRange Integer
236218
deriving (Eq, Show)
237219

238220
instance Error ScriptDataRangeError where
239-
displayError (ScriptDataNumberOutOfRange n) =
240-
"Number in script data value "
241-
<> show n
242-
<> " is outside the range -(2^64-1) .. 2^64-1."
243221
displayError (ScriptDataConstructorOutOfRange n) =
244222
"Constructor numbers in script data value "
245223
<> show n
246224
<> " is outside the range 0 .. 2^64-1."
247-
displayError (ScriptDataBytesTooLong actualLen) =
248-
"Byte strings in script data must consist of at most "
249-
<> show scriptDataByteStringMaxLength
250-
<> " bytes, but it consists of "
251-
<> show actualLen
252-
<> " bytes."
253-
254225

255226
-- ----------------------------------------------------------------------------
256227
-- JSON conversion

0 commit comments

Comments
 (0)