@@ -61,10 +61,34 @@ struct KeccakSpecial5AbiDescription {
6161
6262template <typename DESCRIPTION> struct DelegationWitness {
6363 const TimestampScalar write_timestamp;
64- const RegisterOrIndirectReadWriteData reg_accesses[DESCRIPTION::REG_ACCESSES];
65- const RegisterOrIndirectReadData indirect_reads[DESCRIPTION::INDIRECT_READS];
66- const RegisterOrIndirectReadWriteData indirect_writes[DESCRIPTION::INDIRECT_WRITES];
67- const u16 variables_offsets[DESCRIPTION::VARIABLE_OFFSETS];
64+ // instead of
65+ // const RegisterOrIndirectReadWriteData reg_accesses[DESCRIPTION::REG_ACCESSES];
66+ // const RegisterOrIndirectReadData indirect_reads[DESCRIPTION::INDIRECT_READS];
67+ // const RegisterOrIndirectReadWriteData indirect_writes[DESCRIPTION::INDIRECT_WRITES];
68+ // const u16 variables_offsets[DESCRIPTION::VARIABLE_OFFSETS];
69+ // we implement this as a single byte array to avoid compilation errors when some of the arrays would be zero-size
70+ const u8 contents[DESCRIPTION::REG_ACCESSES * sizeof (RegisterOrIndirectReadWriteData) + DESCRIPTION::INDIRECT_READS * sizeof (RegisterOrIndirectReadData) +
71+ DESCRIPTION::INDIRECT_WRITES * sizeof (RegisterOrIndirectReadWriteData) + DESCRIPTION::VARIABLE_OFFSETS * sizeof (u16 )];
72+
73+ DEVICE_FORCEINLINE const RegisterOrIndirectReadWriteData *reg_accesses () const { return reinterpret_cast <const RegisterOrIndirectReadWriteData *>(contents); }
74+
75+ DEVICE_FORCEINLINE const RegisterOrIndirectReadData *indirect_reads () const {
76+ constexpr size_t offset = DESCRIPTION::REG_ACCESSES * sizeof (RegisterOrIndirectReadWriteData);
77+ return reinterpret_cast <const RegisterOrIndirectReadData *>(contents + offset);
78+ }
79+
80+ DEVICE_FORCEINLINE const RegisterOrIndirectReadWriteData *indirect_writes () const {
81+ constexpr size_t offset =
82+ DESCRIPTION::REG_ACCESSES * sizeof (RegisterOrIndirectReadWriteData) + DESCRIPTION::INDIRECT_READS * sizeof (RegisterOrIndirectReadData);
83+ return reinterpret_cast <const RegisterOrIndirectReadWriteData *>(contents + offset);
84+ }
85+
86+ DEVICE_FORCEINLINE const u16 *variables_offsets () const {
87+ constexpr size_t offset = DESCRIPTION::REG_ACCESSES * sizeof (RegisterOrIndirectReadWriteData) +
88+ DESCRIPTION::INDIRECT_READS * sizeof (RegisterOrIndirectReadData) +
89+ DESCRIPTION::INDIRECT_WRITES * sizeof (RegisterOrIndirectReadWriteData);
90+ return reinterpret_cast <const u16 *>(contents + offset);
91+ }
6892};
6993
7094template <typename DESCRIPTION> struct DelegationTrace {
@@ -79,20 +103,20 @@ template <typename DESCRIPTION> struct DelegationTrace {
79103 const auto cycle_data = tracing_data + trace_row;
80104 switch (placeholder.tag ) {
81105 case DelegationRegisterReadValue: {
82- return cycle_data->reg_accesses [reg_offset].read_value ;
106+ return cycle_data->reg_accesses () [reg_offset].read_value ;
83107 }
84108 case DelegationRegisterWriteValue: {
85- return cycle_data->reg_accesses [reg_offset].write_value ;
109+ return cycle_data->reg_accesses () [reg_offset].write_value ;
86110 }
87111 case DelegationIndirectReadValue: {
88- return DESCRIPTION::use_read_indirects (register_index) ? cycle_data->indirect_reads [word_index].read_value
89- : cycle_data->indirect_writes [word_index].read_value ;
112+ return DESCRIPTION::use_read_indirects (register_index) ? cycle_data->indirect_reads () [word_index].read_value
113+ : cycle_data->indirect_writes () [word_index].read_value ;
90114 }
91115 case DelegationIndirectWriteValue: {
92116 if (DESCRIPTION::use_read_indirects (register_index)) {
93117 __trap ();
94118 }
95- return cycle_data->indirect_writes [word_index].write_value ;
119+ return cycle_data->indirect_writes () [word_index].write_value ;
96120 }
97121 default :
98122 __trap ();
@@ -110,7 +134,7 @@ template <typename DESCRIPTION> struct DelegationTrace {
110134 case DelegationIndirectAccessVariableOffset: {
111135 const u32 variable_index = placeholder.payload [0 ];
112136 const auto cycle_data = tracing_data + trace_row;
113- return cycle_data->variables_offsets [variable_index];
137+ return cycle_data->variables_offsets () [variable_index];
114138 }
115139 default :
116140 __trap ();
@@ -138,11 +162,11 @@ template <typename DESCRIPTION> struct DelegationTrace {
138162 case DelegationWriteTimestamp:
139163 return TimestampData::from_scalar (cycle_data->write_timestamp );
140164 case DelegationRegisterReadTimestamp: {
141- return cycle_data->reg_accesses [reg_offset].timestamp ;
165+ return cycle_data->reg_accesses () [reg_offset].timestamp ;
142166 }
143167 case DelegationIndirectReadTimestamp: {
144- return DESCRIPTION::use_read_indirects (register_index) ? cycle_data->indirect_reads [word_index].timestamp
145- : cycle_data->indirect_writes [word_index].timestamp ;
168+ return DESCRIPTION::use_read_indirects (register_index) ? cycle_data->indirect_reads () [word_index].timestamp
169+ : cycle_data->indirect_writes () [word_index].timestamp ;
146170 }
147171 default :
148172 __trap ();
0 commit comments