diff --git a/Blockchain/Sources/Blockchain/Types/WorkOutput.swift b/Blockchain/Sources/Blockchain/Types/WorkOutput.swift index 22e32d09..2c56e0d4 100644 --- a/Blockchain/Sources/Blockchain/Types/WorkOutput.swift +++ b/Blockchain/Sources/Blockchain/Types/WorkOutput.swift @@ -4,8 +4,12 @@ import Foundation public enum WorkResultError: Error, CaseIterable { case outOfGas case panic + /// the number of exports made was invalidly reported + case badExports + /// the service's code was not available for lookup in state at the posterior state of the lookup-anchor block case invalidCode - case codeTooLarge // code larger than MaxServiceCodeSize + /// code larger than MaxServiceCodeSize + case codeTooLarge } public struct WorkOutput: Sendable, Equatable { @@ -21,6 +25,7 @@ extension WorkOutput: Codable { case success case outOfGas case panic + case badExports case invalidCode case codeTooLarge } @@ -37,8 +42,10 @@ extension WorkOutput: Codable { case 2: self = .init(.failure(.panic)) case 3: - self = .init(.failure(.invalidCode)) + self = .init(.failure(.badExports)) case 4: + self = .init(.failure(.invalidCode)) + case 5: self = .init(.failure(.codeTooLarge)) default: throw DecodingError.dataCorrupted( @@ -56,6 +63,8 @@ extension WorkOutput: Codable { self = .init(.failure(.outOfGas)) } else if container.contains(.panic) { self = .init(.failure(.panic)) + } else if container.contains(.badExports) { + self = .init(.failure(.badExports)) } else if container.contains(.invalidCode) { self = .init(.failure(.invalidCode)) } else if container.contains(.codeTooLarge) { @@ -84,10 +93,12 @@ extension WorkOutput: Codable { try container.encode(UInt8(1)) case .panic: try container.encode(UInt8(2)) - case .invalidCode: + case .badExports: try container.encode(UInt8(3)) - case .codeTooLarge: + case .invalidCode: try container.encode(UInt8(4)) + case .codeTooLarge: + try container.encode(UInt8(5)) } } } else { @@ -101,6 +112,8 @@ extension WorkOutput: Codable { try container.encodeNil(forKey: .outOfGas) case .panic: try container.encodeNil(forKey: .panic) + case .badExports: + try container.encodeNil(forKey: .badExports) case .invalidCode: try container.encodeNil(forKey: .invalidCode) case .codeTooLarge: diff --git a/Blockchain/Sources/Blockchain/Types/WorkPackage.swift b/Blockchain/Sources/Blockchain/Types/WorkPackage.swift index 620bf788..d283a134 100644 --- a/Blockchain/Sources/Blockchain/Types/WorkPackage.swift +++ b/Blockchain/Sources/Blockchain/Types/WorkPackage.swift @@ -9,7 +9,7 @@ public struct WorkPackage: Sendable, Equatable, Codable { // h public var authorizationServiceIndex: ServiceIndex - // c + // u public var authorizationCodeHash: Data32 // p @@ -59,3 +59,20 @@ extension WorkPackage: Dummy { ) } } + +extension WorkPackage { + /// a: work-package’s implied authorizer, the hash of the concatenation of the authorization code + /// and the parameterization + public func authorizer(serviceAccounts: some ServiceAccounts) async throws -> Data32 { + try await Blake2b256.hash(authorizationCode(serviceAccounts: serviceAccounts), parameterizationBlob) + } + + /// c: the authorization code + public func authorizationCode(serviceAccounts: some ServiceAccounts) async throws -> Data { + try await serviceAccounts.historicalLookup( + serviceAccount: authorizationServiceIndex, + timeslot: context.lookupAnchor.timeslot, + preimageHash: authorizationCodeHash + ) ?? Data() + } +} diff --git a/Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift b/Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift index 504ebef4..cc10ff5d 100644 --- a/Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift +++ b/Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift @@ -427,8 +427,8 @@ public class Transfer: HostCall { } public func gasCost(state: VMState) -> Gas { - let (reg8, reg9): (UInt32, UInt32) = state.readRegister(Registers.Index(raw: 8), Registers.Index(raw: 9)) - return Gas(10) + Gas(reg8) + Gas(0x1_0000_0000) * Gas(reg9) + let reg9: UInt64 = state.readRegister(Registers.Index(raw: 9)) + return Gas(10) + Gas(reg9) } public func _callImpl(config: ProtocolConfigRef, state: VMState) async throws { @@ -454,8 +454,6 @@ public class Transfer: HostCall { state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.WHO.rawValue) } else if gasLimit < destAcc!.minOnTransferGas { state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.LOW.rawValue) - } else if Gas(state.getGas()) < gasLimit { - state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.HIGH.rawValue) } else if let acc, acc.balance - amount < acc.thresholdBalance(config: config) { state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.CASH.rawValue) } else if var acc { diff --git a/Blockchain/Sources/Blockchain/VMInvocations/HostCall/ResultConstants.swift b/Blockchain/Sources/Blockchain/VMInvocations/HostCall/ResultConstants.swift index 7372f85c..8b67a35e 100644 --- a/Blockchain/Sources/Blockchain/VMInvocations/HostCall/ResultConstants.swift +++ b/Blockchain/Sources/Blockchain/VMInvocations/HostCall/ResultConstants.swift @@ -15,8 +15,6 @@ public enum HostCallResultCode: UInt64 { case CASH = 0xFFFF_FFFF_FFFF_FFF9 /// LOW = 2^64 − 8: Gas limit too low. case LOW = 0xFFFF_FFFF_FFFF_FFF8 - /// HIGH = 2^64 − 9: Gas limit too high. - case HIGH = 0xFFFF_FFFF_FFFF_FFF7 /// HUH = 2^64 − 10: The item is already solicited or cannot be forgotten. case HUH = 0xFFFF_FFFF_FFFF_FFF6 /// OK = 0: The return value indicating general success. diff --git a/Node/Package.resolved b/Node/Package.resolved index 21e00dc6..88a24089 100644 --- a/Node/Package.resolved +++ b/Node/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "e6fc7ac1513fbfe8e482dc8b89ef5388fcc4ffb7a67e2def60644a806029f64e", + "originHash" : "fd50b22dcf258877cc79f49fe7cb855a71ce6974bd1a2732a13b0d3e49c057fc", "pins" : [ { "identity" : "async-channels", @@ -46,6 +46,15 @@ "version" : "4.14.3" } }, + { + "identity" : "lrucache", + "kind" : "remoteSourceControl", + "location" : "https://github.com/nicklockwood/LRUCache.git", + "state" : { + "revision" : "542f0449556327415409ededc9c43a4bd0a397dc", + "version" : "1.0.7" + } + }, { "identity" : "multipart-kit", "kind" : "remoteSourceControl", diff --git a/Node/Tests/NodeTests/chainfiles/devnet_allconfig_spec.json b/Node/Tests/NodeTests/chainfiles/devnet_allconfig_spec.json index 0146bf4c..ca787347 100644 --- a/Node/Tests/NodeTests/chainfiles/devnet_allconfig_spec.json +++ b/Node/Tests/NodeTests/chainfiles/devnet_allconfig_spec.json @@ -36,9 +36,9 @@ "totalNumberOfCores" : 1, "totalNumberOfValidators" : 3, "transferMemoSize" : 128, - "workPackageAuthorizerGas" : 10000000, - "workPackageRefineGas" : 10000000, - "totalAccumulationGas": 35000000, + "workPackageAuthorizerGas" : 50000000, + "workPackageRefineGas" : 5000000000, + "totalAccumulationGas": 3500000000, "maxDepsInWorkReport": 8 }, "state" : {},