Coder Social home page Coder Social logo

nethermindeth / blockifier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from starkware-libs/blockifier

1.0 1.0 4.0 8.33 MB

Blockifier is a Rust implementation for the transaction-executing component in the StarkNet sequencer, in charge of creating state diffs and blocks.

License: Apache License 2.0

Shell 0.13% Python 0.59% Rust 91.35% Starlark 0.01% Cairo 7.78% JavaScript 0.12% Dockerfile 0.02%

blockifier's Introduction


GitHub Workflow Status codecov

Table of Contents

About

Blockifier is a Rust implementation of the component in the Starknet sequencer that executes transactions, and is in charge of creating state diffs and blocks.

Roadmap

The Blockifier is a step towards a decentralized sequencer client for Starknet, allowing anyone to run one. We'll add more milestones to this table once we finish the first one, where we blockify transactions sequentially, including all existing functionality.

name status
Add the ability to execute a block and output a state diff.
Integrate with the existing Starknet Sequencer by replacing its current transaction-blockifying component, which is written in Python.
Implement optimistic concurrency of transaction execution.
Extend the Blockifier into a full Starknet sequencer, written in Rust, replacing the one currently in use.

Support

Reach out to the maintainer at one of the following places:

Security

Blockifier follows good security practices, but 100% security cannot be assured. Blockifier is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

License

This project is licensed under the Apache 2.0 license.

See LICENSE for more information.

blockifier's People

Contributors

adi-yakovian avatar alon-dotan-starkware avatar alonh5 avatar amosstarkware avatar aner-starkware avatar arnistarkware avatar avi-starkware avatar avivyossef-starkware avatar ayeletstarkware avatar barak-b-starkware avatar domhenderson avatar dorimedini-starkware avatar elintul avatar giladchase avatar ilyalesokhin-starkware avatar liorgold2 avatar meship-starkware avatar mohammadnassar1 avatar nimrod-starkware avatar nirlevi-starkware avatar noaov1 avatar oristarkware avatar spapinistarkware avatar tdelabro avatar tzahitaub avatar varex83 avatar xrvdg avatar yael-starkware avatar yoni-starkware avatar zuphitf avatar

Stargazers

 avatar

Watchers

 avatar

blockifier's Issues

Moving Native Compilation outside of the Blockifier

General Idea

The Native Blockifier is capable of executing Starknet Contracts compiled ahead of time using the Cairo Native compiler. The way it works currently is:

  1. The Blockifier receives a Starknet Contract in Sierra.
  2. It compiles it down to Machine Code.
  3. Executes it.
  4. Returns the Execution Trace.

This setup, although initially good enough for testing, won't be good in Production. The main reason is that it creates a bottleneck during execution where it will stop just to compile a file something that could have already been done by this point. It also raises other issue such as what to do with the compile file, store it somewhere (and how long) or delete it.

This two problems are not for the Blockifier to take care of but by the Sequencer/Nodes. We need to update the workflow, removing the compilation step, to:

  1. The Blockifier receives a Starknet Contract compiled with Cairo Native.
  2. Executes it.
  3. Returns the transaction trace

More technical

We currently have a SierraContractClass representing a Contract Definition written in Sierra. We should swap it for a NativeContractClass representing a Contract Definition compiled with Native.

This will break the general flow of the program since everything is based on getting this Sierra and compiling it. Also, I don't know how difficult it could be to represent a Natively Compiled Contract as a Rust object (maybe it's very easy).

Finally, you should take into account testing. Testing uses Sierra files which are compiled with Native during the test execution. Since now we won't have anymore compilation, those should be compiled (by having them pre-compiled) or compiling them directly in execution. We can discuss the best solution for this.

Juno

The problem of solving this issue alone is that we are going to end up with something un-usable since there isn't any Node prepared to work with the Native compiler.

The solution for this is that we are going to prep Juno in a patchy way to perform the compilation on it's side. Juno communicates with the Blockifier using CGo (an FFI). This communication layer is written partly in Go and partly in Rust.

The Patchy solution comes when the Juno sends the Sierra to the Blockifier, being able to "capture" it in the Rust side of the translation, compiling it with Native, and sending that instead. Maybe we can improve over this idea.

Now, this won't fix any of the problems mentioned, but for the scope of our tests we don't care about them. We only care about Native Blockifier performing the same as Base Blockifier.
What this will do is to make our current Native Blockifier prototype achieve its final form, making it ready (or almost-ready) for production.

Find & Fix Mismatch in in Get Execution Info result

Executing get_execution_info returns a TxInfo as parts of its result. There is a missmatch between the account_contract_address returned by the syscall and the one expected.

The syscall is returning the correct one but it seems that Native is reading the value where it shouldn't (perhaps because it is boxed).

To solve the issue we need to (i) learn what is causing this error, (ii) fix it by either updating the code or our dependencies

Share secp256 implementation between native and non-native.

In #102 native's secp256 syscall calls were simplified by inlining and making the operation stateless. These simplifications can be ported back to the non-native secp256 syscall handler such that the native and non-native syscall handler can share parts of the implementation.

Native resources should match the VMs

Gas handling for Native is still not implemented. When real testing this cause for transactions that should fail for insufficient founds are actually being executed, possibly affecting transactions later on.

We need to implement a mechanisms for Native transactions to match the resources used by the VM.

Fix Native Keccak

Keccak is failing. It is producing the wrong hash value.

    #[external(v0)]
    fn test_keccak(ref self: ContractState) {
        let mut input: Array::<u256> = Default::default();
        input.append(u256 { low: 1, high: 0 });

        let res = keccak::keccak_u256s_le_inputs(input.span());
        assert(res.low == 0x587f7cc3722e9654ea3963d5fe8c0748, 'Wrong hash value');
        assert(res.high == 0xa5963aa610cb75ba273817bce5f8c48f, 'Wrong hash value');
    }

Test Get Execution V1

Currently, get_execution_info_v1 is missing tests due to compilers defaulting to version v2 when compiling.

Nonetheless, is still possible to find versions v1 when executing transactions. We should find a way to add tests for this as seamlessly as possible.

Make fallback system

The Blockifier will be using two systems to execute transactions:

  1. The battle-tested VM
  2. The new and faster but still unreliable Cairo Native

It will default to the Cairo Native one but a system must be put in place when the this fails to start execution using the first one.

Points are failures can occur twice:

  • During Compilation
  • During Execution

We will asume that Naive will return their errors wrapped in a result.

Update test_get_execution_info to use the updated testing framework.

When executing test_get_execution_info it keeps the old test designs, where both Cairo1 and Cairo0 contracts are initialized and an input flag is_legacy determines which one to execute. This can be re-structured to remove the flag and set the input directly to Cairo0 test contract in the right places.

Split Event Emitting Syscall Test

Event emitting test consist of four different test cases. Divide the test into 4 minor tests accordingly.

This will let us see with a more granularity where Native is failing and the VM is not.

Implement secp256k1

It should be implemented in the Native Syscall Handler. Also, make sure the test is available for Native as well

Add unit tests to Sierra Utils

We have a couple of core functionality in Sierra Utils. Most of this functionality is untested which makes it vulnerable to changes that could affect their behaviour.

We should add unit tests for each of them

Point free secp256 on native

Native doesn't need to keep track of points when executing secp256 operations. Rewrite the instructions in terms of Affine<Curve> instead of the old syscall handler.

Investigate struct ordening `u256` in Cairo and Native/Blockifier

Accessing the high part of a U256 from within Rust gives the same result as accessing the low part of u256 from within Cairo. This seems to point to the order of the struct getting mixed up. We currently workaround this in both keccak and secp in the native starknet sycall handler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.