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

Migrate slots to U256 #328

Merged
merged 13 commits into from
Jun 10, 2024
Merged

Migrate slots to U256 #328

merged 13 commits into from
Jun 10, 2024

Conversation

aajj999
Copy link
Contributor

@aajj999 aajj999 commented Jun 6, 2024

  • Migrate slot library to U256
  • Use 256 in ERC721Token & ERC20Token
  • Implement From and Into for U256 type (Bytes32)
  • Add from_field function for U256

}

bytes
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not inline?

let low = U128::from_le_bytes(low_bytes);

U256::new(high, low)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not inline?


fn from_field(field: Field) -> Self {
U256::from_bytes32(field_to_bytes32(field))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As From trait?

Copy link
Contributor

Choose a reason for hiding this comment

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

#nextPR

let mut bytes = [0x00; 32];
bytes[31] = 0x10;
assert_eq(U256::into(big_number), bytes);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Some more tests pls :)


#[test]
fn from_bytes32_zero() {
let mut bytes = [0x00; 32];
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary mut

global limit_u256 = U256 {high: limit, low:limit};

#[test]
fn from_bytes32_zero() {
Copy link
Contributor

@marekkirejczyk marekkirejczyk Jun 7, 2024

Choose a reason for hiding this comment

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

  mod from_bytes32 {

  }
  mod into_bytes32 {

  }


#[test]
fn from_bytes32_limit() {
let mut bytes = [0xff; 32];
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary mut

Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary import bytes32::field_to_bytes32 can be removed


global TOKEN_BALANCE_INDEX = 0;

struct ERC20Token {
address: Address,
balances_slot: Bytes32,
allowances_slot: Bytes32,
balances_slot: U256,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bytes32 import can be removed

@aajj999 aajj999 added this pull request to the merge queue Jun 10, 2024
Merged via the queue into main with commit a84b535 Jun 10, 2024
6 checks passed
@aajj999 aajj999 deleted the ania/migrate_slots branch June 10, 2024 09:55
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