Skip to content

Conversation

@carpawell
Copy link
Member

Contract part of #3742.

Copy link
Contributor

@cthulhu-rider cthulhu-rider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase is needed

panic(fmt.Sprintf("unexpected native contract found: %T", contract))
}
}
return append(newContracts, meta.NewMetadata(neoContract))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta.NewMetadata does not seem resistant to nil arg. I'd precheck it

in general, looking at for-loop, we dont check absence of any contract. If they are required, i'd still prevent this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added required contracts checks to NewCustomNatives

newContracts = append(newContracts, contract)
case *native.Std, *native.Crypto, *native.Oracle, *native.Treasury:
default:
panic(fmt.Sprintf("unexpected native contract found: %T", contract))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this done to not miss new contract?

since native.NewDefaultContracts does not state there will be no more contract, i'd say this is an error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new contract is a significant (and very rare) event, this forces explicit handling of it. Should be ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this done to not miss new contract?

yes, *native.Treasury was even added after this feature was started to be implemented. my idea was that once there is an update in neo-go, tests will start panicking, and we will immediately find out whether we need to adopt a new contract to our side chain or not

g := &GAS{
initialSupply: init,
}
defer g.BuildHFSpecificMD(g.ActiveIn())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer seems redundant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the way every native contract is implemented in neo-go, so i suggest to keep it

return nil
}

// InitializeCache implements the Contract interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// InitializeCache implements the Contract interface.
// InitializeCache implements [native.IGAS] interface.

for all methods

}

// makeUint160Key creates a key from the account script hash.
func makeUint160Key(prefix byte, h util.Uint160) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused too? Seems like some stuff is copy-pasted but not needed

return fmt.Errorf("%d vector has incorrect REP: %w", i, err)
}
rep := repB.Int64()
if rep > maxREPsClauses {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd also check negatives

Nodes keys.PublicKeys
}

func (p Placement) ToStackItem() (stackitem.Item, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason lost resolution for this thread: #3742 (comment)

is used now

}
metaInfo, ok := metaInfoSI.Value().([]stackitem.MapElement)
if !ok {
panic(fmt.Errorf("unexpected deserialized meta information value: expected %T, %T, given", metaInfo, metaInfoSI.Value()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
panic(fmt.Errorf("unexpected deserialized meta information value: expected %T, %T, given", metaInfo, metaInfoSI.Value()))
panic(fmt.Errorf("unexpected deserialized meta information value: expected %T, %T given", metaInfo, metaInfoSI.Value()))

}

if foundSigs == rep {
continue nodesLoop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instruction seems excessive here, condition may be inverted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reimplementation of the byte-contract code from the neofs-contracts problems. fixed

panic("incorrect vub")
}
if vub.Int64() <= int64(ic.BlockHeight()) {
panic("incorrect vub: exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime values may be helpful in exception

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added values everywhere a value is parsed and can be stringified

@@ -0,0 +1,45 @@
package contracts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd strip this directory, can be metachain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont mind

newContracts = append(newContracts, contract)
case *native.Std, *native.Crypto, *native.Oracle, *native.Treasury:
default:
panic(fmt.Sprintf("unexpected native contract found: %T", contract))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new contract is a significant (and very rare) event, this forces explicit handling of it. Should be ok.

)

// nep17TokenNative represents a NEP-17 token contract.
type nep17TokenNative struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. This should be imported from NeoGo native, really.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really sorry, but it is not now

m.AddMethod(md, desc)

desc = native.NewDescriptor("registerMetaContainer", smartcontract.VoidType,
manifest.NewParameter("cID", smartcontract.Hash256Type))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

container

m.AddMethod(md, desc)

desc = native.NewDescriptor("unregisterMetaContainer", smartcontract.VoidType,
manifest.NewParameter("cID", smartcontract.Hash256Type))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well.

panic("container does not support chained metadata")
}

sigsVectorsRaw, ok := args[1].Value().([]stackitem.Item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows current container contract, but eventually it can be removed from parameters, nodes can sign transaction directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will require responding there with a signature not of an object's metadata, but with a signature of some predefined transaction. is that what you meant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Another option is a custom verification callback.

}
}

// required
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cid is checked separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used in other checks above (container must exist and be registered as one that supports meta)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have similar checks at the same place.


for _, sig := range sigVectors[i] {
for _, node := range placement[i].Nodes {
if node.Verify(sig, metaHash) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i only suggest sorting signatures by public keys. requires support on the IR side and on the SN side

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just about sorting. Remember, currently signatures are verified in verify() method of Proxy contract. This scales well. Checking them during transaction execution doesn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But sorting is beneficial anyway and easily done.

}
if v, ok := getFromMap(metaInfo, "firstPart"); ok {
firstPart, err := v.TryBytes()
if err != nil || len(firstPart) != smartcontract.Hash256Len {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sha256 extraction is pretty popular

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok-ok

if err != nil {
panic(err)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's it, no processing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the secondary index must be in the same chain? my first implementation only needs side chain to check metadata and then notify about it. all the storage nodes handle notification on their own

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Among things current structure tries to solve is state synchronization. There is everything needed for it in blockchain, but if you're just throwing an event it all doesn't work. Primary index (based on submitted data) must be built directly on-chain. Then seconday one (header-based) is a different story.

@carpawell carpawell force-pushed the feat/meta-data-native-contract branch 2 times, most recently from bd68082 to c8ae0ca Compare December 30, 2025 17:31
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.74%. Comparing base (97f9696) to head (1f840ee).

Files with missing lines Patch % Lines
pkg/innerring/internal/metachain/contracts.go 0.00% 30 Missing ⚠️
pkg/innerring/internal/blockchain/blockchain.go 0.00% 2 Missing ⚠️
pkg/innerring/internal/metachain/chain.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3759      +/-   ##
==========================================
- Coverage   25.77%   25.74%   -0.03%     
==========================================
  Files         657      659       +2     
  Lines       42163    42195      +32     
==========================================
- Hits        10867    10863       -4     
- Misses      30308    30344      +36     
  Partials      988      988              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Also, implement new MetaData contract and GAS contract implementation without
economic.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
@carpawell carpawell force-pushed the feat/meta-data-native-contract branch from c8ae0ca to 1f840ee Compare December 30, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants