@@ -34,7 +34,6 @@ use eth_types::{
34
34
use ethers_core:: utils:: keccak256;
35
35
use gadgets:: util:: { and, expr_from_bytes} ;
36
36
use halo2_proofs:: { circuit:: Value , plonk:: Error } ;
37
-
38
37
use log:: trace;
39
38
use std:: iter:: once;
40
39
@@ -68,6 +67,8 @@ pub(crate) struct CreateGadget<F, const IS_CREATE2: bool, const S: ExecutionStat
68
67
keccak_output : Word < F > ,
69
68
// prevous code hash befor creating
70
69
code_hash_previous : Cell < F > ,
70
+ #[ cfg( feature = "scroll" ) ]
71
+ keccak_code_hash_previous : Cell < F > ,
71
72
code_hash_is_empty : IsEqualGadget < F > ,
72
73
code_hash_is_zero : IsZeroGadget < F > ,
73
74
copy_rwc_inc : Cell < F > ,
@@ -84,6 +85,8 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
84
85
// Use rw_counter of the step which triggers next call as its call_id.
85
86
let callee_call_id = cb. curr . state . rw_counter . clone ( ) ;
86
87
let code_hash_previous = cb. query_cell ( ) ;
88
+ #[ cfg( feature = "scroll" ) ]
89
+ let keccak_code_hash_previous = cb. query_cell_phase2 ( ) ;
87
90
let opcode = cb. query_cell ( ) ;
88
91
let copy_rwc_inc = cb. query_cell ( ) ;
89
92
@@ -312,6 +315,9 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
312
315
new_address. clone ( ) ,
313
316
0 . expr ( ) ,
314
317
1 . expr ( ) ,
318
+ code_hash_previous. expr ( ) ,
319
+ #[ cfg( feature = "scroll" ) ]
320
+ keccak_code_hash_previous. expr ( ) ,
315
321
value. clone ( ) ,
316
322
& mut callee_reversion_info,
317
323
) ;
@@ -509,6 +515,8 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
509
515
keccak_code_hash,
510
516
keccak_output,
511
517
code_hash_previous,
518
+ #[ cfg( feature = "scroll" ) ]
519
+ keccak_code_hash_previous,
512
520
code_hash_is_empty,
513
521
code_hash_is_zero,
514
522
copy_rwc_inc,
@@ -669,6 +677,14 @@ impl<F: Field, const IS_CREATE2: bool, const S: ExecutionState> ExecutionGadget<
669
677
rw_offset += 2 ;
670
678
#[ cfg( feature = "scroll" ) ]
671
679
{
680
+ let keccak_code_hash_previous = block. rws [ step. rw_indices [ 16 + rw_offset] ]
681
+ . account_keccak_codehash_pair ( )
682
+ . 1 ;
683
+ self . keccak_code_hash_previous . assign (
684
+ region,
685
+ offset,
686
+ region. word_rlc ( keccak_code_hash_previous) ,
687
+ ) ?;
672
688
rw_offset += 2 ; // Read Write empty Keccak code hash.
673
689
}
674
690
let [ caller_balance_pair, callee_balance_pair] = if !value. is_zero ( ) {
@@ -800,7 +816,7 @@ mod test {
800
816
static ref CALLER_ADDRESS : Address = address!( "0x00bbccddee000000000000000000000000002400" ) ;
801
817
}
802
818
803
- fn run_test_circuits ( ctx : TestContext < 2 , 1 > ) {
819
+ fn run_test_circuits < const NACC : usize , const NTX : usize > ( ctx : TestContext < NACC , NTX > ) {
804
820
CircuitTestBuilder :: new_from_test_ctx ( ctx)
805
821
. params ( CircuitsParams {
806
822
max_rws : 70_000 ,
@@ -1092,4 +1108,44 @@ mod test {
1092
1108
run_test_circuits ( test_context ( caller) ) ;
1093
1109
} ) ;
1094
1110
}
1111
+
1112
+ #[ test]
1113
+ fn test_create2_deploy_to_non_zero_balance_address ( ) {
1114
+ let initialization_code = initialization_bytecode ( true ) ;
1115
+ let root_code = creater_bytecode ( initialization_code, 0 . into ( ) , true , true ) ;
1116
+ let caller = Account {
1117
+ address : * CALLER_ADDRESS ,
1118
+ code : root_code. into ( ) ,
1119
+ nonce : Word :: one ( ) ,
1120
+ balance : eth ( 10 ) ,
1121
+ ..Default :: default ( )
1122
+ } ;
1123
+ let ctx = TestContext :: < 3 , 1 > :: new (
1124
+ None ,
1125
+ |accs| {
1126
+ accs[ 0 ]
1127
+ . address ( address ! ( "0x000000000000000000000000000000000000cafe" ) )
1128
+ . balance ( eth ( 10 ) ) ;
1129
+ accs[ 1 ] . account ( & caller) ;
1130
+ accs[ 2 ]
1131
+ . address ( address ! ( "0x4e74035cefd0998ea16ab5145f7713620a9eb0c5" ) )
1132
+ . balance ( eth ( 10 ) ) ;
1133
+ } ,
1134
+ |mut txs, accs| {
1135
+ txs[ 0 ]
1136
+ . from ( accs[ 0 ] . address )
1137
+ . to ( accs[ 1 ] . address )
1138
+ . gas ( word ! ( "0x2386F26FC10000" ) ) ;
1139
+ } ,
1140
+ |block, _| block,
1141
+ )
1142
+ . unwrap ( ) ;
1143
+ CircuitTestBuilder :: new_from_test_ctx ( ctx)
1144
+ . params ( CircuitsParams {
1145
+ max_rws : 200 ,
1146
+ max_copy_rows : 200 ,
1147
+ ..Default :: default ( )
1148
+ } )
1149
+ . run ( ) ;
1150
+ }
1095
1151
}
0 commit comments