Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM dataword ONE is null #1266

Open
tangkunprimeledger opened this issue Mar 20, 2019 · 3 comments
Open

EVM dataword ONE is null #1266

tangkunprimeledger opened this issue Mar 20, 2019 · 3 comments

Comments

@tangkunprimeledger
Copy link

tangkunprimeledger commented Mar 20, 2019

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
Copy link
Collaborator

zilm13 commented Mar 20, 2019

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
Copy link
Author

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

@zilm13
Copy link
Collaborator

zilm13 commented Mar 29, 2019

@tangkunprimeledger mine is develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants