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

1 - reading/writing more than 32 bytes into the TendConfig.extraData field #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcclurejt
Copy link
Contributor

@mcclurejt mcclurejt commented Dec 19, 2024

Only the first 32 bytes of extraData are read/written from TendConfig.

This PR adds logic to handle more than 32 bytes for TendConfig.extraData.

issue

@mcclurejt mcclurejt marked this pull request as ready for review December 19, 2024 12:28
@mcclurejt mcclurejt changed the title add logic for reading/writing more than 32 bytes into the TendConfig.extraData field reading/writing more than 32 bytes into the TendConfig.extraData field Dec 19, 2024

/// @dev Tests that `TendConfig.extraData` is fully loaded even when the
/// content is greater than a single storage slot.
function test_extraData_large() external {
Copy link

@brianmcmichael brianmcmichael Dec 19, 2024

Choose a reason for hiding this comment

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

You'll probably want to add tests for cases that assert when extraData is "", < bytes32 bytes, and > bytes32 bytes.

I re-ran the original test with a single char bytes input and the output wasn't matching the input.

Ensure you include assertions on minOutput, minVaultSharePrice, and positionClosureLimit when populated with non-zero values as well.

Copy link

Choose a reason for hiding this comment

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

I re-ran the original test with a single char bytes input and the output wasn't matching the input.

I couldn't reproduce this, can you show the example. (but agree with adding different test cases for different extreme cases of slots occupied.)

@mcclurejt mcclurejt changed the title reading/writing more than 32 bytes into the TendConfig.extraData field 1 - reading/writing more than 32 bytes into the TendConfig.extraData field Dec 19, 2024
Comment on lines +382 to +398
// Pointer to the actual data.
let extraDataData := add(extraData, 0x20)

// Store the length in the `extraDataSlot`.
tstore(extraDataSlot, extraDataLength)

// Store the data in subsequent slots.
for {
let i := 0
} lt(i, extraDataLength) {
i := add(i, 32)
} {
tstore(
add(extraDataSlot, add(div(i, 32), 1)),
mload(add(extraDataData, i))
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We're mixing and matching hex and decimals here. It's up to you whether or not you want to fix this, but I generally prefer all hex in inline assembly.

Copy link

@Sean329 Sean329 Jan 9, 2025

Choose a reason for hiding this comment

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

I got a concern here which involves some low level memory layout that I'm very certain about the details: does the compiler ensure that the extraDataData always gets padded into 32 bytes for the last few remaining words if it's short of 32?
Here the mload is always loading 32 in each iteration, I'm thinking if it has risks of reading unwanted data for the last piece if the memory layout didn't get padded to a full 32? Maybe some quick tests of extraDataLength not being exactly multiples of 32 can help answering it.

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.

5 participants