Skip to content
Open
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
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/nspcc-dev/bbolt v0.0.0-20250911202005-807225ebb0c8
github.com/nspcc-dev/hrw/v2 v2.0.4
github.com/nspcc-dev/locode-db v0.8.2
github.com/nspcc-dev/neo-go v0.116.0
github.com/nspcc-dev/neo-go v0.116.1-0.20260130082647-9c7004d3311f
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea
github.com/nspcc-dev/neofs-contract v0.26.0
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.16.0.20260127152410-12dbac67e506
Expand Down Expand Up @@ -93,7 +93,9 @@ require (
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.38.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ github.com/nspcc-dev/hrw/v2 v2.0.4 h1:o3Zh/2aF+IgGpvt414f46Ya20WG9u9vWxVd16ErFI8
github.com/nspcc-dev/hrw/v2 v2.0.4/go.mod h1:dUjOx27zTTvoPmT5EG25vSSWL2tKS7ndAa2TPTiZwFo=
github.com/nspcc-dev/locode-db v0.8.2 h1:+9+1Z7ppG+ISDLHzMND7PZ8+R4H3d04doVRyNevOpz0=
github.com/nspcc-dev/locode-db v0.8.2/go.mod h1:PtAASXSG4D4Oz0js9elzTyTr8GLpOJO20qFL881Nims=
github.com/nspcc-dev/neo-go v0.116.0 h1:s6z0TDCCH9E/0XVb28e0MYXWzENHhApGsiifLPlstTs=
github.com/nspcc-dev/neo-go v0.116.0/go.mod h1:RDOBkZ+EGtr/NRFItY1oLx7zEIKKqFZKjKupEnMj6q8=
github.com/nspcc-dev/neo-go v0.116.1-0.20260130082647-9c7004d3311f h1:IOEvEfypBaC3Am2tHpqoxc+KwN7CpYGlKykJy/67k74=
github.com/nspcc-dev/neo-go v0.116.1-0.20260130082647-9c7004d3311f/go.mod h1:RDOBkZ+EGtr/NRFItY1oLx7zEIKKqFZKjKupEnMj6q8=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20260121113504-979d1f4aada1 h1:k2PZRCJ82ZSNa398+U6lty6Z0NZOurL72wnEn6ulgos=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20260121113504-979d1f4aada1/go.mod h1:X2spkE8hK/l08CYulOF19fpK5n3p2xO0L1GnJFIywQg=
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea h1:mK0EMGLvunXcFyq7fBURS/CsN4MH+4nlYiqn6pTwWAU=
Expand Down
5 changes: 3 additions & 2 deletions pkg/innerring/internal/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/consensus"
"github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
Expand Down Expand Up @@ -48,7 +49,7 @@ type Blockchain struct {
// New returns new Blockchain configured by the specified Config. New panics if
// any required Config field is zero or unset. Resulting Blockchain is ready to
// run. Launched Blockchain should be finally stopped.
func New(cfg *config.Consensus, wallet *config.Wallet, errChan chan<- error, log *zap.Logger) (res *Blockchain, err error) {
func New(cfg *config.Consensus, wallet *config.Wallet, errChan chan<- error, log *zap.Logger, customNatives ...func(cfg neogoconfig.ProtocolConfiguration) []interop.Contract) (res *Blockchain, err error) {
switch {
case cfg.Storage.Type == "":
panic("uninitialized storage config")
Expand Down Expand Up @@ -259,7 +260,7 @@ func New(cfg *config.Consensus, wallet *config.Wallet, errChan chan<- error, log
}
}()

bc, err := core.NewBlockchain(bcStorage, cfgBase.Blockchain(), log)
bc, err := core.NewBlockchain(bcStorage, cfgBase.Blockchain(), log, customNatives...)
if err != nil {
return nil, fmt.Errorf("init core blockchain component: %w", err)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/innerring/internal/metachain/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package metachain

import (
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring/internal/blockchain"
"go.uber.org/zap"
)

// NewMetaChain returns side chain with redefined/custom native contracts.
// See [contracts.NewCustomNatives] for details.
func NewMetaChain(cfg *config.Consensus, wallet *config.Wallet, errChan chan<- error, log *zap.Logger) (*blockchain.Blockchain, error) {
return blockchain.New(cfg, wallet, errChan, log, NewCustomNatives)
}
55 changes: 55 additions & 0 deletions pkg/innerring/internal/metachain/contracts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package metachain

import (
neogoconfig "github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/nspcc-dev/neofs-node/pkg/innerring/internal/metachain/gas"
"github.com/nspcc-dev/neofs-node/pkg/innerring/internal/metachain/meta"
)

// NewCustomNatives returns custom list of native contracts for metadata
// side chain. Returned contracts:
// - Management
// - Ledger
// - NEO
// - redefined GAS (see [gas.NewGAS] for details)
// - Policy
// - Designate
// - Notary
// - new native metadata contract (see [meta.NewMetadata] for details).
func NewCustomNatives(cfg neogoconfig.ProtocolConfiguration) []interop.Contract {
mgmt := native.NewManagement()
ledger := native.NewLedger()

g := gas.NewGAS()
n := native.NewNEO(cfg)
p := native.NewPolicy()

n.GAS = g
n.Policy = p

mgmt.NEO = n
mgmt.Policy = p
ledger.Policy = p

desig := native.NewDesignate(cfg.Genesis.Roles)
desig.NEO = n

notary := native.NewNotary()
notary.Policy = p
notary.GAS = g
notary.NEO = n
notary.Desig = desig

return []interop.Contract{
mgmt,
ledger,
n,
g,
p,
desig,
notary,
meta.NewMetadata(n),
}
}
142 changes: 142 additions & 0 deletions pkg/innerring/internal/metachain/gas/gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package gas

import (
"math/big"

"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/dao"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativeids"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)

// DefaultBalance is a balance of every account in redefined [GAS] native
// contract.
const DefaultBalance = 100

var _ = (native.IGAS)(&GAS{})

func (g *GAS) Metadata() *interop.ContractMD {
return &g.ContractMD
}

// GAS represents GAS custom native contract. It always returns [DefaultBalance] as a
// balance, has no-op `Burn`, `Mint`, `Transfer` operations.
type GAS struct {
interop.ContractMD
symbol string
decimals int64
factor int64
}

// NewGAS returns [GAS] custom native contract.
func NewGAS() *GAS {
g := &GAS{}
defer g.BuildHFSpecificMD(g.ActiveIn())

g.ContractMD = *interop.NewContractMD(nativenames.Gas, nativeids.GasToken, func(m *manifest.Manifest, hf config.Hardfork) {
m.SupportedStandards = []string{manifest.NEP17StandardName}
})
g.symbol = "GAS"
g.decimals = 8
g.factor = native.GASFactor

desc := native.NewDescriptor("symbol", smartcontract.StringType)
md := native.NewMethodAndPrice(g.Symbol, 0, callflag.NoneFlag)
g.AddMethod(md, desc)

desc = native.NewDescriptor("decimals", smartcontract.IntegerType)
md = native.NewMethodAndPrice(g.Decimals, 0, callflag.NoneFlag)
g.AddMethod(md, desc)

desc = native.NewDescriptor("totalSupply", smartcontract.IntegerType)
md = native.NewMethodAndPrice(g.TotalSupply, 1<<15, callflag.ReadStates)
g.AddMethod(md, desc)

desc = native.NewDescriptor("balanceOf", smartcontract.IntegerType,
manifest.NewParameter("account", smartcontract.Hash160Type))
md = native.NewMethodAndPrice(g.balanceOf, 1<<15, callflag.ReadStates)
g.AddMethod(md, desc)

transferParams := []manifest.Parameter{
manifest.NewParameter("from", smartcontract.Hash160Type),
manifest.NewParameter("to", smartcontract.Hash160Type),
manifest.NewParameter("amount", smartcontract.IntegerType),
}
desc = native.NewDescriptor("transfer", smartcontract.BoolType,
append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))...,
)
md = native.NewMethodAndPrice(g.Transfer, 1<<17, callflag.States|callflag.AllowCall|callflag.AllowNotify)
md.StorageFee = 50
g.AddMethod(md, desc)

eDesc := native.NewEventDescriptor("Transfer", transferParams...)
eMD := native.NewEvent(eDesc)
g.AddEvent(eMD)

return g
}

// Initialize initializes a GAS contract.
func (g *GAS) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *interop.HFSpecificContractMD) error {
return nil
}

// InitializeCache implements the [interop.Contract] interface.
func (g *GAS) InitializeCache(_ interop.IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error {
return nil
}

// OnPersist implements the [interop.Contract] interface.
func (g *GAS) OnPersist(ic *interop.Context) error {
return nil
}

// PostPersist implements the [interop.Contract] interface.
func (g *GAS) PostPersist(ic *interop.Context) error {
return nil
}

// ActiveIn implements the [interop.Contract] interface.
func (g *GAS) ActiveIn() *config.Hardfork {
return nil
}

// BalanceOf returns native GAS token balance for the acc.
func (g *GAS) BalanceOf(d *dao.Simple, acc util.Uint160) *big.Int {
return big.NewInt(DefaultBalance * native.GASFactor)
}

func (g *GAS) Symbol(_ *interop.Context, _ []stackitem.Item) stackitem.Item {
return stackitem.NewByteArray([]byte(g.symbol))
}

func (g *GAS) Decimals(_ *interop.Context, _ []stackitem.Item) stackitem.Item {
return stackitem.NewBigInteger(big.NewInt(g.decimals))
}

func (g *GAS) TotalSupply(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
return stackitem.NewBigInteger(big.NewInt(DefaultBalance * native.GASFactor))
}

func (g *GAS) Transfer(ic *interop.Context, args []stackitem.Item) stackitem.Item {
return stackitem.NewBool(true)
}

// balanceOf is the only difference with default native GAS implementation:
// it always returns fixed number of tokens.
func (g *GAS) balanceOf(ic *interop.Context, args []stackitem.Item) stackitem.Item {
return stackitem.NewBigInteger(big.NewInt(DefaultBalance * native.GASFactor))
}

func (g *GAS) Mint(ic *interop.Context, h util.Uint160, amount *big.Int, callOnPayment bool) {
}

func (g *GAS) Burn(ic *interop.Context, h util.Uint160, amount *big.Int) {
}
44 changes: 44 additions & 0 deletions pkg/innerring/internal/metachain/gas/gas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package gas_test

import (
"math/big"
"testing"

"github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/innerring/internal/metachain"
)

func newGasClient(t *testing.T) (*neotest.ContractInvoker, *neotest.ContractInvoker) {
ch, validators, committee := chain.NewMultiWithOptions(t, &chain.Options{
NewNatives: metachain.NewCustomNatives,
})
e := neotest.NewExecutor(t, ch, validators, committee)

return e.ValidatorInvoker(e.NativeHash(t, nativenames.Gas)), e.CommitteeInvoker(e.NativeHash(t, nativenames.Gas))
}

const defaultBalance = 100

func TestGAS(t *testing.T) {
gasValidatorsI, gasCommitteeI := newGasClient(t)
hardcodedBalance := stackitem.NewBigInteger(big.NewInt(defaultBalance * native.GASFactor))

t.Run("committee balance", func(t *testing.T) {
gasCommitteeI.Invoke(t, hardcodedBalance, "balanceOf", gasCommitteeI.Hash)
})

t.Run("new account balance", func(t *testing.T) {
s := gasValidatorsI.NewAccount(t, defaultBalance*native.GASFactor+1)
gasCommitteeI.WithSigners(s).Invoke(t, hardcodedBalance, "balanceOf", s.ScriptHash())
})

t.Run("transfer does not change balance", func(t *testing.T) {
newAcc := gasValidatorsI.NewAccount(t, defaultBalance*native.GASFactor+1)
gasCommitteeI.Invoke(t, stackitem.Bool(true), "transfer", gasCommitteeI.Hash, newAcc.ScriptHash(), 1, stackitem.Null{})
gasCommitteeI.Invoke(t, hardcodedBalance, "balanceOf", newAcc.ScriptHash())
})
}
29 changes: 29 additions & 0 deletions pkg/innerring/internal/metachain/meta/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package meta

import (
"math"
)

const (
// Metadata contract identifiers.
MetaDataContractID = math.MinInt32
MetaDataContractName = "MetaData"
)

const (
// storage prefixes.
metaContainersPrefix = iota
containerPlacementPrefix

// object prefixes.
addrIndex
lockedByIndex
)

const (
// event names.
putObjectEvent = "ObjectPut"

// limits.
maxREPsClauses = 255
)
Loading
Loading