Skip to content

Changed hashing schema implementation to match provider-NIT-4724#4586

Open
mahdy-nasr wants to merge 2 commits intomasterfrom
implement-string-hashing-for-address-filtering
Open

Changed hashing schema implementation to match provider-NIT-4724#4586
mahdy-nasr wants to merge 2 commits intomasterfrom
implement-string-hashing-for-address-filtering

Conversation

@mahdy-nasr
Copy link
Copy Markdown
Contributor

As per linear ticket, this PR fixes the current hashing algorithm for address-filtering feature. It is matching with current provider has.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.33%. Comparing base (c4de738) to head (50a91e4).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4586      +/-   ##
==========================================
+ Coverage   34.22%   34.33%   +0.11%     
==========================================
  Files         498      498              
  Lines       59094    59085       -9     
==========================================
+ Hits        20223    20286      +63     
+ Misses      35293    35218      -75     
- Partials     3578     3581       +3     

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

❌ 14 Tests Failed:

Tests completed Failed Passed Skipped
4693 14 4679 0
View the top 3 failed tests by shortest run time
TestAliasingFlaky
Stack Traces | -0.000s run time
=== RUN   TestAliasingFlaky
=== PAUSE TestAliasingFlaky
=== CONT  TestAliasingFlaky
    common_test.go:777: BuildL1 deployConfig: DeployBold=true, DeployReferenceDAContracts=false
INFO [04-01|14:20:46.963] New local node record                    seq=1,775,053,246,963 id=4442c9bd8fe4c1a5                        ip=127.0.0.1 udp=0 tcp=0
INFO [04-01|14:20:46.963] Started P2P networking                   self=enode://a1fb2b0aad9c8912067302d52a98e2e5fe1c31b41068ce866b329b0a2d33364d1c2ce5b243f468ea8d6357eca8d7a22e0b07babf68bbf5ea34c7c96af66afd1e@127.0.0.1:0
INFO [04-01|14:20:46.963] Started log indexer
WARN [04-01|14:20:46.963] Getting file info                        dir= error="stat : no such file or directory"
TestPruningDBSizeReduction
Stack Traces | 0.000s run time
=== RUN   TestPruningDBSizeReduction
--- FAIL: TestPruningDBSizeReduction (0.00s)
TestBatchPosterL1SurplusMatchesBatchGasFlaky
Stack Traces | 0.530s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x207b1d2]

goroutine 76 [running]:
testing.tRunner.func1.2({0x37e0900, 0x61f39b0})
	/opt/hostedtoolcache/go/1.25.8/x64/src/testing/testing.go:1872 +0x237
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.25.8/x64/src/testing/testing.go:1875 +0x35b
panic({0x37e0900?, 0x61f39b0?})
	/opt/hostedtoolcache/go/1.25.8/x64/src/runtime/panic.go:783 +0x132
github.com/offchainlabs/nitro/arbnode.(*InboxTracker).GetBatchCount(0x17763900?)
	/home/runner/work/nitro/nitro/arbnode/inbox_tracker.go:210 +0x12
github.com/offchainlabs/nitro/arbnode.(*InboxTracker).FindInboxBatchContainingMessage(0x0, 0x7)
	/home/runner/work/nitro/nitro/arbnode/inbox_tracker.go:225 +0x2f
github.com/offchainlabs/nitro/system_tests.TestBatchPosterL1SurplusMatchesBatchGasFlaky(0xc00010b340)
	/home/runner/work/nitro/nitro/system_tests/batch_poster_test.go:839 +0x725
testing.tRunner(0xc00010b340, 0x41b2618)
	/opt/hostedtoolcache/go/1.25.8/x64/src/testing/testing.go:1934 +0xea
created by testing.(*T).Run in goroutine 1
	/opt/hostedtoolcache/go/1.25.8/x64/src/testing/testing.go:1997 +0x465

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

}

salt, err := hex.DecodeString(trimHexPrefix(payload.Salt))
salt, err := uuid.Parse(payload.Salt)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need to enforce that Salt is an uuid here?
Spec only says it is string.
This can break down the line, salt format can change to not use uuid, which is valid according to the spec, and we will break here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

there is no detailed actual spec. we have only code example of the hashing. But from the example and from speaking with them. the address is in form of '0x....' with 20bytes but used with delimiter in a string version. and Salt is UUID using with delimiter too in string version.

This implementation is better to catch any deviation and has strong validation that we get the data in right format. we part the 20byte addresses. we parse the 32Byte hashes, we parse the UUID and when do the hashing we use string::string format.

In future, the only change we spoke about that they will do is moving everything to binary bytes for hashing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Specification only says that salt is a string.
The fact that they are using a uuid, and providing the uuid in string format is irrelevant to nitro then.
The provider can decide to change how the salt is built on the fly, and we should be able to handle that gracefully if they provide the string representation.
Just use the string, no need to enforce parsing uuid for the salt here.
Parsing the uuid is not compliant with the spec, and make nitro more fragile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mahdy-nasr confirmed, with the salt provider, that despite the document that we have access not mentioning this, the salt will be a uuid.

@mahdy-nasr mahdy-nasr assigned diegoximenes and unassigned mahdy-nasr Apr 1, 2026
Copy link
Copy Markdown
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

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

Some nitpicks.

}

salt, err := hex.DecodeString(trimHexPrefix(payload.Salt))
salt, err := uuid.Parse(payload.Salt)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mahdy-nasr confirmed, with the salt provider, that despite the document that we have access not mentioning this, the salt will be a uuid.


// Store hashes to the hashstore so FilteringReady returns true
execNode.Sequencer.StoreFilterRulesForTest(t, []byte("test-salt"), nil, "test-digest")
salt, _ := uuid.Parse("3ccf0cbf-b23f-47ba-9c2f-4e7bd672b4c7")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, This is just a test, and I’m already providing a valid format, so this adds no value.

// After load, should have current time
before := time.Now()
store.Store([]byte("salt"), nil, "etag")
salt, _ := uuid.Parse("2cef04bf-b23f-47ba-9c2f-4e7bd652c1c6")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.


// Create test data
salt := []byte("test-salt")
salt, _ := uuid.Parse("2cef04bf-b23f-47ba-9c2f-4e7bd652c1c6")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.

store := NewHashStore(100)

salt1 := []byte("salt1")
salt1, _ := uuid.Parse("3ccf0cbf-b23f-47ba-9c2f-4e7bd672b4c7")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.


// Store second set with different salt (simulating hourly rotation)
salt2 := []byte("salt2")
salt2, _ := uuid.Parse("2cef04bf-b23f-47ba-9c2f-4e7bd652c1c6")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.

store := NewHashStore(100)

salt1 := []byte("test-salt")
salt1, _ := uuid.Parse("3ccf0cbf-b23f-47ba-9c2f-4e7bd672b4c7")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.


// prepare second set for swapping
salt2 := []byte("new-salt")
salt2, _ := uuid.Parse("2cef04bf-b23f-47ba-9c2f-4e7bd652c1c6")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.

}
if string(salt) != "test-salt" {
t.Errorf("expected salt 'test-salt', got '%s'", string(salt))
expectedSalt, _ := uuid.Parse("2cef04bf-b23f-47ba-9c2f-4e7bd652c1c6")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: do not ignore returned errors.

@mahdy-nasr
Copy link
Copy Markdown
Contributor Author

mahdy-nasr commented Apr 1, 2026

@diegoximenes
Instead of replying to all comments same message, Just decided to write here.
My response to returning error in the test:

This is just a test, and I’m already providing a valid hard-coded format, impossible to result in Error. so this adds no value. Add to this that tests will fail if they are not parsed.

@mahdy-nasr mahdy-nasr assigned diegoximenes and unassigned mahdy-nasr Apr 1, 2026
@diegoximenes
Copy link
Copy Markdown
Contributor

@diegoximenes Instead of replying to all comments same message, Just decided to write here. My response to returning error in the test:

This is just a test, and I’m already providing a valid hard-coded format, impossible to result in Error. so this adds no value. Add to this that tests will fail if they are not parsed.

It is about good practices instead of correctness.
Your code is correct, thats why I added the comments as nitpicks.
Ignoring returned errors in golang, even for tests, is considered a bad practice.
There are some linters for avoiding that, I even thought Nitro was already using it.
Example why is a bad practice:
Someone creates a test that uses a deterministic valid input to a function, and the error returned by this function is ignored.
Later, in another PR, someone updates the input, which will cause an error to be returned.
This can cause failures in the test down the line, in another part of the code, but it can be considerable easier to pinpoint the issue if the root cause error was handled in the first place.
I've faced issues like that before.
Adding error handling in those places is straightforward, you are already doing so in other tests, so no good reason to not follow best practices here 🙂.

@mahdy-nasr
Copy link
Copy Markdown
Contributor Author

mahdy-nasr commented Apr 1, 2026

@diegoximenes I agree with you totally in general. But for this case I am not convinced :
1- It is not a production code. Of course missing error handling on that is unacceptable.
2-It is not an ignored error that is error-able (it is hard coded value). Adding the handling like adding noise to the code.
3-This is very common in tests in our code. I just checked git grep -i "_ =" and found lots of samples and all of them has this hardcoded/determnistic input. and some time it is about what you are testing. I really see no reason to add the error handling here.

@mahdy-nasr mahdy-nasr removed their assignment Apr 1, 2026
@diegoximenes
Copy link
Copy Markdown
Contributor

@diegoximenes I agree with you totally in general. But for this case I am not convinced : 1- It is not a production code. Of course missing error handling on that is unacceptable. 2-It is not an ignored error that is error-able (it is hard coded value). Adding the handling like adding noise to the code. 3-This is very common in tests in our code. I just checked git grep -i "_ =" and found lots of samples and all of them has this hardcoded/determnistic input. and some time it is about what you are testing. I really see no reason to add the error handling here.

I understand your concern, but part of code review is helping each other build habits that pay off over time.
These small patterns compound, both in code quality and in how other contributors (and LLMs) model what "good" looks like in this codebase.
I really didn't expect this discussion over this minor issue going over for so long, but I will push back again.

  • The fact that something is common in the codebase doesn't make it good practice. New PRs are opportunities to raise the bar, to set the tone for new PRs from other developers and LLMs.
  • We should hedge against future test issues too, not only production issues. As an example, the suggested change can simplify debugging test errors, and even guaranteeing that test errors will be generated, if future PRs wrongly change hardcoded inputs. It is about setting the pattern of checking returned errors even for hardcoded inputs.
  • The suggested changes are simple, is about adding a require.NoError line per call site. If you inspect this PR you will check that this suggestion was already implemented by some test code that you are introducing.
  • As the reviewer I am not able to easily attest that some hardcoded values were properly set. As an example, TestHashStore_LoadedAt could be silently using an uuid.Nil from a parsing error. Again, this is not only specific for this PR, is about the pattern that this PR is setting for future changes.

@mahdy-nasr
Copy link
Copy Markdown
Contributor Author

mahdy-nasr commented Apr 2, 2026

I really didn't expect this discussion over this minor issue going over for so long

I agree.
I do not think this minor point is worth more back-and-forth. Best practices matter, but they are a means, not the goal.

TestHashStore_LoadedAt also does not support this point, since it is not testing salt correctness. Salt here is a dummy placeholder. If salt parsing were wrong, the other relevant tests would already fail.

I do not see value in continuing this discussion further. Lets focus on other more priority work now.

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.

3 participants