diff --git a/adapters/vm2core/vm2core.go b/adapters/vm2core/vm2core.go index c8e2e57c1..25222e9c7 100644 --- a/adapters/vm2core/vm2core.go +++ b/adapters/vm2core/vm2core.go @@ -41,11 +41,10 @@ func AdaptOrderedEvents(events []vm.OrderedEvent) []*core.Event { return utils.Map(events, AdaptOrderedEvent) } -func AdaptStateDiff(trace *vm.TransactionTrace) *core.StateDiff { - if trace.StateDiff == nil { - return nil +func AdaptStateDiff(stateDiff *vm.StateDiff) *core.StateDiff { + if stateDiff == nil { + return core.EmptyStateDiff() } - stateDiff := trace.StateDiff newStorageDiffs := make(map[felt.Felt]map[felt.Felt]*felt.Felt, len(stateDiff.StorageDiffs)) for _, sd := range stateDiff.StorageDiffs { entries := make(map[felt.Felt]*felt.Felt) diff --git a/genesis/genesis.go b/genesis/genesis.go index 9d5bab38a..bfa10ab59 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -209,7 +209,7 @@ func GenesisStateDiff( //nolint:funlen,gocyclo return nil, nil, fmt.Errorf("execute function call: %v", err) } - traceSD := vm2core.AdaptStateDiff(&trace[0]) + traceSD := vm2core.AdaptStateDiff(trace[0].StateDiff) genesisSD, _ := genesisState.StateDiffAndClasses() genesisSD.Merge(traceSD) genesisState.SetStateDiff(genesisSD) diff --git a/sync/pending.go b/sync/pending.go index a8441e4c7..c75122871 100644 --- a/sync/pending.go +++ b/sync/pending.go @@ -9,6 +9,8 @@ import ( "github.com/NethermindEth/juno/db" ) +var feltOne = new(felt.Felt).SetUint64(1) + type Pending struct { Block *core.Block StateUpdate *core.StateUpdate @@ -97,8 +99,7 @@ func (p *PendingStateWriter) IncrementNonce(contractAddress *felt.Felt) error { if err != nil { return fmt.Errorf("get contract nonce: %v", err) } - newNonce := new(felt.Felt).SetUint64(1) - p.stateDiff.Nonces[*contractAddress] = newNonce.Add(currentNonce, newNonce) + p.stateDiff.Nonces[*contractAddress] = currentNonce.Add(currentNonce, feltOne) return nil }