Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preview net ID #5396

Merged
merged 11 commits into from
Feb 20, 2024
Merged

Add preview net ID #5396

merged 11 commits into from
Feb 20, 2024

Conversation

Kay-Zee
Copy link
Member

@Kay-Zee Kay-Zee commented Feb 14, 2024

Still need invalidCodePreviewNetwork if we actually do need a brand new chain ID. Typically, this is something i'd get @tarakby's help with.

Otherwise, this is more or a less looking off of this PR: https://github.com/onflow/flow-go/pull/3433/files

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (bdcaccf) 56.33% compared to head (c9d89c3) 56.31%.

Files Patch % Lines
cmd/bootstrap/cmd/machine_account.go 0.00% 4 Missing and 1 partial ⚠️
cmd/scaffold.go 0.00% 4 Missing ⚠️
cmd/bootstrap/cmd/block.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           feature/stable-cadence    #5396      +/-   ##
==========================================================
- Coverage                   56.33%   56.31%   -0.02%     
==========================================================
  Files                        1023     1023              
  Lines                       99105    99116      +11     
==========================================================
- Hits                        55827    55819       -8     
- Misses                      39059    39073      +14     
- Partials                     4219     4224       +5     
Flag Coverage Δ
unittests 56.31% <38.88%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

} else {
sameChainCheck := chain.IsValid(address)
require.True(t, sameChainCheck)
}
}
}

// sanity check: mainnet addresses must fail the test check
r = uint64(rand.Intn(maxIndex - loop))
for k := 0; k < loop; k++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

removed as this is covered by the test section just above

@janezpodhostnik
Copy link
Contributor

I checked that the systemcontracts are properly set up for this, and they are.

@Kay-Zee Kay-Zee marked this pull request as ready for review February 15, 2024 17:39
@@ -273,6 +273,9 @@ const invalidCodeTransientNetwork = uint64(0x1cb159857af02018)
// invalidCodeSandboxNetwork is the invalid codeword used for Sandbox network.
const invalidCodeSandboxNetwork = uint64(0x1035ce4eff92ae01)

// invalidCodePreviewNetwork is the invalid codeword used for Preview networks.
Copy link
Member

Choose a reason for hiding this comment

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

Still need invalidCodePreviewNetwork if we actually do need a brand new chain ID. Typically, this is something i'd get @tarakby's help with.

Can we add comment how this codeword is produced? or is there a test function to produce or validate this value?

Copy link
Contributor

Choose a reason for hiding this comment

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

a brief explanation for all the invalid code words is given here. All the invalid code words are validated by this test : all address spaces created are disjoint (each two don't intersect)

Copy link
Contributor

Choose a reason for hiding this comment

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

added more comments here: f627367.
Understanding all the details require going through the other comments in the implementation, and reading the basics about Hamming codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

From my layman understanding, I think for generation it is something like this:

while
    r = rand_uint64() 
    if r != 0 and not isValidCodeWord(r):
      break

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, though isValidCodeWord(r) should be applied to all existing networks (Mainnet and all others). I also choose r with a hamming weight close to 32 so that we distance the test space from the Mainnet space

Copy link
Contributor

Choose a reason for hiding this comment

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

@tarakby off topic but I was wondering that recently, is it possible to write a function that suggests closest address ( when user writes the address wrong ) something like did you mean xxxxxx ?

Copy link
Member

Choose a reason for hiding this comment

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

@tarakby Could you maybe add this "layman understanding" to the comment? It helped me understand what is happening there :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

@bluesign

is it possible to write a function that suggests closest address ( when user writes the address wrong )

Good question! the scheme was designed only for error detection (up to 6 bits) and not error correction. However I speculate the scheme can also provide up to 3 bits of error correction (no proof, only gut feeling), which means we can guess the original address correctly if we believe up to 3 bits only got flipped.
If more bits were flipped, we can still make a guess, but the guess will be wrong (different than the original address), which is dangerous from a blockchain user perspective (imagine sending tokens to the wrong address because it was suggested by an interface). I think it's safer to only check the address and reject any invalid address, to force the user to double check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you maybe add this "layman understanding" to the comment? It helped me understand what is happening there

makes sense, and it's useful for future extensions of the code. I'll add it in another PR

cmd/scaffold.go Outdated Show resolved Hide resolved
cmd/scaffold.go Outdated Show resolved Hide resolved
@j1010001 j1010001 merged commit 6b0ce48 into feature/stable-cadence Feb 20, 2024
50 of 51 checks passed
@j1010001 j1010001 deleted the kan/preview-net-chain-id branch February 20, 2024 18:27
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.

9 participants