@@ -4,7 +4,7 @@ use anyhow::Result;
44use ceno_emul:: {
55 BN254_FP_WORDS , BN254_FP2_WORDS , BN254_POINT_WORDS , CENO_PLATFORM , EmuContext , InsnKind ,
66 Platform , Program , SECP256K1_ARG_WORDS , SECP256K1_COORDINATE_WORDS , SHA_EXTEND_WORDS ,
7- StepRecord , VMState , WORD_SIZE , Word , WordAddr , WriteOp ,
7+ StepRecord , UINT256_WORDS_FIELD_ELEMENT , VMState , WORD_SIZE , Word , WordAddr , WriteOp ,
88 host_utils:: { read_all_messages, read_all_messages_as_words} ,
99} ;
1010use ceno_host:: CenoStdin ;
@@ -623,6 +623,61 @@ fn test_bn254_precompile() -> Result<()> {
623623 let program_elf = ceno_examples:: bn254_precompile;
624624 let mut state = VMState :: new_from_elf ( unsafe_platform ( ) , program_elf) ?;
625625 let _ = run ( & mut state) ?;
626+ Ok ( ( ) )
627+ }
628+
629+ fn test_uint256_mul ( ) -> Result < ( ) > {
630+ let mut state = VMState :: new_from_elf ( unsafe_platform ( ) , program_elf) ?;
631+
632+ let steps = run ( & mut state) ?;
633+
634+ let syscalls = steps. iter ( ) . filter_map ( |step| step. syscall ( ) ) . collect_vec ( ) ;
635+ assert_eq ! ( syscalls. len( ) , 1 ) ;
636+
637+ let witness = syscalls[ 0 ] ;
638+ assert_eq ! ( witness. reg_ops. len( ) , 2 ) ;
639+ assert_eq ! ( witness. reg_ops[ 0 ] . register_index( ) , Platform :: reg_arg0( ) ) ;
640+ assert_eq ! ( witness. reg_ops[ 1 ] . register_index( ) , Platform :: reg_arg1( ) ) ;
641+
642+ let a_address = witness. reg_ops [ 0 ] . value . after ;
643+ assert_eq ! ( a_address, witness. reg_ops[ 0 ] . value. before) ;
644+ let a_address: WordAddr = a_address. into ( ) ;
645+
646+ let b_address = witness. reg_ops [ 1 ] . value . after ;
647+ assert_eq ! ( b_address, witness. reg_ops[ 1 ] . value. before) ;
648+ let b_address: WordAddr = b_address. into ( ) ;
649+
650+ const A_MUL_B : [ u8 ; 65 ] = [
651+ 4 , 188 , 11 , 115 , 232 , 35 , 63 , 79 , 186 , 163 , 11 , 207 , 165 , 64 , 247 , 109 , 81 , 125 , 56 , 83 ,
652+ 131 , 221 , 140 , 154 , 19 , 186 , 109 , 173 , 9 , 127 , 142 , 169 , 219 , 108 , 17 , 216 , 218 , 125 , 37 ,
653+ 30 , 87 , 86 , 194 , 151 , 20 , 122 , 64 , 118 , 123 , 210 , 29 , 60 , 209 , 138 , 131 , 11 , 247 , 157 , 212 ,
654+ 209 , 123 , 162 , 111 , 197 , 70 ,
655+ ] ;
656+ let expect = bytes_to_words ( A_MUL_B ) ;
657+
658+ assert_eq ! ( witness. mem_ops. len( ) , 3 * UINT256_WORDS_FIELD_ELEMENT ) ;
659+ // Expect first half to consist of read/writes on P
660+ for ( i, write_op) in witness
661+ . mem_ops
662+ . iter ( )
663+ . take ( UINT256_WORDS_FIELD_ELEMENT )
664+ . enumerate ( )
665+ {
666+ assert_eq ! ( write_op. addr, a_address + i) ;
667+ assert_eq ! ( write_op. value. after, expect[ i] ) ;
668+ }
669+
670+ // Expect second half to consist of reads on Q
671+ for ( i, write_op) in witness
672+ . mem_ops
673+ . iter ( )
674+ . skip ( UINT256_WORDS_FIELD_ELEMENT )
675+ . take ( UINT256_WORDS_FIELD_ELEMENT * UINT256_WORDS_FIELD_ELEMENT )
676+ . enumerate ( )
677+ {
678+ assert_eq ! ( write_op. addr, b_address + i) ;
679+ assert_eq ! ( write_op. value. after, write_op. value. before) ;
680+ }
626681
627682 Ok ( ( ) )
628683}
0 commit comments