Skip to content

Conversation

@bragaigor
Copy link
Contributor

@bragaigor bragaigor commented Nov 14, 2025

Fixes NIT-4074

Adds 2 new wasm imports:

  • programPrepare
  • programRequiresPrepare

program_requires_prepare:

Arguments:

  • modulehash

Returns: boolean

Called just beforecall to newProgram.

Jit/arbitrator implementation: always return false

program_prepare:

Arguments:

  • statedb - EVM database
  • module_hash - the activated program modulehash (used as signifier)
  • wasm - the wasm code,
  • code_hash_ptr - Contract's code hash
  • page_limit - Stylus page limit
  • arbos_version_for_gas - activation gas
  • program - program to be activated
  • stylus_version
  • debug

Returns: nothing

Only called if program_requires_prepare returns true.

Arbitrator / jit implementation: nop

In order to make implementation easier and more maintainable we create a handleProgramPrepare so that we can get access to all parameters program_prepare requires.

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
4487 4 4483 0
View the top 3 failed tests by shortest run time
TestRedisProduceComplex/one_producer,_all_consumers_are_active
Stack Traces | 1.310s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
�[36mDEBUG�[0m[12-19|12:07:00.896] Redis stream consuming                   �[36mconsumer_id�[0m=32677db1-a3d7-4ee4-80cf-678ae61b3498 �[36mmessage_id�[0m=1766146019756-3
�[36mDEBUG�[0m[12-19|12:07:00.896] consumer: setting result                 �[36mcid�[0m=32677db1-a3d7-4ee4-80cf-678ae61b3498 �[36mmsgIdInStream�[0m=1766146019756-3  �[36mresultKeyInRedis�[0m=result-key:stream:f20f8812-dcbd-419f-8fc1-88777fd3feb3.1766146019756-3
�[36mDEBUG�[0m[12-19|12:07:00.896] consumer: xdel                           �[36mcid�[0m=3179869a-8669-423d-be24-f2a6ca0b1242 �[36mmessageId�[0m=1766146019756-1
�[36mDEBUG�[0m[12-19|12:07:00.896] consumer: xdel                           �[36mcid�[0m=0643a5bd-6cb7-466a-a98a-b1244a514632 �[36mmessageId�[0m=1766146019756-0
�[36mDEBUG�[0m[12-19|12:07:00.896] Redis stream consuming                   �[36mconsumer_id�[0m=f2cd2f6b-7613-4d67-939a-07953bae0b57 �[36mmessage_id�[0m=1766146019756-4
�[36mDEBUG�[0m[12-19|12:07:00.900] consumer: setting result                 �[36mcid�[0m=f2cd2f6b-7613-4d67-939a-07953bae0b57 �[36mmsgIdInStream�[0m=1766146019756-4  �[36mresultKeyInRedis�[0m=result-key:stream:f20f8812-dcbd-419f-8fc1-88777fd3feb3.1766146019756-4
�[36mDEBUG�[0m[12-19|12:07:00.896] consumer: xack                           �[36mcid�[0m=32677db1-a3d7-4ee4-80cf-678ae61b3498 �[36mmessageId�[0m=1766146019756-3
�[36mDEBUG�[0m[12-19|12:07:00.900] consumer: xack                           �[36mcid�[0m=ec7bbc1d-ba95-41a6-9e4e-1b99f0a171d7 �[36mmessageId�[0m=1766146019756-2
�[36mDEBUG�[0m[12-19|12:07:00.900] consumer: xdel                           �[36mcid�[0m=145dbd3b-0497-43c1-8107-78a562744cac �[36mmessageId�[0m=1766146019739-0
�[36mDEBUG�[0m[12-19|12:07:00.901] trimming                                 �[36mxTrimMinID�[0m=1766146019756-2 �[36mtrimmed�[0m=0 �[36mtrim-err�[0m=<nil>
�[36mDEBUG�[0m[12-19|12:07:00.901] consumer: xdel                           �[36mcid�[0m=32677db1-a3d7-4ee4-80cf-678ae61b3498 �[36mmessageId�[0m=1766146019756-3
�[36mDEBUG�[0m[12-19|12:07:00.902] consumer: xdel                           �[36mcid�[0m=ec7bbc1d-ba95-41a6-9e4e-1b99f0a171d7 �[36mmessageId�[0m=1766146019756-2
�[36mDEBUG�[0m[12-19|12:07:00.902] consumer: xack                           �[36mcid�[0m=f2cd2f6b-7613-4d67-939a-07953bae0b57 �[36mmessageId�[0m=1766146019756-4
�[36mDEBUG�[0m[12-19|12:07:00.902] consumer: xdel                           �[36mcid�[0m=f2cd2f6b-7613-4d67-939a-07953bae0b57 �[36mmessageId�[0m=1766146019756-4
�[36mDEBUG�[0m[12-19|12:07:00.919] checkResponses                           �[36mresponded�[0m=70 �[36merrored�[0m=0 �[36mchecked�[0m=91
�[36mDEBUG�[0m[12-19|12:07:00.924] redis producer: check responses starting
�[36mDEBUG�[0m[12-19|12:07:00.944] checkResponses                           �[36mresponded�[0m=21 �[36merrored�[0m=0 �[36mchecked�[0m=21
�[31mERROR�[0m[12-19|12:07:00.944] Error from XpendingExt in getting PEL for auto claim �[31merr�[0m="context canceled" �[31mpendingLen�[0m=0
�[36mDEBUG�[0m[12-19|12:07:01.002] Error destroying a stream group          �[36merror�[0m="dial tcp 127.0.0.1:41079: connect: connection refused"
--- FAIL: TestRedisProduceComplex/one_producer,_all_consumers_are_active (1.31s)
TestValidationInputsAtWithWasmTarget
Stack Traces | 2.840s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
=== CONT  TestValidationInputsAtWithWasmTarget
    common_test.go:693: BuildL1 deployConfig: DeployBold=false, DeployReferenceDAContracts=false
    validation_inputs_at_test.go:70: goroutine 1653508 [running]:
        runtime/debug.Stack()
        	/opt/hostedtoolcache/go/1.25.5/x64/src/runtime/debug/stack.go:26 +0x5e
        github.com/offchainlabs/nitro/util/testhelpers.RequireImpl({0x40f1690, 0xc09c1c9500}, {0x40ae940, 0xc0a83d9ce0}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/util/testhelpers/testhelpers.go:29 +0x55
        github.com/offchainlabs/nitro/system_tests.Require(0xc09c1c9500, {0x40ae940, 0xc0a83d9ce0}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/system_tests/common_test.go:2003 +0x5d
        github.com/offchainlabs/nitro/system_tests.TestValidationInputsAtWithWasmTarget(0xc09c1c9500)
        	/home/runner/work/nitro/nitro/system_tests/validation_inputs_at_test.go:70 +0x970
        testing.tRunner(0xc09c1c9500, 0x3d31328)
        	/opt/hostedtoolcache/go/1.25.5/x64/src/testing/testing.go:1934 +0xea
        created by testing.(*T).Run in goroutine 1
        	/opt/hostedtoolcache/go/1.25.5/x64/src/testing/testing.go:1997 +0x465
        
    validation_inputs_at_test.go:70: �[31;1m [] failed calculating position for validation: batch not found on L1 yet �[0;0m
INFO [12-19|12:17:51.682] HTTP server stopped                      endpoint=127.0.0.1:39937
TRACE[12-19|12:17:51.682] P2P networking is spinning down
--- FAIL: TestValidationInputsAtWithWasmTarget (2.84s)
TestRedisProduceComplex
Stack Traces | 20.800s run time
=== RUN   TestRedisProduceComplex
=== PAUSE TestRedisProduceComplex
=== CONT  TestRedisProduceComplex
--- FAIL: TestRedisProduceComplex (20.80s)

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@bragaigor bragaigor force-pushed the braga/program-prepare-arbitrator branch from 2fb49b5 to fcc1383 Compare November 16, 2025 12:34
@bragaigor bragaigor marked this pull request as ready for review November 19, 2025 11:20
@bragaigor bragaigor force-pushed the braga/program-prepare-arbitrator branch from fcc1383 to 5355d3f Compare December 1, 2025 19:33
@bragaigor bragaigor assigned bragaigor and tsahee and unassigned tsahee and bragaigor Dec 1, 2025
rauljordan
rauljordan previously approved these changes Dec 5, 2025
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

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

The changes are pretty straightforward, LGTM

@tsahee tsahee assigned eljobe and tsahee and unassigned tsahee and eljobe Dec 9, 2025
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

small request

statedb.AddStylusPages(program.footprint)
defer statedb.SetStylusPagesOpen(open)

handleProgramPrepare(statedb, moduleHash, contract.Address(), contract.Code, contract.CodeHash, params.MaxWasmSize, params.PageLimit, evm.Context.Time, debugMode, program, runCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's take it one small step forward:

  • have handleProgramPrepare return localAsm []byte.
  • have the native implementation be current lines 230.. 238 that calls getCompiledProgram and extracts just the correct impl from the map
  • remove getCompiledProgram from the wasm implementation and replace it with what you currently have for handleProgramPrepare + return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8d0988e . I kept the current panic in case getCompiledProgram returns an error. Let me know if we prefer handleProgramPrepare to return an error instead.

@tsahee tsahee assigned bragaigor and unassigned tsahee Dec 9, 2025
@bragaigor bragaigor force-pushed the braga/program-prepare-arbitrator branch from 6be417c to c661d08 Compare December 9, 2025 10:21
@bragaigor bragaigor assigned tsahee and unassigned bragaigor Dec 9, 2025
@tsahee tsahee added the after-next-version This PR shouldn't be merged until after the next version is released label Dec 10, 2025
@tsahee
Copy link
Contributor

tsahee commented Dec 10, 2025

labeling it after-next-version, by which I mean after arbos 52 with customDA support

tsahee
tsahee previously approved these changes Dec 10, 2025
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.15%. Comparing base (5b59a1a) to head (63fc9b7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4013      +/-   ##
==========================================
+ Coverage   33.35%   35.15%   +1.80%     
==========================================
  Files         453      453              
  Lines       55536    55539       +3     
==========================================
+ Hits        18524    19527    +1003     
+ Misses      33774    32566    -1208     
- Partials     3238     3446     +208     

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
ProgramPrepare needs the same parameters as handleProgramPrepare
so we could either move ProgramPrepare closer to
handleProgramPrepare or inside of it. In light that ProgramPrepare
can update in the future we move it closer to handleProgramPrepare

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Update handleProgramPrepare() to return localAsm []byte

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@bragaigor
Copy link
Contributor Author

Added required changelog file

@bragaigor bragaigor requested a review from tsahee December 19, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

after-next-version This PR shouldn't be merged until after the next version is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants