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

Return encoded extrinsics without padding #1505

Merged
merged 3 commits into from
Dec 4, 2023
Merged

Return encoded extrinsics without padding #1505

merged 3 commits into from
Dec 4, 2023

Conversation

Kailai-Wang
Copy link
Contributor

It should fix the ExtrinsicNotFound error during enclave registration.

With the padded version (post-padded with spaces 0x20) the extrinsic submission would succeed since the decoding goes through even with postpositioned (unused) bytes. However, the substrate-api-client wouldn't find the hash with the prolonged extrinsic that we pass in.

Related: scs/substrate-api-client#624

@clangenb clangenb added A0-core Affects a core part B1-releasenotes C3-medium 📣 Elevates a release containing this PR to "medium priority" E0-breaksnothing labels Nov 28, 2023
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Great improvement, I like it. I just have two questions.

skip_ra.into(),
)
};

ensure!(result == sgx_status_t::SGX_SUCCESS, Error::Sgx(result));
ensure!(retval == sgx_status_t::SGX_SUCCESS, Error::Sgx(retval));

Ok(unchecked_extrinsic)
Ok(Vec::from(&unchecked_extrinsic[..unchecked_extrinsic_size as usize]))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs a check that unchecked_extrinsic_size < unchecked_extrinsic.len() to prevent panics. This true for all the following usages too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is implicitly guaranteed by the ffi impl, isn't it

If it's out of index, it should have error'ed out within write_slice_and_whitespace_pad

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yes and no. If we have implemented everything correctly, yes, but the compiler can't make any checks across the ffi-boundaries. So I prefer being defensive here, as it just needs an error of some programmer in the future to introduce potential panics here.

Sorry, for being nitpicky here. 🙏

Copy link
Contributor

@clangenb clangenb Nov 30, 2023

Choose a reason for hiding this comment

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

Hmm, on the other hand the panic is on the untrusted side, so returning an error or panicking here, is essentially the same from the enclave's perspective.

hmm, still I would like to push the best practices as much as possible, so please fix it. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it is actually not the same, one case writes it in the, mut sgx_staus_t result and the other one returns the sgx error from the function. :)

core-primitives/utils/src/buffer.rs Show resolved Hide resolved
core-primitives/utils/src/buffer.rs Show resolved Hide resolved
@brenzi
Copy link
Collaborator

brenzi commented Dec 4, 2023

good spot @Kailai-Wang, thanks a lot for this contribution. the remaining CI error is most likely a credential access issue because your PR is from external.
I have good use for this fix right now, so I suggest to merge this and we'll take care of @clangenb's security checks separately right away

@clangenb
Copy link
Contributor

clangenb commented Dec 4, 2023

I agree, sorry for being picky!

@brenzi brenzi merged commit e40355f into integritee-network:master Dec 4, 2023
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-core Affects a core part B1-releasenotes C3-medium 📣 Elevates a release containing this PR to "medium priority" E0-breaksnothing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants