Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 1d1066d

Browse files
authored
fix: get_create_init_code can be wrong (privacy-scaling-explorations#1671)
### Description [_PR description_] ### Issue Link fix privacy-scaling-explorations#1670 ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Contents - [_item_] ### Rationale [_design decisions and extended information_] ### How Has This Been Tested? [_explanation_] <hr> ## How to fill a PR description Please give a concise description of your PR. The target readers could be future developers, reviewers, and auditors. By reading your description, they should easily understand the changes proposed in this pull request. MUST: Reference the issue to resolve ### Single responsability Is RECOMMENDED to create single responsibility commits, but not mandatory. Anyway, you MUST enumerate the changes in a unitary way, e.g. ``` This PR contains: - Cleanup of xxxx, yyyy - Changed xxxx to yyyy in order to bla bla - Added xxxx function to ... - Refactored .... ``` ### Design choices RECOMMENDED to: - What types of design choices did you face? - What decisions you have made? - Any valuable information that could help reviewers to think critically
1 parent c1ec848 commit 1d1066d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

bus-mapping/src/circuit_input_builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,21 +501,21 @@ pub fn keccak_inputs_tx_circuit(
501501
}
502502

503503
/// Retrieve the init_code from memory for {CREATE, CREATE2}
504-
pub fn get_create_init_code<'a>(
505-
call_ctx: &'a CallContext,
506-
step: &GethExecStep,
507-
) -> Result<&'a [u8], Error> {
504+
pub fn get_create_init_code(call_ctx: &CallContext, step: &GethExecStep) -> Result<Vec<u8>, Error> {
508505
let offset = step.stack.nth_last(1)?.low_u64() as usize;
509506
let length = step.stack.nth_last(2)?.as_usize();
510507

511508
let mem_len = call_ctx.memory.0.len();
512-
if offset >= mem_len {
513-
return Ok(&[]);
509+
let mut result = vec![0u8; length];
510+
if length > 0 && offset < mem_len {
511+
let offset_end = offset
512+
.checked_add(length)
513+
.expect("overflow should be handled using OOG error")
514+
.min(mem_len);
515+
let copy_len = offset_end - offset;
516+
result[..copy_len].copy_from_slice(&call_ctx.memory.0[offset..offset_end]);
514517
}
515-
516-
let offset_end = offset.checked_add(length).unwrap_or(mem_len);
517-
518-
Ok(&call_ctx.memory.0[offset..offset_end])
518+
Ok(result)
519519
}
520520

521521
/// Retrieve the memory offset and length of call.

0 commit comments

Comments
 (0)