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

Fault proving: Populate ContractsRawCode when processing Create Transaction in global merkle root crate #2652

Merged

Conversation

acerone85
Copy link
Contributor

Linked Issues/PRs

Closes #2587

Description

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this. Overall looks good but there are two tiny blockers I can see:

  1. A dangling todo that should reference an issue.
  2. An as conversion in production code.

If these are addressed I'd happily approve this PR.

@acerone85 acerone85 force-pushed the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch from 7f0ff15 to ebe1f20 Compare January 31, 2025 14:06
netrome
netrome previously approved these changes Jan 31, 2025
Comment on lines 158 to 164
let contract_id = tx
.metadata()
.as_ref()
.map(|metadata| metadata.body.contract_id)
.ok_or(anyhow::anyhow!(
"Create transaction does not have a contract ID in its metadata"
))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't rely on existence of the contract_id in metadata. I would suggest to use contract_id from ContractCreated output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0f91ceb, but I'm curious to know why the metadata is unreliable.

@netrome netrome force-pushed the 2582-fault_provingglobal_roots-initial-test-suite-for-storage-updates branch from 2457f06 to bbf6361 Compare January 31, 2025 20:51
Base automatically changed from 2582-fault_provingglobal_roots-initial-test-suite-for-storage-updates to master January 31, 2025 21:11
@netrome netrome dismissed their stale review January 31, 2025 21:11

The base branch was changed.

@acerone85 acerone85 force-pushed the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch from ebe1f20 to 4177a75 Compare February 3, 2025 11:25
netrome
netrome previously approved these changes Feb 3, 2025
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Just a nit :)

@acerone85 acerone85 force-pushed the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch from d103ddb to ee3edba Compare February 4, 2025 10:26
@rymnc rymnc requested review from xgreenx and netrome February 4, 2025 14:48
netrome
netrome previously approved these changes Feb 4, 2025
}

// TODO: https://github.com/FuelLabs/fuel-core/issues/2654
// This code is copied from the executor. We should refactor it to be shared.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe. It's not super obvious to me who should own this function. Maybe add it to where TransactionBuilder is maintained. Or add the functionality to the TransactionBuilder :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a separate PR (#2654) where I add it to fuel-core-types behind the test-helpers feature. Happy to discuss if this is the right place there.


// TODO: https://github.com/FuelLabs/fuel-core/issues/2654
// This code is copied from the executor. We should refactor it to be shared.
fn create_contract(bytecode: &[u8], rng: &mut impl rand::RngCore) -> Create {
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename this create_contract_tx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: e6aadd5

Comment on lines 152 to 153
// CreateBody is not publicly exported, so we need to use a generic type
// and ensure that all trait bounds are satisfied
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, removed in be996d8

@acerone85 acerone85 force-pushed the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch from d0572ee to e6aadd5 Compare February 5, 2025 09:41
@acerone85 acerone85 force-pushed the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch from e6aadd5 to 6bc31c6 Compare February 5, 2025 12:47
@netrome netrome merged commit 05538a5 into master Feb 5, 2025
33 checks passed
@netrome netrome deleted the 2587-fault_provingglobal_roots-populate-contractsrawcode-table branch February 5, 2025 13:16
@AurelienFT AurelienFT mentioned this pull request Feb 5, 2025
AurelienFT added a commit that referenced this pull request Feb 5, 2025
## Version 0.41.6

### Added
- [2668](#2668): Expose gas
price service test helpers
- [2621](#2598): Global merkle
root storage updates process upgrade transactions.
- [2650](#2650): Populate
`ProcessedTransactions` table in global merkle root storage.
- [2667](#2667): Populate
`Blobs` table in global merkle root storage.
- [2652](#2652): Global Merkle
Root storage crate: Add Raw contract bytecode to global merkle root
storage when processing Create transactions.

### Fixed
- [2673](#2673): Change read
behavior on the InMemoryTransaction to use offset and allow not equal
buf size (fix CCP and LDC broken from
FuelLabs/fuel-vm#847)
fn process_create_transaction(&mut self, tx: &Create) -> anyhow::Result<()> {
let bytecode_witness_index = tx.bytecode_witness_index();
let witnesses = tx.witnesses();
let bytecode = witnesses[usize::from(*bytecode_witness_index)].as_vec();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If bytecode_witness_index is malicious, it will panic

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that clippy missed this 🤔 thanks for spotting!

Copy link
Contributor

Choose a reason for hiding this comment

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

Created hotfix PR #2677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fault_proving(global_roots): Populate ContractsRawCode table
5 participants