From 04ddf178be8ab96e4636d80cd66b009a0e60d30b Mon Sep 17 00:00:00 2001 From: "daniel.vladco" Date: Wed, 27 Nov 2024 16:53:18 +0200 Subject: [PATCH] fix: host func casting --- .../polkavm/host_call/accumulate_functions.go | 28 ++++---- .../host_call/accumulate_functions_test.go | 42 ++++++------ internal/polkavm/host_call/common.go | 24 +++---- .../polkavm/host_call/general_functions.go | 67 ++++++++----------- .../host_call/general_functions_test.go | 38 +++++------ internal/statetransition/accumulate.go | 2 +- internal/statetransition/on_transfer.go | 2 +- 7 files changed, 95 insertions(+), 108 deletions(-) diff --git a/internal/polkavm/host_call/accumulate_functions.go b/internal/polkavm/host_call/accumulate_functions.go index 57a6093..0d2cfdf 100644 --- a/internal/polkavm/host_call/accumulate_functions.go +++ b/internal/polkavm/host_call/accumulate_functions.go @@ -23,12 +23,12 @@ func Bless(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) ( // let [m, a, v, o, n] = ω7...12 managerServiceId, assignServiceId, designateServiceId, addr, servicesNr := regs[A0], regs[A1], regs[A2], regs[A3], regs[A4] // let g = {(s ↦ g) where E4(s) ⌢ E8(g) = μ_o+12i⋅⋅⋅+12 | i ∈ Nn} if Zo⋅⋅⋅+12n ⊂ Vμ otherwise ∇ - for i := range servicesNr { - serviceId, err := readNumber[block.ServiceId](mem, addr+(12*i), 4) + for i := range uint32(servicesNr) { + serviceId, err := readNumber[block.ServiceId](mem, uint32(addr)+(12*i), 4) if err != nil { return gas, withCode(regs, OOB), mem, ctxPair, err } - serviceGas, err := readNumber[uint64](mem, addr+(12*i)+4, 8) + serviceGas, err := readNumber[uint64](mem, uint32(addr)+(12*i)+4, 8) if err != nil { return gas, withCode(regs, OOB), mem, ctxPair, err } @@ -54,12 +54,12 @@ func Assign(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) // let o = ω8 addr := regs[A1] core := regs[A0] - if core >= uint32(common.TotalNumberOfCores) { + if core >= uint64(common.TotalNumberOfCores) { return gas, withCode(regs, CORE), mem, ctxPair, nil } for i := 0; i < state.PendingAuthorizersQueueSize; i++ { bytes := make([]byte, 32) - if err := mem.Read(addr+uint32(32*i), bytes); err != nil { + if err := mem.Read(uint32(addr)+uint32(32*i), bytes); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } ctxPair.RegularCtx.AccumulationState.WorkReportsQueue[core][i] = crypto.Hash(bytes) @@ -84,7 +84,7 @@ func Designate(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPai addr := regs[A0] for i := 0; i < common.NumberOfValidators; i++ { bytes := make([]byte, 336) - if err := mem.Read(addr+uint32(336*i), bytes); err != nil { + if err := mem.Read(uint32(addr)+uint32(336*i), bytes); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } @@ -109,7 +109,7 @@ func Checkpoint(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPa ctxPair.ExceptionalCtx = ctxPair.RegularCtx // Set the new ϱ' value into ω′7 - regs[A0] = uint32(gas & ((1 << 32) - 1)) + regs[A0] = uint64(gas & ((1 << 32) - 1)) return gas, regs, mem, ctxPair, nil } @@ -126,7 +126,7 @@ func New(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) (Ga // c = μo⋅⋅⋅+32 if No⋅⋅⋅+32 ⊂ Vμ otherwise ∇ codeHashBytes := make([]byte, 32) - if err := mem.Read(addr, codeHashBytes); err != nil { + if err := mem.Read(uint32(addr), codeHashBytes); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } @@ -149,7 +149,7 @@ func New(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) (Ga // if a ≠ ∇ ∧ b ≥ (xs)t if b >= ctxPair.RegularCtx.ServiceAccount().ThresholdBalance() { - regs[A0] = uint32(ctxPair.RegularCtx.ServiceId) + regs[A0] = uint64(ctxPair.RegularCtx.ServiceId) currentAccount := ctxPair.RegularCtx.ServiceAccount() currentAccount.Balance = b ctxPair.RegularCtx.ServiceState[ctxPair.RegularCtx.ServiceId] = currentAccount @@ -176,7 +176,7 @@ func Upgrade(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) // c = μo⋅⋅⋅+32 if No⋅⋅⋅+32 ⊂ Vμ otherwise ∇ codeHash := make([]byte, 32) - if err := mem.Read(addr, codeHash); err != nil { + if err := mem.Read(uint32(addr), codeHash); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } @@ -202,7 +202,7 @@ func Transfer(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair // m = μo⋅⋅⋅+M if No⋅⋅⋅+M ⊂ Vμ otherwise ∇ m := make([]byte, service.TransferMemoSizeBytes) - if err := mem.Read(o, m); err != nil { + if err := mem.Read(uint32(o), m); err != nil { return gas, withCode(regs, OK), mem, ctxPair, nil } @@ -263,7 +263,7 @@ func Quit(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair) (G // m = E−1(μo⋅⋅⋅+M) memo := make([]byte, service.TransferMemoSizeBytes) - if err := mem.Read(addr, memo); err != nil { + if err := mem.Read(uint32(addr), memo); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } @@ -309,7 +309,7 @@ func Solicit(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair, addr, preimageLength := regs[A0], regs[A1] // let h = μo⋅⋅⋅+32 if Zo⋅⋅⋅+32 ⊂ Vμ otherwise ∇ preimageHashBytes := make([]byte, 32) - if err := mem.Read(addr, preimageHashBytes); err != nil { + if err := mem.Read(uint32(addr), preimageHashBytes); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } @@ -350,7 +350,7 @@ func Forget(gas Gas, regs Registers, mem Memory, ctxPair AccumulateContextPair, // let h = μo⋅⋅⋅+32 if Zo⋅⋅⋅+32 ⊂ Vμ otherwise ∇ preimageHashBytes := make([]byte, 32) - if err := mem.Read(addr, preimageHashBytes); err != nil { + if err := mem.Read(uint32(addr), preimageHashBytes); err != nil { return gas, withCode(regs, OOB), mem, ctxPair, nil } diff --git a/internal/polkavm/host_call/accumulate_functions_test.go b/internal/polkavm/host_call/accumulate_functions_test.go index b91021a..e3e6f84 100644 --- a/internal/polkavm/host_call/accumulate_functions_test.go +++ b/internal/polkavm/host_call/accumulate_functions_test.go @@ -91,7 +91,7 @@ func TestAccumulate(t *testing.T) { A4: 3, }, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, initialGas: 100, @@ -122,7 +122,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, expectedX: AccumulateContext{ AccumulationState: state.AccumulationState{ @@ -141,7 +141,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, expectedX: AccumulateContext{ AccumulationState: state.AccumulationState{ @@ -166,7 +166,7 @@ func TestAccumulate(t *testing.T) { }, initialRegs: deltaRegs{A1: 123123, A2: 123124123, A3: 756846353}, expectedDeltaRegs: deltaRegs{ - A0: uint32(currentServiceID), + A0: uint64(currentServiceID), }, initialGas: 100, expectedGas: 88, @@ -214,7 +214,7 @@ func TestAccumulate(t *testing.T) { }, initialRegs: deltaRegs{A1: 3453453453, A2: 456456456}, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, initialGas: 100, expectedGas: 88, @@ -242,7 +242,7 @@ func TestAccumulate(t *testing.T) { A2: 80, // g }, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, initialGas: 1000000100, expectedGas: 88, @@ -293,7 +293,7 @@ func TestAccumulate(t *testing.T) { A0: 1234, // d: receiver address }, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, initialGas: 100, expectedGas: 88, @@ -379,7 +379,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, X: AccumulateContext{ ServiceId: currentServiceID, @@ -414,7 +414,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(OK), + A0: uint64(OK), }, X: AccumulateContext{ ServiceId: currentServiceID, @@ -451,7 +451,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(HUH), + A0: uint64(HUH), }, X: AccumulateContext{ ServiceId: currentServiceID, @@ -488,7 +488,7 @@ func TestAccumulate(t *testing.T) { initialGas: 100, expectedGas: 88, expectedDeltaRegs: deltaRegs{ - A0: uint32(FULL), + A0: uint64(FULL), }, X: AccumulateContext{ ServiceId: currentServiceID, @@ -515,7 +515,7 @@ func TestAccumulate(t *testing.T) { fn: fnTms(Forget), alloc: alloc{A0: hash2bytes(randomHash)}, initialRegs: deltaRegs{A1: 123}, - expectedDeltaRegs: deltaRegs{A0: uint32(OK)}, + expectedDeltaRegs: deltaRegs{A0: uint64(OK)}, initialGas: 100, expectedGas: 88, X: AccumulateContext{ @@ -547,7 +547,7 @@ func TestAccumulate(t *testing.T) { fn: fnTms(Forget), alloc: alloc{A0: hash2bytes(randomHash)}, initialRegs: deltaRegs{A1: 123}, - expectedDeltaRegs: deltaRegs{A0: uint32(OK)}, + expectedDeltaRegs: deltaRegs{A0: uint64(OK)}, initialGas: 100, expectedGas: 88, timeslot: randomTimeslot2, @@ -582,7 +582,7 @@ func TestAccumulate(t *testing.T) { fn: fnTms(Forget), alloc: alloc{A0: hash2bytes(randomHash)}, initialRegs: deltaRegs{A1: 123}, - expectedDeltaRegs: deltaRegs{A0: uint32(OK)}, + expectedDeltaRegs: deltaRegs{A0: uint64(OK)}, initialGas: 100, expectedGas: 88, timeslot: randomTimeslot2 + jamtime.PreimageExpulsionPeriod + 1, @@ -615,7 +615,7 @@ func TestAccumulate(t *testing.T) { fn: fnTms(Forget), alloc: alloc{A0: hash2bytes(randomHash)}, initialRegs: deltaRegs{A1: 123}, - expectedDeltaRegs: deltaRegs{A0: uint32(OK)}, + expectedDeltaRegs: deltaRegs{A0: uint64(OK)}, initialGas: 100, expectedGas: 88, timeslot: randomTimeslot2 + jamtime.PreimageExpulsionPeriod + 1, @@ -655,7 +655,7 @@ func TestAccumulate(t *testing.T) { mem := memoryMap.NewMemory(nil, nil, nil) initialRegs := Registers{ RA: VmAddressReturnToHost, - SP: memoryMap.StackAddressHigh, + SP: uint64(memoryMap.StackAddressHigh), } stackAddress := memoryMap.StackAddressLow for addrReg, v := range tc.alloc { @@ -663,7 +663,7 @@ func TestAccumulate(t *testing.T) { err = mem.Write(stackAddress, v) require.NoError(t, err) - initialRegs[addrReg] = stackAddress + initialRegs[addrReg] = uint64(stackAddress) stackAddress = stackAddress + uint32(len(v)) } for i, v := range tc.initialRegs { @@ -685,7 +685,7 @@ func TestAccumulate(t *testing.T) { expectedRegs := initialRegs for i, reg := range tc.expectedDeltaRegs { - expectedRegs[i] = reg + expectedRegs[i] = uint64(reg) } assert.Equal(t, expectedRegs, regs) assert.Equal(t, tc.expectedGas, gasRemaining) @@ -697,7 +697,7 @@ func TestAccumulate(t *testing.T) { type hostCall func(Gas, Registers, Memory, AccumulateContextPair, jamtime.Timeslot) (Gas, Registers, Memory, AccumulateContextPair, error) type alloc map[Reg][]byte -type deltaRegs map[Reg]uint32 +type deltaRegs map[Reg]uint64 func fixedSizeBytes(size int, b []byte) []byte { bb := make([]byte, size) @@ -706,8 +706,8 @@ func fixedSizeBytes(size int, b []byte) []byte { } func checkUint64(t *testing.T, gas uint64) deltaRegs { - a0 := uint32(math.Mod(float64(gas), 1<<32)) - a1 := uint32(math.Floor(float64(gas) / (1 << 32))) + a0 := uint64(math.Mod(float64(gas), 1<<32)) + a1 := uint64(math.Floor(float64(gas) / (1 << 32))) assert.Equal(t, gas, uint64(a1)<<32|uint64(a0)) return deltaRegs{ A0: a0, diff --git a/internal/polkavm/host_call/common.go b/internal/polkavm/host_call/common.go index 545552d..6813998 100644 --- a/internal/polkavm/host_call/common.go +++ b/internal/polkavm/host_call/common.go @@ -43,19 +43,19 @@ const ( ForgetID = 14 ) -type Code uint32 +type Code uint64 const ( - NONE Code = math.MaxUint32 - WHAT Code = math.MaxUint32 - 1 - OOB Code = math.MaxUint32 - 2 - WHO Code = math.MaxUint32 - 3 - FULL Code = math.MaxUint32 - 4 - CORE Code = math.MaxUint32 - 5 - CASH Code = math.MaxUint32 - 6 - LOW Code = math.MaxUint32 - 7 - HIGH Code = math.MaxUint32 - 8 - HUH Code = math.MaxUint32 - 9 + NONE Code = math.MaxUint64 + WHAT Code = math.MaxUint64 - 1 + OOB Code = math.MaxUint64 - 2 + WHO Code = math.MaxUint64 - 3 + FULL Code = math.MaxUint64 - 4 + CORE Code = math.MaxUint64 - 5 + CASH Code = math.MaxUint64 - 6 + LOW Code = math.MaxUint64 - 7 + HIGH Code = math.MaxUint64 - 8 + HUH Code = math.MaxUint64 - 9 OK Code = 0 ) @@ -98,6 +98,6 @@ func readNumber[U interface{ ~uint32 | ~uint64 }](mem Memory, addr uint32, lengt } func withCode(regs Registers, s Code) Registers { - regs[A0] = uint32(s) + regs[A0] = uint64(s) return regs } diff --git a/internal/polkavm/host_call/general_functions.go b/internal/polkavm/host_call/general_functions.go index 8b711d0..709716e 100644 --- a/internal/polkavm/host_call/general_functions.go +++ b/internal/polkavm/host_call/general_functions.go @@ -28,7 +28,7 @@ func GasRemaining(gas polkavm.Gas, regs polkavm.Registers) (polkavm.Gas, polkavm gas -= GasRemainingCost // Set the new ϱ' value into ω′7 - regs[polkavm.A0] = uint32(gas) + regs[polkavm.A0] = uint64(gas) return gas, regs, nil } @@ -44,12 +44,12 @@ func Lookup(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servi // Determine the lookup key 'a' a := s - if uint64(omega7) != math.MaxUint64 && omega7 != uint32(serviceId) { + if uint64(omega7) != math.MaxUint64 && omega7 != uint64(serviceId) { var exists bool // Lookup service account by serviceId in the serviceState a, exists = serviceState[serviceId] if !exists { - regs[polkavm.A0] = uint32(NONE) + regs[polkavm.A0] = uint64(NONE) return gas, regs, mem, nil } } @@ -58,10 +58,9 @@ func Lookup(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servi // Ensure the memory range is valid for hashing (µho..ho+32) memorySlice := make([]byte, 32) - err := mem.Read(ho, memorySlice) + err := mem.Read(uint32(ho), memorySlice) if err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, err + return gas, withCode(regs, OOB), mem, err } // Compute the hash H(µho..ho+32) @@ -70,8 +69,7 @@ func Lookup(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servi // Lookup value in storage (v) using the hash v, exists := a.Storage[hash] if !exists { - regs[polkavm.A0] = uint32(NONE) - return gas, regs, mem, nil + return gas, withCode(regs, NONE), mem, nil } bo := regs[polkavm.A2] @@ -79,16 +77,14 @@ func Lookup(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servi // Write value to memory if within bounds if len(v) > 0 && len(v) <= int(bz) { - if err = mem.Write(bo, v); err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, err + if err = mem.Write(uint32(bo), v); err != nil { + return gas, withCode(regs, OOB), mem, err } } else { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, err + return gas, withCode(regs, OOB), mem, err } - regs[polkavm.A0] = uint32(len(v)) + regs[polkavm.A0] = uint64(len(v)) return gas, regs, mem, err } @@ -106,7 +102,7 @@ func Read(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s service bz := regs[polkavm.A4] a := s - if uint64(omega7) != math.MaxUint64 && omega7 != uint32(serviceId) { + if uint64(omega7) != math.MaxUint64 && omega7 != uint64(serviceId) { var exists bool a, exists = serviceState[block.ServiceId(omega7)] if !exists { @@ -116,10 +112,9 @@ func Read(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s service // read key data from memory at ko..ko+kz keyData := make([]byte, kz) - err := mem.Read(ko, keyData) + err := mem.Read(uint32(ko), keyData) if err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, nil + return gas, withCode(regs, OOB), mem, nil } serviceIdBytes, err := jam.Marshal(omega7) @@ -137,24 +132,21 @@ func Read(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s service v, exists := a.Storage[k] if !exists { - regs[polkavm.A0] = uint32(NONE) - return gas, regs, mem, nil + return gas, withCode(regs, NONE), mem, nil } writeLen := int(math.Min(float64(bz), float64(len(v)))) if writeLen > 0 { - if err = mem.Write(bo, v[:writeLen]); err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, nil + if err = mem.Write(uint32(bo), v[:writeLen]); err != nil { + return gas, withCode(regs, OOB), mem, nil } - regs[polkavm.A0] = uint32(len(v)) + regs[polkavm.A0] = uint64(len(v)) return gas, regs, mem, nil } - regs[polkavm.A0] = uint32(NONE) - return gas, regs, mem, nil + return gas, withCode(regs, NONE), mem, nil } // Write ΩW(ϱ, ω, μ, s, s) @@ -170,7 +162,7 @@ func Write(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servic vz := regs[polkavm.A3] keyData := make([]byte, kz) - err := mem.Read(ko, keyData) + err := mem.Read(uint32(ko), keyData) if err != nil { return gas, regs, mem, s, err } @@ -187,10 +179,9 @@ func Write(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servic delete(a.Storage, k) } else { valueData := make([]byte, vz) - err := mem.Read(vo, valueData) + err := mem.Read(uint32(vo), valueData) if err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, s, err + return gas, withCode(regs, OOB), mem, s, err } a.Storage[k] = valueData @@ -198,17 +189,15 @@ func Write(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, s servic storageItem, ok := s.Storage[k] if !ok { - regs[polkavm.A0] = uint32(NONE) - return gas, regs, mem, s, err + return gas, withCode(regs, NONE), mem, s, err } if a.ThresholdBalance() > a.Balance { - regs[polkavm.A0] = uint32(FULL) - return gas, regs, mem, s, err + return gas, withCode(regs, FULL), mem, s, err } // otherwise a.ThresholdBalance() <= a.Balance - regs[polkavm.A0] = uint32(len(storageItem)) // l + regs[polkavm.A0] = uint64(len(storageItem)) // l return gas, regs, mem, a, err // return service account 'a' as opposed to 's' for not successful paths } @@ -246,11 +235,9 @@ func Info(gas polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, serviceId return gas, regs, mem, polkavm.ErrPanicf(err.Error()) } - if err := mem.Write(omega8, m); err != nil { - regs[polkavm.A0] = uint32(OOB) - return gas, regs, mem, nil + if err := mem.Write(uint32(omega8), m); err != nil { + return gas, withCode(regs, OOB), mem, nil } - regs[polkavm.A0] = uint32(OK) - return gas, regs, mem, nil + return gas, withCode(regs, OK), mem, nil } diff --git a/internal/polkavm/host_call/general_functions_test.go b/internal/polkavm/host_call/general_functions_test.go index bd0c3ca..a5f7c50 100644 --- a/internal/polkavm/host_call/general_functions_test.go +++ b/internal/polkavm/host_call/general_functions_test.go @@ -65,7 +65,7 @@ func TestLookup(t *testing.T) { t.Run("service_not_found", func(t *testing.T) { initialRegs := polkavm.Registers{ polkavm.RA: polkavm.VmAddressReturnToHost, - polkavm.SP: memoryMap.StackAddressHigh, + polkavm.SP: uint64(memoryMap.StackAddressHigh), } mem := memoryMap.NewMemory(nil, nil, nil) initialGas := uint64(100) @@ -96,10 +96,10 @@ func TestLookup(t *testing.T) { initialRegs := polkavm.Registers{ polkavm.RA: polkavm.VmAddressReturnToHost, - polkavm.SP: memoryMap.StackAddressHigh, - polkavm.A0: uint32(serviceId), - polkavm.A1: ho, - polkavm.A2: bo, + polkavm.SP: uint64(memoryMap.StackAddressHigh), + polkavm.A0: uint64(serviceId), + polkavm.A1: uint64(ho), + polkavm.A2: uint64(bo), polkavm.A3: 32, } sa := service.ServiceAccount{ @@ -170,12 +170,12 @@ func TestRead(t *testing.T) { bz := uint32(32) initialRegs := polkavm.Registers{ polkavm.RA: polkavm.VmAddressReturnToHost, - polkavm.SP: memoryMap.StackAddressHigh, - polkavm.A0: uint32(serviceId), - polkavm.A1: ko, - polkavm.A2: kz, - polkavm.A3: bo, - polkavm.A4: bz, + polkavm.SP: uint64(memoryMap.StackAddressHigh), + polkavm.A0: uint64(serviceId), + polkavm.A1: uint64(ko), + polkavm.A2: uint64(kz), + polkavm.A3: uint64(bo), + polkavm.A4: uint64(bz), } mem := memoryMap.NewMemory(nil, nil, nil) err = mem.Write(ko, keyData) @@ -238,11 +238,11 @@ func TestWrite(t *testing.T) { initialRegs := polkavm.Registers{ polkavm.RA: polkavm.VmAddressReturnToHost, - polkavm.SP: memoryMap.StackAddressHigh, - polkavm.A0: ko, - polkavm.A1: kz, - polkavm.A2: vo, - polkavm.A3: vz, + polkavm.SP: uint64(memoryMap.StackAddressHigh), + polkavm.A0: uint64(ko), + polkavm.A1: uint64(kz), + polkavm.A2: uint64(vo), + polkavm.A3: uint64(vz), } mem := memoryMap.NewMemory(nil, nil, nil) err = mem.Write(ko, keyData) @@ -317,9 +317,9 @@ func TestInfo(t *testing.T) { mem := memoryMap.NewMemory(nil, nil, nil) initialRegs := polkavm.Registers{ polkavm.RA: polkavm.VmAddressReturnToHost, - polkavm.SP: memoryMap.StackAddressHigh, - polkavm.A0: uint32(serviceId), - polkavm.A1: omega1, + polkavm.SP: uint64(memoryMap.StackAddressHigh), + polkavm.A0: uint64(serviceId), + polkavm.A1: uint64(omega1), } hostCall := func(hostCall uint32, gasCounter polkavm.Gas, regs polkavm.Registers, mem polkavm.Memory, x service.ServiceAccount) (polkavm.Gas, polkavm.Registers, polkavm.Memory, service.ServiceAccount, error) { gasCounter, regs, mem, err = host_call.Info(gasCounter, regs, mem, serviceId, serviceState) diff --git a/internal/statetransition/accumulate.go b/internal/statetransition/accumulate.go index 97b4464..bc78ab7 100644 --- a/internal/statetransition/accumulate.go +++ b/internal/statetransition/accumulate.go @@ -102,7 +102,7 @@ func (a *Accumulator) InvokePVM(accState state.AccumulationState, serviceIndex b case host_call.ForgetID: gasCounter, regs, mem, ctx, err = host_call.Forget(gasCounter, regs, mem, ctx, a.header.TimeSlotIndex) default: - regs[polkavm.A0] = uint32(host_call.WHAT) + regs[polkavm.A0] = uint64(host_call.WHAT) gasCounter -= AccumulateCost } return gasCounter, regs, mem, ctx, err diff --git a/internal/statetransition/on_transfer.go b/internal/statetransition/on_transfer.go index dcf867f..a873f67 100644 --- a/internal/statetransition/on_transfer.go +++ b/internal/statetransition/on_transfer.go @@ -43,7 +43,7 @@ func InvokePVMOnTransfer(serviceState service.ServiceState, serviceIndex block.S case host_call.InfoID: gasCounter, regs, mem, err = host_call.Info(gasCounter, regs, mem, serviceIndex, serviceState) default: - regs[polkavm.A0] = uint32(host_call.WHAT) + regs[polkavm.A0] = uint64(host_call.WHAT) gasCounter -= OnTransferCost } return gasCounter, regs, mem, serviceAccount, err