-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
crypto: use address32 flag #8542
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
Flagging this as one other spot that will need to change: https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/sources/address.move#L11 |
f7ee3c5
to
66dddea
Compare
1456a8d
to
c7a9a86
Compare
70e6992
to
9f82b72
Compare
@@ -8,17 +8,14 @@ module sui::address { | |||
use std::string; | |||
|
|||
/// The length of an address, in bytes | |||
const LENGTH: u64 = 20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @sblackshear to review address.move and address_test.move
9f82b72
to
abd204e
Compare
@@ -76,7 +76,7 @@ export function isValidTransactionDigest( | |||
// which uses the Move account address length | |||
// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 . | |||
|
|||
export const SUI_ADDRESS_LENGTH = 20; | |||
export const SUI_ADDRESS_LENGTH = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @Jordan-Mysten i tried to make all the typescript changes too (at least all unit tests are passing, but not any e2e), feel free to push any more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can follow-up with this at a later point, but would probably be ideal for BCS + SDK to use the same constant so this can easily be configured in a single place.
crates/sui-adapter-transactional-tests/tests/size_limits/move_object_size_limit.move
Show resolved
Hide resolved
@@ -70,6 +71,6 @@ export class Secp256k1PublicKey implements PublicKey { | |||
let tmp = new Uint8Array(SECP256K1_PUBLIC_KEY_SIZE + 1); | |||
tmp.set([SIGNATURE_SCHEME_TO_FLAG['Secp256k1']]); | |||
tmp.set(this.toBytes(), 1); | |||
return sha3.sha3_256(tmp).slice(0, 40); | |||
return sha3.sha3_256(tmp).slice(0, SUI_ADDRESS_LENGTH * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd a comment here that this double size is because of hex being 100% longer (each hex char represents half a byte of information)
@@ -353,12 +362,16 @@ fn test_move_package_size_for_gas_metering() { | |||
let serialized = bcs::to_bytes(&package).unwrap(); | |||
// If the following assertion breaks, it's likely you have changed MovePackage's fields. | |||
// Make sure to adjust `object_size_for_gas_metering()` to include those changes. | |||
assert_eq!(size + 2, serialized.len()); | |||
assert_eq!(size - 2, serialized.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the correct thing to do to change the test? from what i see, the object_size_for_gas_metering seems to be an approx to begin with, and no need to tweak there.
let meta_data_size = size_of::<Owner>() + size_of::<TransactionDigest>() + size_of::<u64>();
this should take into account the size of owner aka the increased address size
7be39ba
to
d658bd9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS Changes LGTM
@@ -76,7 +76,7 @@ export function isValidTransactionDigest( | |||
// which uses the Move account address length | |||
// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 . | |||
|
|||
export const SUI_ADDRESS_LENGTH = 20; | |||
export const SUI_ADDRESS_LENGTH = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can follow-up with this at a later point, but would probably be ideal for BCS + SDK to use the same constant so this can easily be configured in a single place.
d658bd9
to
6f6f6f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent job, thanks both to @joyqvq and all reviewers.
assert_eq!(effects.events.len(), 6); | ||
assert_eq!(effects.events.len(), 7); | ||
// TODO: figure out why an extra event is emitted. | ||
// assert_eq!(effects.events.len(), 6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will create an issue to track the effects issues, i guess @patrickkuo's work might be relevant
6f6f6f3
to
abf8cc5
Compare
abf8cc5
to
5d3f521
Compare
EDIT: as per #9262 the hash function is changed from SHA3-256 to BLAKE2b!
Description
Specifics:
How to retrieve new address
We cannot derive 32-byte address from the legacy 20-byte address. Instead, you can derive directly from the flag and the private key using the following command. Alternatively, you can construct from the flag and public key (address = last 32 bytes of sha3_256(flag || pubkey)).
0. Build/download latest sui (0.28.0 or newer)
flag || privkey
base64 stringIn Typescript, use latest
toSuiAddress()
In Rust, use latest pk.into()
Test vectors
We provide three test cases for each signature scheme in three arrays. In each array, the first element is the mnemonics, the second element is a base64 encoded
flag || privkey
(same as what you see in sui.keystore), the third element is the derived 32-bytes address in hex.For Ed25519:
sui/sdk/typescript/test/unit/cryptography/ed25519-keypair.test.ts
Line 12 in 4adfbff
For Secp256k1
sui/sdk/typescript/test/unit/cryptography/secp256k1-keypair.test.ts
Line 37 in 4adfbff
Test Plan
See all unit tests. e2e tests see:
If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.
Type of Change (Check all that apply)
Any 20 byte old address is invalidated.
When 0.29.0 is released for sui, the user MUST upgrade the sui wallet and SDK to the latest version to interact with the network. This change is backward incompatible. User needs to reimport their mnemonics or private key to see an valid 32-byte address.
All move packages and FN can only understand a 32-byte address and fail all 20-byte addresses.
All system objects and IDs are using the new 32-byte representation.
All old object IDs and Sui Addresses are invalidated.