Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ extension Accumulation {
for transfer in accumulateOutput.transfers {
transferGroups[transfer.destination, default: []].append(transfer)
}

logger.debug("transfer groups: \(transferGroups)")

for (service, transfers) in transferGroups.sorted(by: { $0.key < $1.key }) {
let gasUsed = try await onTransfer(
config: config,
Expand All @@ -656,6 +659,7 @@ extension Accumulation {
)
let count = UInt32(transfers.count)
if count == 0 { continue }
logger.debug("transfer complete: service: \(service), transfers count: \(count), gasUsed: \(gasUsed)")
transfersStats[service] = (count, gasUsed)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Codec
import Utils

public struct AvailabilitySpecifications: Sendable, Equatable, Codable {
// h
// p
public var workPackageHash: Data32

// l
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PolkaVM
import TracingUtils
import Utils

private let logger = Logger(label: "HostCall ")

Expand All @@ -16,7 +17,7 @@ extension HostCall {
state.consumeGas(gasCost(state: state))
logger.debug("consumed \(gasCost(state: state)) gas, \(state.getGas()) left")

guard hasEnoughGas(state: state) else {
guard state.getGas() >= GasInt(0) else {
logger.debug("not enough gas")
return .exit(.outOfGas)
}
Expand All @@ -43,8 +44,4 @@ extension HostCall {
public func gasCost(state _: VMState) -> Gas {
Gas(10)
}

func hasEnoughGas(state: VMState) -> Bool {
Gas(state.getGas()) >= gasCost(state: state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public class Read: HostCall {
nil
}

logger.debug("value: \(value?.toHexString() ?? "nil")")

guard let value else {
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.NONE.rawValue)
return
Expand All @@ -311,7 +313,7 @@ public class Read: HostCall {
throw VMInvocationsError.panic
} else {
state.writeRegister(Registers.Index(raw: 7), value.count)
logger.debug("val: \(value[relative: first ..< (first + len)].toDebugHexString())")
logger.debug("writing val: \(value[relative: first ..< (first + len)].toDebugHexString())")
try state.writeMemory(address: regs[2], values: value[relative: first ..< (first + len)])
}
}
Expand Down Expand Up @@ -430,7 +432,7 @@ public class Info: HostCall {
let first = min(Int(reg9), value?.count ?? 0)
let len = min(Int(reg10), (value?.count ?? 0) - first)

let isWritable = value != nil && state.isMemoryWritable(address: o, length: len)
let isWritable = state.isMemoryWritable(address: o, length: len)

logger.debug("value: \(value?.debugDescription ?? "nil"), isWritable: \(isWritable)")

Expand Down Expand Up @@ -797,15 +799,12 @@ public class Bless: HostCall {
var alwaysAcc: [ServiceIndex: Gas]?
let length = 12 * Int(regs[4])
if state.isMemoryReadable(address: regs[3], length: length) {
alwaysAcc = [:]
let data = try state.readMemory(address: regs[3], length: length)
for i in stride(from: 0, to: length, by: 12) {
let serviceIndex = ServiceIndex(data[i ..< i + 4].decode(UInt32.self))
let gas = Gas(data[i + 4 ..< i + 12].decode(UInt64.self))
if alwaysAcc != nil {
alwaysAcc![serviceIndex] = gas
} else {
alwaysAcc = [serviceIndex: gas]
}
alwaysAcc![serviceIndex] = gas
}
}

Expand Down Expand Up @@ -848,11 +847,9 @@ public class Assign: HostCall {
var authorizationQueue: [Data32]?
let length = 32 * config.value.maxAuthorizationsQueueItems
if state.isMemoryReadable(address: startAddr, length: length) {
authorizationQueue = []
let data = try state.readMemory(address: startAddr, length: length)
for i in stride(from: 0, to: length, by: 32) {
if authorizationQueue == nil {
authorizationQueue = [Data32]()
}
authorizationQueue!.append(Data32(data[i ..< i + 32])!)
}
}
Expand Down Expand Up @@ -891,11 +888,9 @@ public class Designate: HostCall {
var validatorQueue: [ValidatorKey]?
let length = 336 * config.value.totalNumberOfValidators
if state.isMemoryReadable(address: startAddr, length: length) {
validatorQueue = []
let data = try state.readMemory(address: startAddr, length: length)
for i in stride(from: 0, to: length, by: 336) {
if validatorQueue == nil {
validatorQueue = [ValidatorKey]()
}
try validatorQueue!.append(ValidatorKey(data: Data(data[i ..< i + 336])))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class OnTransferContext: InvocationContext {
}

public func dispatch(index: UInt32, state: VMState) async -> ExecOutcome {
logger.debug("dispatching host-call: \(index)")
switch UInt8(index) {
case GasFn.identifier:
return await GasFn().call(config: config, state: state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public final class RefineContext: InvocationContext {
}

public func dispatch(index: UInt32, state: VMState) async -> ExecOutcome {
logger.debug("dispatching host-call: \(index)")

switch UInt8(index) {
case GasFn.identifier:
return await GasFn().call(config: config, state: state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public func accumulate(
)
)
let ctx = AccumulateContext(context: contextContent, config: config, timeslot: timeslot, operands: arguments)
let argument = try JamEncoder.encode(UInt(timeslot), UInt(serviceIndex), UInt(arguments.count))
let argumentData = try JamEncoder.encode(UInt(timeslot), UInt(serviceIndex), UInt(arguments.count))

let (exitReason, gas, output) = await invokePVM(
config: config,
blob: codeBlob,
pc: 5,
gas: gas,
argumentData: argument,
argumentData: argumentData,
ctx: ctx
)

Expand Down
2 changes: 1 addition & 1 deletion Codec/Sources/Codec/Compact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public protocol CompactEncodable {

/// A coding wrapper that converts CompactEncodable types to UInt for compact encoding/decoding.
/// This supports both Swift's built-in integer types and custom types that conform to CompactEncodable.
public struct Compact<T: CompactEncodable & Codable>: Codable, CodableAlias {
public struct Compact<T: CompactEncodable & Codable & Sendable>: Codable, CodableAlias, Sendable {
public typealias Alias = T

public var alias: T
Expand Down
11 changes: 2 additions & 9 deletions JAMTests/Sources/JAMTests/TestLoader.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Blockchain
import Foundation

// somehow without this the GH Actions CI fails
extension Foundation.Bundle: @unchecked @retroactive Sendable {}

public struct Testcase: CustomStringConvertible, Sendable {
public var description: String
public var data: Data
Expand All @@ -21,13 +18,9 @@ public enum TestVariants: String, CaseIterable {
public var config: ProtocolConfigRef {
switch self {
case .tiny:
var tiny = ProtocolConfigRef.tiny
tiny = tiny.mutate {
$0.preimagePurgePeriod = 32
}
return tiny
ProtocolConfigRef.tiny
case .full:
return ProtocolConfigRef.mainnet
ProtocolConfigRef.mainnet
}
}
}
Expand Down
67 changes: 66 additions & 1 deletion JAMTests/Tests/JAMTests/jamtestnet/FuzzTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,75 @@ struct FuzzTests {
// example: ("0.7.0/1754982630", "00000004")
],
ignore: [
// traces
]
))
func v070(_ input: Testcase) async throws {
try await TraceTest.test(input)
}

@Test(arguments: try loadTests(
version: "0.7.0/_new",
filters: [
],
ignore: [
// TODO: revisit these later
("0.7.0/_new/1758621171", "00000236"), // used more gas
("0.7.0/_new/1758621171", "00000237"), // used more gas, 2 services
("0.7.0/_new/1758621172", "00000038"), // used more gas
("0.7.0/_new/1758621173", "00000045"), // used more gas
("0.7.0/_new/1758621412", "00000024"), // used more gas: 136 (init data is set)
("0.7.0/_new/1758621412", "00000025"), // used more gas, and 1 storage mismatch
("0.7.0/_new/1758621498", "00000024"), // used more gas: 136
("0.7.0/_new/1758621498", "00000025"), // used more gas, and 1 storage mismatch
("0.7.0/_new/1758621547", "00000032"), // used more gas, and 1 storage mismatch
("0.7.0/_new/1758621879", "00000348"), // used more gas
("0.7.0/_new/1758621952", "00000291"), // used more gas: 136 (init data is set)
("0.7.0/_new/1758621952", "00000292"), // many (seems manager service 0 need to change delegator to 3436841821)
("0.7.0/_new/1758622000", "00000230"), // used more gas (0: 363, 2052168113: 136)
("0.7.0/_new/1758622051", "00000093"), // used more gas
("0.7.0/_new/1758622051", "00000094"), // used more gas
("0.7.0/_new/1758622104", "00000022"), // many
("0.7.0/_new/1758622160", "00000009"), // used more gas
("0.7.0/_new/1758622313", "00000012"), // used more gas
("0.7.0/_new/1758622403", "00000238"), // used more gas, and 1 storage mismatch
("0.7.0/_new/1758622403", "00000239"), // used more gas, and privileged service mismatch
("0.7.0/_new/1758622442", "00000163"), // used more gas
("0.7.0/_new/1758622442", "00000164"), // used more gas, and privileged service mismatch
("0.7.0/_new/1758622524", "00000038"), // used more gas
("0.7.0/_new/1758622524", "00000039"), // used more gas
]
))
func v070new1(_ input: Testcase) async throws {
try await TraceTest.test(input)
}

@Test(arguments: try loadTests(
version: "0.7.0/_new2",
filters: [
],
ignore: [
// TODO: revisit these later
("0.7.0/_new2/1758636775", "00000013"), // used more gas
("0.7.0/_new2/1758636775", "00000014"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758636819", "00000022"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758636961", "00000018"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637024", "00000017"), // used more gas
("0.7.0/_new2/1758637024", "00000018"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637136", "00000019"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637250", "00000015"), // used more gas
("0.7.0/_new2/1758637250", "00000016"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637297", "00000015"), // used more gas
("0.7.0/_new2/1758637297", "00000016"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637332", "00000016"), // used more gas
("0.7.0/_new2/1758637332", "00000017"), // used more gas
("0.7.0/_new2/1758637363", "00000023"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637447", "00000061"), // used more gas, and 1 storage mismatch
("0.7.0/_new2/1758637447", "00000062"), // used more gas, and 2 storage mismatch
("0.7.0/_new2/1758637485", "00000019"), // used more gas, and 2 storage mismatch
("0.7.0/_new2/1758708840", "00000958"), // error (exp post state is empty)
]
))
func v070new2(_ input: Testcase) async throws {
try await TraceTest.test(input)
}
}
23 changes: 10 additions & 13 deletions JAMTests/Tests/JAMTests/w3f/TrieTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ struct TrieTests {

@Test(arguments: try loadTests())
func trieTests(_ testcase: Testcase) throws {
withKnownIssue("TODO: outdated key type", isIntermittent: true) {
let decoder = JSONDecoder()
let testcase = try decoder.decode(TrieTestCase.self, from: testcase.data)
for element in testcase {
let kv = element.input.reduce(into: [Data31: Data]()) { result, entry in
let keyData = Data(fromHexString: entry.key)
let valueData = Data(fromHexString: entry.value)
// result[Data31(keyData!)!] = valueData
result[Data31()] = valueData
}

let result = try stateMerklize(kv: kv)
#expect(result.data.toHexString() == element.output)
let decoder = JSONDecoder()
let testcase = try decoder.decode(TrieTestCase.self, from: testcase.data)
for element in testcase {
let kv = element.input.reduce(into: [Data31: Data]()) { result, entry in
let keyData = Data(fromHexString: entry.key)
let valueData = Data(fromHexString: entry.value)
result[Data31(keyData![relative: 0 ..< 31])!] = valueData
}

let result = try stateMerklize(kv: kv)
#expect(result.data.toHexString() == element.output)
}
}
}
Binary file added JAMTests/fuzz/0.7.0/1757841566/00000199.bin
Binary file not shown.
615 changes: 615 additions & 0 deletions JAMTests/fuzz/0.7.0/1757841566/00000199.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757841566/00000200.bin
Binary file not shown.
564 changes: 564 additions & 0 deletions JAMTests/fuzz/0.7.0/1757841566/00000200.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757842797/00000020.bin
Binary file not shown.
420 changes: 420 additions & 0 deletions JAMTests/fuzz/0.7.0/1757842797/00000020.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757842797/00000021.bin
Binary file not shown.
498 changes: 498 additions & 0 deletions JAMTests/fuzz/0.7.0/1757842797/00000021.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757842852/00000034.bin
Binary file not shown.
615 changes: 615 additions & 0 deletions JAMTests/fuzz/0.7.0/1757842852/00000034.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757842852/00000035.bin
Binary file not shown.
564 changes: 564 additions & 0 deletions JAMTests/fuzz/0.7.0/1757842852/00000035.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843609/00000033.bin
Binary file not shown.
961 changes: 961 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843609/00000033.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843609/00000034.bin
Binary file not shown.
917 changes: 917 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843609/00000034.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843719/00000034.bin
Binary file not shown.
1,053 changes: 1,053 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843719/00000034.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843719/00000035.bin
Binary file not shown.
922 changes: 922 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843719/00000035.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843735/00000009.bin
Binary file not shown.
528 changes: 528 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843735/00000009.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757843735/00000010.bin
Binary file not shown.
557 changes: 557 additions & 0 deletions JAMTests/fuzz/0.7.0/1757843735/00000010.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757861618/00000616.bin
Binary file not shown.
998 changes: 998 additions & 0 deletions JAMTests/fuzz/0.7.0/1757861618/00000616.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757861618/00000617.bin
Binary file not shown.
1,155 changes: 1,155 additions & 0 deletions JAMTests/fuzz/0.7.0/1757861618/00000617.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862207/00000489.bin
Binary file not shown.
1,542 changes: 1,542 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862207/00000489.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862207/00000493.bin
Binary file not shown.
1,506 changes: 1,506 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862207/00000493.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862468/00000159.bin
Binary file not shown.
1,864 changes: 1,864 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862468/00000159.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862468/00000160.bin
Binary file not shown.
1,744 changes: 1,744 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862468/00000160.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862472/00000159.bin
Binary file not shown.
1,864 changes: 1,864 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862472/00000159.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862472/00000160.bin
Binary file not shown.
1,744 changes: 1,744 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862472/00000160.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000001.bin
Binary file not shown.
295 changes: 295 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000001.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000002.bin
Binary file not shown.
356 changes: 356 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000002.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000003.bin
Binary file not shown.
372 changes: 372 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000003.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000004.bin
Binary file not shown.
381 changes: 381 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000004.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000005.bin
Binary file not shown.
390 changes: 390 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000005.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000006.bin
Binary file not shown.
390 changes: 390 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000006.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/1757862743/00000007.bin
Binary file not shown.
343 changes: 343 additions & 0 deletions JAMTests/fuzz/0.7.0/1757862743/00000007.json

Large diffs are not rendered by default.

Binary file not shown.
3,484 changes: 3,484 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621171/00000236.json

Large diffs are not rendered by default.

Binary file not shown.
3,488 changes: 3,488 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621171/00000237.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621172/00000037.bin
Binary file not shown.
1,540 changes: 1,540 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621172/00000037.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621172/00000038.bin
Binary file not shown.
1,512 changes: 1,512 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621172/00000038.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621173/00000044.bin
Binary file not shown.
1,586 changes: 1,586 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621173/00000044.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621173/00000045.bin
Binary file not shown.
1,680 changes: 1,680 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621173/00000045.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621412/00000024.bin
Binary file not shown.
581 changes: 581 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621412/00000024.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621412/00000025.bin
Binary file not shown.
514 changes: 514 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621412/00000025.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621498/00000024.bin
Binary file not shown.
581 changes: 581 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621498/00000024.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621498/00000025.bin
Binary file not shown.
514 changes: 514 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621498/00000025.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621547/00000032.bin
Binary file not shown.
639 changes: 639 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621547/00000032.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621547/00000033.bin
Binary file not shown.
596 changes: 596 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621547/00000033.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621879/00000347.bin
Binary file not shown.
654 changes: 654 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621879/00000347.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621879/00000348.bin
Binary file not shown.
804 changes: 804 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621879/00000348.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621952/00000291.bin
Binary file not shown.
783 changes: 783 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621952/00000291.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758621952/00000292.bin
Binary file not shown.
724 changes: 724 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758621952/00000292.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622000/00000229.bin
Binary file not shown.
692 changes: 692 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622000/00000229.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622000/00000230.bin
Binary file not shown.
817 changes: 817 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622000/00000230.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622051/00000093.bin
Binary file not shown.
564 changes: 564 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622051/00000093.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622051/00000094.bin
Binary file not shown.
621 changes: 621 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622051/00000094.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622104/00000021.bin
Binary file not shown.
506 changes: 506 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622104/00000021.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622104/00000022.bin
Binary file not shown.
528 changes: 528 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622104/00000022.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622160/00000008.bin
Binary file not shown.
347 changes: 347 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622160/00000008.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622160/00000009.bin
Binary file not shown.
360 changes: 360 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622160/00000009.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622313/00000011.bin
Binary file not shown.
366 changes: 366 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622313/00000011.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622313/00000012.bin
Binary file not shown.
405 changes: 405 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622313/00000012.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622403/00000238.bin
Binary file not shown.
720 changes: 720 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622403/00000238.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622403/00000239.bin
Binary file not shown.
728 changes: 728 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622403/00000239.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622442/00000163.bin
Binary file not shown.
631 changes: 631 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622442/00000163.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622442/00000164.bin
Binary file not shown.
628 changes: 628 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622442/00000164.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622524/00000038.bin
Binary file not shown.
550 changes: 550 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622524/00000038.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new/1758622524/00000039.bin
Binary file not shown.
621 changes: 621 additions & 0 deletions JAMTests/fuzz/0.7.0/_new/1758622524/00000039.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636573/00000032.bin
Binary file not shown.
604 changes: 604 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636573/00000032.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636573/00000033.bin
Binary file not shown.
598 changes: 598 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636573/00000033.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636775/00000013.bin
Binary file not shown.
398 changes: 398 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636775/00000013.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636775/00000014.bin
Binary file not shown.
412 changes: 412 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636775/00000014.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636819/00000021.bin
Binary file not shown.
430 changes: 430 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636819/00000021.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636819/00000022.bin
Binary file not shown.
561 changes: 561 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636819/00000022.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636961/00000017.bin
Binary file not shown.
416 changes: 416 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636961/00000017.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758636961/00000018.bin
Binary file not shown.
565 changes: 565 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758636961/00000018.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637024/00000017.bin
Binary file not shown.
475 changes: 475 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637024/00000017.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637024/00000018.bin
Binary file not shown.
492 changes: 492 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637024/00000018.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637136/00000018.bin
Binary file not shown.
476 changes: 476 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637136/00000018.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637136/00000019.bin
Binary file not shown.
434 changes: 434 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637136/00000019.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637203/00000058.bin
Binary file not shown.
738 changes: 738 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637203/00000058.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637203/00000059.bin
Binary file not shown.
796 changes: 796 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637203/00000059.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637250/00000015.bin
Binary file not shown.
454 changes: 454 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637250/00000015.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637250/00000016.bin
Binary file not shown.
476 changes: 476 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637250/00000016.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637297/00000015.bin
Binary file not shown.
454 changes: 454 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637297/00000015.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637297/00000016.bin
Binary file not shown.
476 changes: 476 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637297/00000016.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637332/00000016.bin
Binary file not shown.
416 changes: 416 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637332/00000016.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637332/00000017.bin
Binary file not shown.
475 changes: 475 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637332/00000017.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637363/00000022.bin
Binary file not shown.
436 changes: 436 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637363/00000022.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637363/00000023.bin
Binary file not shown.
455 changes: 455 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637363/00000023.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637447/00000061.bin
Binary file not shown.
849 changes: 849 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637447/00000061.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637447/00000062.bin
Binary file not shown.
804 changes: 804 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637447/00000062.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637485/00000018.bin
Binary file not shown.
718 changes: 718 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637485/00000018.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758637485/00000019.bin
Binary file not shown.
840 changes: 840 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758637485/00000019.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758708840/00000957.bin
Binary file not shown.
726 changes: 726 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758708840/00000957.json

Large diffs are not rendered by default.

Binary file added JAMTests/fuzz/0.7.0/_new2/1758708840/00000958.bin
Binary file not shown.
568 changes: 568 additions & 0 deletions JAMTests/fuzz/0.7.0/_new2/1758708840/00000958.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PolkaVM/Sources/PolkaVM/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Engine {

private func getInstructionName(_ inst: any Instruction) -> String {
let typeName = String(describing: type(of: inst))
let cleanName = typeName.replacingOccurrences(of: "Instructions.", with: "")
let cleanName = typeName.replacingOccurrences(of: "Instructions::", with: "")
return cleanName.replacingOccurrences(of: "([a-z])([A-Z])", with: "$1_$2", options: .regularExpression).uppercased()
}
}
2 changes: 1 addition & 1 deletion PolkaVM/Sources/PolkaVM/Memory/PageMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class PageMap {
singlePageChecker: (UInt32) -> Bool
) -> (result: Bool, page: UInt32) {
if pages == 0 {
return (singlePageChecker(pageStart), pageStart)
return (true, pageStart)
}

let pageEnd = pageStart + UInt32(pages)
Expand Down
23 changes: 2 additions & 21 deletions PolkaVM/Sources/PolkaVM/Memory/StandardMemory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,16 @@ public final class StandardMemory: Memory {
data: readOnlyData
)

var heapData = readWriteData
let totalHeapSize = Int(heapDataPagesLen + heapEmptyPagesSize)
if heapData.count < totalHeapSize {
let oldSize = heapData.count
let additionalSize = totalHeapSize - oldSize

// Resize and zero-fill efficiently
heapData.count = totalHeapSize
heapData.withUnsafeMutableBytes { bytes in
let zeroPtr = bytes.baseAddress!.advanced(by: oldSize)
memset(zeroPtr, 0, additionalSize)
}
}
heapZone = Zone(
startAddress: heapStart,
endAddress: heapStart + heapDataPagesLen + heapEmptyPagesSize,
data: heapData
data: readWriteData
)

stackZone = Zone(
startAddress: stackStartAddr,
endAddress: UInt32(config.pvmProgramInitStackBaseAddress),
data: {
var stackData = Data(count: Int(stackPageAlignedSize))
_ = stackData.withUnsafeMutableBytes { bytes in
memset(bytes.baseAddress!, 0, Int(stackPageAlignedSize))
}
return stackData
}()
data: Data()
)

argumentZone = Zone(
Expand Down
2 changes: 1 addition & 1 deletion PolkaVM/Sources/PolkaVM/PvmConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension PvmConfig {
public var readOnlyDataSegment: Data? { nil }
public var readWriteDataSegment: Data? { nil }

public var pvmProgramInitRegister1Value: Int { (1 << 32) - (1 << 16) }
public var pvmProgramInitRegister0Value: Int { (1 << 32) - (1 << 16) }
public var pvmProgramInitStackBaseAddress: Int { (1 << 32) - (2 * pvmProgramInitZoneSize) - pvmProgramInitInputDataSize }
public var pvmProgramInitInputStartAddress: Int { pvmProgramInitStackBaseAddress + pvmProgramInitZoneSize }
}
Expand Down
2 changes: 1 addition & 1 deletion PolkaVM/Sources/PolkaVM/Registers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct Registers: Equatable {

/// standard program init registers
public init(config: any PvmConfig, argumentData: Data?) {
self[Index(raw: 0)] = UInt64(config.pvmProgramInitRegister1Value)
self[Index(raw: 0)] = UInt64(config.pvmProgramInitRegister0Value)
self[Index(raw: 1)] = UInt64(config.pvmProgramInitStackBaseAddress)
self[Index(raw: 7)] = UInt64(config.pvmProgramInitInputStartAddress)
self[Index(raw: 8)] = UInt64(argumentData?.count ?? 0)
Expand Down
2 changes: 1 addition & 1 deletion PolkaVM/Sources/PolkaVM/StandardProgram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class StandardProgram {
let stackAlignedSize = Int(Q(stackSize, config))

let totalSize = 5 * ZZ + readOnlyAlignedSize + readWriteAlignedSize + stackAlignedSize + ZI
guard totalSize <= UInt32.max else {
guard totalSize <= 0x1_0000_0000 else {
throw Error.invalidTotalMemorySize
}
code = try ProgramCode(blob[slice.startIndex ..< slice.startIndex + Int(codeLength)])
Expand Down
3 changes: 2 additions & 1 deletion PolkaVM/Sources/PolkaVM/invokePVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public func invokePVM(
let state = try VMStateInterpreter(standardProgramBlob: blob, pc: pc, gas: gas, argumentData: argumentData)
let engine = Engine(config: config, invocationContext: ctx)
let exitReason = await engine.execute(state: state)
let gasUsed = gas - Gas(state.getGas())
let postGas = state.getGas()
let gasUsed = postGas >= GasInt(0) ? gas - Gas(postGas) : gas

switch exitReason {
case .outOfGas:
Expand Down
Loading