ZeroDivisionError: float division by zero

Hi,
I am using the ChipWhisperer-Lite and the CW305 target board for my experiment and I installed ChipWhisperer 5.5 directly (no VM). The setup of AES on the CW305 with ChipWhisperer-Lite is working fine for me. However, using the same scope settings, I got the ZeroDivisionError If I am running the following script for my own crypto algorithm: SHAKE. How to capture the power traces without this error?
j = 0
while j < (N_traces):

            # Generate 256-bit random number
            if i == 0 or i == 1:
                    random(0)
            else: 
                    random(12)

            scope.arm()
                            
            # SHA3-256 using Random_seed
            SHAKE(32, 896, 0)
            # Call SHAKE to write 3744 bytes
            SHAKE(3744, 100, 896)
            # Matrix A generated
            vecmult(100, 100, 900)  

            # Trigger 
            target.fpga_write(target.REG_USER_LED, [0x01]) 
         
            vecmult(164, 256, 900)                
            vecmult(228, 412, 900)
                            
            ret = scope.capture()
            if ret:
                print("Capure timeout")
                continue
            wave = scope.get_last_trace()               
            traces.append(wave)    
            print("Trace %d" % j)
            j += 1  

Error message:
---- Collecting Power Traces for Set 0 ----
Traceback (most recent call last):
File “D:\NIST_PQC_Project\PQC_ChipWhispererBoard\Park_SABER\Python_Saber\Test2.py”, line 274, in
ret = scope.capture()
File “d:\chipwhisperer5_64\git\home\portable\chipwhisperer\software\chipwhisperer\capture\scopes\OpenADC.py”, line 346, in capture
return self.qtadc.capture(self.adc.offset, self.clock.adc_freq, self.adc.samples)
File “d:\chipwhisperer5_64\git\home\portable\chipwhisperer\software\chipwhisperer\capture\scopes_qt.py”, line 110, in capture
timeout = self.sc.capture(offset, adc_freq, samples)
File “d:\chipwhisperer5_64\git\home\portable\chipwhisperer\software\chipwhisperer\capture\scopes_OpenADCInterface.py”, line 2024, in capture
cap_delay = (7.37E6 * 4 * samples) / (adc_freq * 24400)
ZeroDivisionError: float division by zero


def SHAKE(num_bytes, OP2, OP1):
“”"
num_bytes: Number of bytes
OP2: Address of Destination
OP1: Address of Random seed

    """

I’m pretty sure this is a bug that was fixed in subsequent releases; can you see if
upgrading to 5.5.2 fixes the issue?

Jean-Pierre

Thanks, Jean. the problem is resolved.

How to save the power traces as a .csv file?
ret = scope.capture()
if ret:
print(“Capure timeout”)
continue
wave = scope.get_last_trace()
traces.append(wave)
num_points = len(wave)
newarr = wave.reshape(wave, num_points)
np.savetxt(’./Power_Traces_TVLA/set0.csv’, newarr, delimiter = ‘,’)

I got the following error when I am running the above commands:

newarr = wave.reshape(wave, num_points)
TypeError: only integer scalar arrays can be converted to a scalar index

I’m not sure what you’re trying to do here? The problem is with your Python syntax on wave.reshape(wave...).

Maybe what you want is this?

newarr = wave.reshape((num_points, 1))

No.
I need to store 1000 captured tarces on the .csv format for my analysis. I got the error when I am running the following script. Can you check the script is correct or not?

Num_traces = 1000
j = 0
    while j < (Num_traces):   
            scope.arm()       
            SHAKE(3744, 100, 896)  
            ret = scope.capture()
            wave = scope.get_last_trace()               
            traces.append(wave)    
            j += 1
    num_points = len(wave)
    newarr = wave.reshape(Num_traces, num_points)
    np.savetxt('./Power_Traces_TVLA/set0.csv', newarr, delimiter = ',')

Error
newarr = wave.reshape(Num_traces, num_points)
ValueError: cannot reshape array of size 20000 into shape (1000,20000)

Hi,

It looks like you’re trying to reshape a single trace of length 20k into 1000 traces of length 20k, which is why you’re getting that error. I’d suspect you’ll want to make traces a numpy array with dimensions 1000x20k.

Alex

This error message suggests that a function or operation is expecting an integer scalar index (single integer) as an index, but is instead receiving an array or a non-integer value. This can occur when attempting to index or slice an array with a non-integer or non-scalar value. To resolve this error, ensure that the index being used is a single integer and not an array or non-integer value. If working with arrays, consider using integer indexing or slicing methods to access specific elements or subsets of the array.