Skip to content

Commit fb19ec4

Browse files
committed
- boundses in data fixed
1 parent e37bdca commit fb19ec4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/Web3Core/EthereumABI/ABIElements.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ extension ABI.Element.Function {
397397
/// 4) `messageLength` is used to determine where message bytes end to decode string correctly.
398398
/// 5) The rest of the `data` must be 0 bytes or empty.
399399
if data.bytes.count >= 100,
400-
Data(data[data.indices.startIndex..<data.indices.startIndex + 4]) == Data.fromHex("08C379A0"),
401-
BigInt(data[data.indices.startIndex + 4..<data.indices.startIndex + 36]) == 32,
402-
let messageLength = Int(Data(data[data.indices.startIndex + 36..<data.indices.startIndex + 68]).toHexString(), radix: 16),
400+
Data(data[data.indices.startIndex ..< data.indices.startIndex + 4]) == Data.fromHex("08C379A0"),
401+
BigInt(data[data.indices.startIndex + 4 ..< data.indices.startIndex + 36]) == 32,
402+
let messageLength = Int(Data(data[data.indices.startIndex + 36 ..< data.indices.startIndex + 68]).toHexString(), radix: 16),
403403
let message = String(bytes: data.bytes[68..<(68+messageLength)], encoding: .utf8),
404404
(68+messageLength == data.count || data.bytes[68+messageLength..<data.count].reduce(0) { $0 + $1 } == 0) {
405405
return ["_success": false,
@@ -410,11 +410,11 @@ extension ABI.Element.Function {
410410

411411
if data.count >= 4,
412412
let errors = errors,
413-
let customError = errors[data[data.indices.startIndex + 0..<data.indices.startIndex + 4].toHexString().stripHexPrefix()] {
413+
let customError = errors[data[data.indices.startIndex + 0 ..< data.indices.startIndex + 4].toHexString().stripHexPrefix()] {
414414
var errorResponse: [String: Any] = ["_success": false, "_abortedByRevertOrRequire": true, "_error": customError.errorDeclaration]
415415

416416
if (data.count > 32 && !customError.inputs.isEmpty),
417-
let decodedInputs = ABIDecoder.decode(types: customError.inputs, data: Data(data[data.indices.startIndex + 4..<data.indices.startIndex + data.count])) {
417+
let decodedInputs = ABIDecoder.decode(types: customError.inputs, data: Data(data[data.indices.startIndex + 4 ..< data.indices.startIndex + data.count])) {
418418
for idx in decodedInputs.indices {
419419
errorResponse["\(idx)"] = decodedInputs[idx]
420420
if !customError.inputs[idx].name.isEmpty {

0 commit comments

Comments
 (0)