ethereum / ethereumj

DEPRECATED! Java implementation of the Ethereum yellowpaper. For JSON-RPC and other client features check Ethereum Harmony
GNU Lesser General Public License v3.0
2.18k stars 1.1k forks source link

EVM dataword ONE is null #1266

Open tangkunprimeledger opened 5 years ago

tangkunprimeledger commented 5 years ago

class https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java static ONE is null, bug in line 81;

    public static final DataWord ONE = DataWord.of((byte) 1);

     public static DataWord of(int num) {
        return of(intToBytes(num));
      }

      public static DataWord of(byte[] data) {
        if (data == null || data.length == 0) {
            return DataWord.ZERO;
        }
        int leadingZeroBits = numberOfLeadingZeros(data);
        int valueBits = 8 * data.length - leadingZeroBits;
        if (valueBits <= 8) {
            if (data[data.length - 1] == 0) {
                return DataWord.ZERO;
            }
            if (data[data.length - 1] == 1) {
         //hotfix: dataWord one is not init 
              /* * byte[] bytes = new byte[8 * data.length];
                bytes[bytes.length - 1] = 1;
                return new DataWord(bytes);*/
           //bug:return ONE but ONE is not init,so ONE is null
              return DataWord.ONE ;
            }
        }

        if (data.length == 32) {
            return new DataWord(java.util.Arrays.copyOf(data, data.length));
        } else if (data.length <= 32) {
            byte[] bytes = new byte[32];
            System.arraycopy(data, 0, bytes, 32 - data.length, data.length);
            return new DataWord(bytes);
        } else {
            throw new RuntimeException(String.format("Data word can't exceed 32 bytes: 0x%s", ByteUtil.toHexString(data)));
        }
    }
zilm13 commented 5 years ago

I've created test and it passes. Why do you think it's bugged?


    @Test
    public void testOne() {
        byte[] input = new byte[] {0x01};
        DataWord one = DataWord.of(input);
        assertArrayEquals(Hex.decode("0000000000000000000000000000000000000000000000000000000000000001"), one.getData());
    }
tangkunprimeledger commented 5 years ago

@zilm13 Are you sure your source code(DataWord ) is consistent with mine?

zilm13 commented 5 years ago

@tangkunprimeledger mine is develop