[ANN] i n e r t i a - NoM Smart Contracts


i n e r t i a

  1. the natural tendency of objects in motion to stay in motion
  1. an object’s resistance to changes in its motion
  1. an object with more inertia will also have a greater potential to maintain its momentum

a novel WASM-based smart contract framework, purpose-built for the Network of Momentum.

URL: GitHub - EovE7Kj/inertia: smart contracts for momentum

Team: EovE7Kj and Co.

  • ACTIVELY SEEKING ADDITIONAL DEVELOPERS.

Funding

PHASE 1/?
Total Requested Funding for phase 1 : 5000 ZNN and 50000 QSR

So far, we’ve made progress integrating key components for blockchain interaction, WASM contract handling, and a gas metering mechanism. Here’s a summary of what we’ve done:

1. WASM Runtime Integration

  • We’ve built the foundational logic for loading and executing WebAssembly (WASM) contracts. This is done using the wasmer-go library, which allows us to load WASM modules and execute functions from these modules.
  • A WASMRuntime struct was implemented to manage the WASM engine, store, and module.
  • We added methods to load and execute contracts (LoadContract and ExecuteContract), which interface with the WASM runtime.

2. Gas Metering

  • To prevent infinite execution and ensure fair resource usage, we’ve added a simple gas metering mechanism through the QasMeter struct. This tracks gas usage and ensures that a contract cannot exceed a predefined limit.
  • The ConsumeQas method within QasMeter is responsible for checking if the contract execution exceeds the gas limit and throws an error if it does.

3. Contract Execution with Gas Consumption

  • We’ve modified the contract execution flow to track the gas consumption associated with each contract execution. Each function call in the contract deducts gas from the QasMeter.
  • In the ExecuteContract method, we first check if the contract has enough gas to proceed. If not, an error is thrown, and the operation is aborted.

4. API Exposure and Contract Invocation

  • The ExposeAPI method was introduced to allow interaction between the blockchain environment and the contract. This method registers functions that the WASM module can call, such as write_state, which interacts with the blockchain’s state.
  • We’ve created a function to handle the full contract invocation cycle, from loading the contract to executing the functions and interacting with the blockchain API (HandleContractInvocation).

5. Testing

  • A test/ directory was established with a trivial contract.wasm file and a Go test file (test.go). This will allow us to test the WASM contract handling and gas metering mechanisms in a controlled environment.

Roadmap

  1. WASM Runtime Interface: Integrate a WASM runtime library into go-zenon to handle smart contract execution. The runtime should include sandboxing for security and gas metering for performance.
  2. Develop a Contract API: Expose network functionalities (e.g., state storage, transactions) to WASM contracts via APIs, enabling them to interact with the NoM.
  3. Update Node Logic: Extend transaction processing logic to validate and execute WASM contracts, ensuring consensus mechanisms are updated accordingly.
  4. Tooling for Developers: Provide SDKs or compilers that support compiling smart contracts from languages like Rust or AssemblyScript into WASM, along with debugging and deployment tools.
  5. Governance and Upgrades: Ensure proper governance around smart contract execution, potentially requiring changes to the consensus rules or protocol.

9 Likes

Thank you for this update. What sort of consensus or protocol changes do you have in mind?

Also, was the AZ you submitted for the repo that was just added? Or does it include other items in the roadmap? I reviewed the code and looks like it’s exactly what you described: “WASM contract handling, and a gas metering mechanism”.

For those if you who cannot read the code. Here is the gas metering mechanism:

package wasm

type QasMeter struct {
	qasLimit uint64
	qasUsed  uint64
}

func NewQasMeter(limit uint64) *QasMeter {
	return &QasMeter{qasLimit: limit, qasUsed: 0}
}

func (gm *QasMeter) ConsumeQas(amount uint64) error {
	if gm.qasUsed+amount > gm.qasLimit {
		return fmt.Errorf("out of qas")
	}
	gm.qasUsed += amount
	return nil
}

func (gm *QasMeter) RemainingQas() uint64 {
	return gm.qasLimit - gm.qasUsed
}

func (gm *QasMeter) Reset(limit uint64) {
    gm.qasLimit = limit
    gm.qasUsed = 0
}

and here is the WASM contract handling

package wasm

import (
        "fmt"
        "io/ioutil"

        "github.com/wasmerio/wasmer-go/wasmer"
)

type WASMRuntime struct {
        engine  *wasmer.Engine
        store   *wasmer.Store
        module  *wasmer.Module
        imports *wasmer.ImportObject
        qasMeter *QasMeter
}

var gasCosts = map[string]uint64{
    "write_state": 200,
}

// initialize runtime
func NewWASMRuntime(qasLimit uint64) *WASMRuntime {
        engine := wasmer.NewEngine()
        store := wasmer.NewStore(engine)
        return &WASMRuntime{
                engine: engine,
                store:  store,
                qasMeter: NewQasMeter(qasLimit),
        }
}

func (r *WASMRuntime) LoadContract(filepath string) error {
        wasmBytes, err := ioutil.ReadFile(filepath)
        if err != nil {
                return fmt.Errorf("failed to read WASM file: %w", err)
        }

        module, err := wasmer.NewModule(r.store, wasmBytes)
        if err != nil {
                return fmt.Errorf("failed to compile WASM module: %w", err)
        }

        r.module = module
        return nil
}

func HandleContractInvocation(tx *Transaction, api *BlockchainAPI, runtime *WASMRuntime) error {
        // Load contract
        err := runtime.LoadContract(tx.ContractBinary)
        if err != nil {
                return fmt.Errorf("failed to load contract: %w", err)
        }

        // Expose API
        runtime.ExposeAPI(api)

        // Execute function
        _, err = runtime.ExecuteContract(tx.FunctionName, tx.Args...)
        if err != nil {
                return fmt.Errorf("contract execution failed: %w", err)
        }

        return nil
}

func (r *WASMRuntime) ExposeAPI(api *BlockchainAPI) {
    r.imports.Register("env", map[string]wasmer.Int32ToVoid{
        "write_state": func(key, value int32) {
            cost := gasCosts["write_state"]
            if err := r.qasMeter.ConsumeQas(cost); err != nil {
                fmt.Printf("Error: %v\n", err)
                return
            }
            api.WriteState(int32ToString(key), int32ToString(value))
        },
    })
}


func (r *WASMRuntime) ExecuteContract(functionName string, args ...interface{}) ([]byte, error) {
    if err := r.qasMeter.ConsumeQas(100); err != nil {
        return nil, err
    }

    instance, err := wasmer.NewInstance(r.module, r.imports)
    if err != nil {
        return nil, fmt.Errorf("failed to instantiate WASM module: %w", err)
    }
    defer instance.Close()

    function, err := instance.Exports.GetFunction(functionName)
    if err != nil {
        return nil, fmt.Errorf("function '%s' not found: %w", functionName, err)
    }

    result, err := function(args...)
    if err != nil {
        return nil, fmt.Errorf("failed to execute function '%s': %w", functionName, err)
    }

    if err := r.qasMeter.ConsumeQas(uint64(len(result.([]byte)))); err != nil {
        return nil, err
    }

    return result.([]byte), nil
}
  • How many additional developers are needed, and what skills are you looking for?
  • What specific deliverables will be completed in Phase 1?
  • How many phases are anticipated, and what will the total funding look like?
  • What is the estimated timeline for completing Phase 1?
  • Are there any critical dependencies or risks that could delay progress?

@EovE7Kj how does this work?

The test.go is not functional.

1 Like

Can you take it easy on the AZ submissions until theres some more substance in the repos? Why are you so keen to keep submitting after only making a forum post?

Until we can get more clarity on this work I’ve voted no.

I definitely support this work, but I’m confused by this last commit, the work in it, and the roadmap.

I’m going to go full-Linus here, and if it upsets the SAME ~20 people here (and the 5 other identical forums), so be it.

This is literally the initial commit for a project that will take at least 10 months to develop, test, and integrate.

What’s committed so far is preliminary work on WASM runtime integration. You know, the foundation for everything else that’ll follow.

  • 99% of my work lives in a Git repo. I commit constantly—every few minutes. I have 10 git aliases in my rc just for this purpose. Any real developer will tell you why. If you need me to explain it too, we’re having the wrong conversation.
  • The repo is my dev process. It’s not here to be a slideshow for Pillars or a showcase for anyone expecting deliverables after THE FIRST commits. It’s called work in progress.
  • And Git? It’s a tool to organize and maintain ongoing projects. Not to ship you a product after the first step.

The repo is my dev work, not some elevator pitch to convince you I know what I’m doing.


I have a full-time, demanding job. I travel constantly. I spend weeks away from my family. And yet, I’ve spent months of my free time working on these projects—because I believe in this Network. I don’t have the time (or frankly the patience) to waste on explaining why we need Sentinels for smart contracts or walking everyone through the same WP you’ve all already read.

If what you want is a flashy slide deck to impress the crypto Twitter crowd, allocate some more AZ funds for another marketing submission.


This is open development. I thought submissions keep the community informed and engaged with ongoing progress. If transparency about early stages of a long development cycle is something you have a problem with, maybe you need to think about what AZ is supposed to be for.

You want “substance”? Then define what the hell “substance” means a first commit into a project like this.

“ZENON is community”

Back when the WP droppped, it looked like the OG BTC community. This… this is not that.

Dont trust, verify.
“PrIcE gO uP.” - Satoshi Nakamoto

6 Likes

To be fair I do believe the community is being a bit harsh towards @EovE7Kj . He did not ask for funding and claim the product to be finished- the AZ request is literally in its proposal phase- a placeholder cementing a certain commitment.

Asking for substance is a more plausible request when it actually comes to the request of funding and even then how many AZs have we passed for a whole lot less?

4 Likes

Professor, we gotchu. Please tell us how we can help by setting up a requirements list so we can find devz to assist you in integrating zApps.

The core community knows that good things take time. Many of us have been holding for a long time and will continue to do so, no matter what.

As per your comments on the .network website, there is a web dev currently giving it a makeover to appeal to builders instead of speculators.

Satoshi 4 life — may his spirit live forth in us aliens.

3 Likes

Thanks for the reply.

This is not a new conversation, i assumed you were around for other submissions where the lack of well defined goals and objectives has grown into an issue of confidence for the community. We are simply asking for more information on what you intend to build.

Im mainly asking why youre setting this kind of example, ie full AZ submissions with only broad descriptions for whats to be expected. Timeline and actionable goals would mean alot.

If this the initial commit for a certain length of work, 10 months you think? why wouldnt you describe that scope in the AZ? How many phases?

Appreciate any information that will lead to clearer expectations of your work so ppl can figure out on their own where that equates to value for NoM.

2 Likes

Well if we are going full retard, let’s go for it.

You are not the only person here with a full time and demanding job. I also travel all over the country and manage money for other people. You are not the only person here with world class skillz. Does your dad work at Nintendo too?

I might not write code that is consequential to the network but I’ve dedicated all my free time for YEARS to help this network. So join the club. You are not the only one stretched thin doing hard work. In fact, the same retarded 20 people you refer to are all in the same boat. We bust our ass for this project and have nothing but good intentions. No one here is attacking you. We want to understand so we can help and improve the project.

You asked us to help you find devs and be more vocal about the project. Why would you ask for us to help if we cannot understand what you are doing. So clearly we are asking retarded questions. And I’m sure they are irritating. We try getting answers (in TG) before we post here, but it’s the same old bullshit… read between the lines.

If this is an individual effort I get that too. Just say that. I’m going to do X. It’s going to do Y. It’s going to cost about Z. I need help from smart devs but ONLY if you can solve this… In the meantime, don’t ask me questions I’ll be back later. But if you want to engage the community (or expect us to do something) you need to expect to do some hand to hand combat with some autistic retards.

Honestly? This is a massive slap in the face to the people here busting their ass. Maybe you think you are the only person here working hard. NEWS FLASH!!! You aren’t.

2 Likes

The code in the repository you’re showcasing is not functional, yet you state you’ve “made progress integrating key components for blockchain interaction, WASM contract handling, and a gas metering mechanism.”.

Why does test.go have such obvious errors?

3 Likes

Guys, people that are developing and and doing work for the project, are doing really good job. The community really appreciates it!

Please do not fight over some missunderstandings, we are all on the same side and want Zenon to suceed!

And I want to say Thank You All for putting in all those efforts!

2 Likes

Let’s not forget the base AZ process involves A) the initial submission (i.e. pillars vote that the proposal is warranted and worthwhile) and B) subsequent funding requests after delivery.

This submission is currently only for A.

Questions should be asked to clarify deliverables, costings and time estimates etc.

Discourse and discussion is good! Let’s be respectful and helpful though.

I support this proposal - @EovE7Kj has a proven track record of development, and as explained his repo is WIP and he’ll update us here as progress is made for major milestones I imagine.

When phases are submitted for funding that should be the trigger for reviewing code and effort

1 Like

If you support this proposal, can you please explain to me what it includes? Have you looked at the repo? Is he asking for a full AZ for what has been submitted?

1 Like

Dont Trust, BUT
Community Unable to Clarify

1 Like

Just a question - do you just jump into a codebase and start firing away code at random? Even when there is no readme in the parent folder? Are you familiar with typical software project structure? ./test/ dir is almost always exclusively for the developer testing.

You’re like someone walking into a car factory and being stunned to find that the cars are not fully-assembled.
Crash test? What is this thing, the car is ruined! I don't plan to drive straight into a wall!

It seems like nobody here has pieced together that at the present the repository is basically framework-level WASM interface intended to patch into a running node. ./test/ will grow as the testing progresses! You don’t have all the pieces because:

  1. the solution is still being formulated
  2. the code is still being rewritten, and will likely be reworked
  3. THE REPO IS FOR THE DEV(s) WRITING IT

Does everyone here understand what git is?

I wasn’t delivering YOU a piece of software. I was only making public (parts of) my own local git repo.

4 Likes

I meant no disrespect to you or anyone else working on this project.

I just get the feeling that around here, development takes a back seat to ephemeral chasing after exposure. I don’t want people to notice this blockchain because it’s pumping like XRP. I want people to notice this blockchain because it does shit that no other blockchain can do. And it seems like people here want that too, but their feeble solution is to sit around and wait for professor-z and co. to miraculously reappear and do it all for us.

The pieces are there. You need people to actually DO the work.

6 Likes

I believe this is the deliverable list for the AZ ask - I don’t expect to see it in the repo until funding phases are raised