Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

New Module Hash Model #168

Merged
merged 20 commits into from
Oct 16, 2023
Merged

Conversation

rachel-bousfield
Copy link
Contributor

@rachel-bousfield rachel-bousfield commented Oct 13, 2023

This PR leverages the new onchain module hash to make a number of simplifications and improvements

  • We no longer tie activation to account objects. You'll notice in the Geth PR it's entirely module hash based.
  • Validators now store activated prover Module's in the db, which they pre-fetch before fraud proofs & block validation.
  • JIT validation no longer requires any pre-activation. We load existing Asm from disk.
  • Activation pricing now happens in Rust
  • We patch ToB's table size concern.
  • Other efficiency improvements, for example reducing the number of Asm copies.

This PR includes conceptual changes that will be easier to track by adopting the following nomenclature.

  • activation the process of instrumenting a WASM to produce an asm and module
  • asm the instrumented, x86 or ARM version of a Stylus contract nodes run in the happy case
  • module the instrumented, WAVM version of a Stylus contract nodes link-in when fraud proving
  • module hash the hash of a module, which uniquely determines a module and asm pair

Associated PRs

@cla-bot cla-bot bot added the s label Oct 13, 2023
@rachel-bousfield rachel-bousfield changed the title Onchain compiled edits New Module Hash Model Oct 13, 2023
@rachel-bousfield rachel-bousfield marked this pull request as ready for review October 13, 2023 23:04
Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -35,60 +35,47 @@ extern "C" {
#[repr(C, align(256))]
struct MemoryLeaf([u8; 32]);

/// Compiles and instruments a user wasm.
/// Instruments a user wasm.
Copy link
Member

Choose a reason for hiding this comment

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

Instruments and activates?

sp: usize,
) {
let mut sp = GoStack::new(sp);
let wasm = sp.read_go_slice_owned();
let page_limit = sp.read_u16();
let version = sp.read_u16();
let debug = sp.read_bool32();
let (out_hash_ptr, out_hash_len) = sp.read_go_slice();
let module_hash = sp.read_go_ptr();
let gas = sp.read_go_ptr();
Copy link
Member

Choose a reason for hiding this comment

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

maybe add comment about modules_hash being output, gas being input & output

@@ -342,7 +337,7 @@ func (p Programs) setProgram(codehash common.Hash, program Program) error {
if err != nil {
return err
}
return p.compiledHashes.Set(codehash, program.compiledHash)
return p.compiledHashes.Set(codehash, program.moduleHash)
Copy link
Member

Choose a reason for hiding this comment

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

update p.compiledHashes to p.moduleHashes?

Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@PlasmaPower PlasmaPower left a comment

Choose a reason for hiding this comment

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

A couple minor additional comments but largely LGTM

@@ -93,6 +93,7 @@ func activateProgram(
func callProgram(
address common.Address,
program Program,
Copy link
Contributor

Choose a reason for hiding this comment

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

This program parameter is no longer used now that moduleHash is passed in separately.

@@ -13,7 +13,7 @@ import (
type Burner interface {
Burn(amount uint64) error
Burned() uint64
GasLeft() *uint64
GasLeft() *uint64 // SystemBurner's panic
Copy link
Contributor

Choose a reason for hiding this comment

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

The apostrophe doesn't read well to me, could you do

// `SystemBurner`s panic

instead?

Copy link
Contributor

@PlasmaPower PlasmaPower left a comment

Choose a reason for hiding this comment

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

LGTM

@rachel-bousfield rachel-bousfield merged commit c33c522 into onchain-compiled Oct 16, 2023
14 checks passed
@rachel-bousfield rachel-bousfield deleted the onchain-compiled-edits branch October 16, 2023 06:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants