diff --git a/tests/solidity/bytecode.js b/tests/solidity/bytecode.js new file mode 100644 index 000000000..8796aabfa --- /dev/null +++ b/tests/solidity/bytecode.js @@ -0,0 +1,6 @@ +{ + "linkReferences": {}, + "object": "608060405234801561001057600080fd5b5061001961007a565b604051809103906000f080158015610035573d6000803e3d6000fd5b506000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061008a565b60405161015f8061055c83390190565b6104c3806100996000396000f3fe60806040526004361061005c576000357c01000000000000000000000000000000000000000000000000000000009004806355313dea146100615780636d3d141614610078578063b9d1e5aa1461008f578063f8a8fd6d146100a6575b600080fd5b34801561006d57600080fd5b506100766100bd565b005b34801561008457600080fd5b5061008d6100bf565b005b34801561009b57600080fd5b506100a46100c4565b005b3480156100b257600080fd5b506100bb6100c6565b005b005b600080fd5bfe5b600160021a6002f35b60058110156100e3576001810190506100cf565b5060065b60058111156100fb576001810190506100e7565b5060015b6005811215610113576001810190506100ff565b5060065b600581131561012b57600181019050610117565b5060021561013857600051505b60405160208101602060048337505060405160208101602060048339505060405160208101602060048360003c50503660005b81811015610182576002815260018101905061016b565b505060008020506000602060403e6010608060106040610123612710fa506020610123600af05060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600060405180807f697353616d654164647265737328616464726573732c61646472657373290000815250601e01905060405180910390209050600033905060405182815281600482015281602482015260648101604052602081604483600088611388f1505060405182815281600482015281602482015260648101604052602081604483600088611388f250506040518281528160048201528160248201526064810160405260208160448387611388f4505060006242004290507f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001026040518082815260200191505060405180910390a07f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001026040518082815260200191505060405180910390a13373ffffffffffffffffffffffffffffffffffffffff166001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001026040518082815260200191505060405180910390a2806001023373ffffffffffffffffffffffffffffffffffffffff166001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001026040518082815260200191505060405180910390a380600102816001023373ffffffffffffffffffffffffffffffffffffffff166001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001027f50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb206001026040518082815260200191505060405180910390a46002fffea165627a7a723058200e51baa2b454b47fdf0ef596fa24aff8ed3a3727b7481ebd25349182ce7152a30029608060405234801561001057600080fd5b5061013f806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063161e715014610040575b600080fd5b34801561004c57600080fd5b506100af6004803603604081101561006357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506100c9565b604051808215151515815260200191505060405180910390f35b60008173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610108576001905061010d565b600090505b9291505056fea165627a7a72305820358f67a58c115ea636b0b8e5c4ca7a52b8192d0f3fa98a4434d6ea04596b5d0d0029", + "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x19 PUSH2 0x7A JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 PUSH1 0x0 CREATE DUP1 ISZERO DUP1 ISZERO PUSH2 0x35 JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP PUSH1 0x0 DUP1 PUSH2 0x100 EXP DUP2 SLOAD DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF MUL NOT AND SWAP1 DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND MUL OR SWAP1 SSTORE POP PUSH2 0x8A JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x15F DUP1 PUSH2 0x55C DUP4 CODECOPY ADD SWAP1 JUMP JUMPDEST PUSH2 0x4C3 DUP1 PUSH2 0x99 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x5C JUMPI PUSH1 0x0 CALLDATALOAD PUSH29 0x100000000000000000000000000000000000000000000000000000000 SWAP1 DIV DUP1 PUSH4 0x55313DEA EQ PUSH2 0x61 JUMPI DUP1 PUSH4 0x6D3D1416 EQ PUSH2 0x78 JUMPI DUP1 PUSH4 0xB9D1E5AA EQ PUSH2 0x8F JUMPI DUP1 PUSH4 0xF8A8FD6D EQ PUSH2 0xA6 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x6D JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x76 PUSH2 0xBD JUMP JUMPDEST STOP JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x84 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x8D PUSH2 0xBF JUMP JUMPDEST STOP JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x9B JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0xA4 PUSH2 0xC4 JUMP JUMPDEST STOP JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0xB2 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0xBB PUSH2 0xC6 JUMP JUMPDEST STOP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST INVALID JUMPDEST PUSH1 0x1 PUSH1 0x2 BYTE PUSH1 0x2 RETURN JUMPDEST PUSH1 0x5 DUP2 LT ISZERO PUSH2 0xE3 JUMPI PUSH1 0x1 DUP2 ADD SWAP1 POP PUSH2 0xCF JUMP JUMPDEST POP PUSH1 0x6 JUMPDEST PUSH1 0x5 DUP2 GT ISZERO PUSH2 0xFB JUMPI PUSH1 0x1 DUP2 ADD SWAP1 POP PUSH2 0xE7 JUMP JUMPDEST POP PUSH1 0x1 JUMPDEST PUSH1 0x5 DUP2 SLT ISZERO PUSH2 0x113 JUMPI PUSH1 0x1 DUP2 ADD SWAP1 POP PUSH2 0xFF JUMP JUMPDEST POP PUSH1 0x6 JUMPDEST PUSH1 0x5 DUP2 SGT ISZERO PUSH2 0x12B JUMPI PUSH1 0x1 DUP2 ADD SWAP1 POP PUSH2 0x117 JUMP JUMPDEST POP PUSH1 0x2 ISZERO PUSH2 0x138 JUMPI PUSH1 0x0 MLOAD POP JUMPDEST PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 ADD PUSH1 0x20 PUSH1 0x4 DUP4 CALLDATACOPY POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 ADD PUSH1 0x20 PUSH1 0x4 DUP4 CODECOPY POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 ADD PUSH1 0x20 PUSH1 0x4 DUP4 PUSH1 0x0 EXTCODECOPY POP POP CALLDATASIZE PUSH1 0x0 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0x182 JUMPI PUSH1 0x2 DUP2 MSTORE PUSH1 0x1 DUP2 ADD SWAP1 POP PUSH2 0x16B JUMP JUMPDEST POP POP PUSH1 0x0 DUP1 KECCAK256 POP PUSH1 0x0 PUSH1 0x20 PUSH1 0x40 RETURNDATACOPY PUSH1 0x10 PUSH1 0x80 PUSH1 0x10 PUSH1 0x40 PUSH2 0x123 PUSH2 0x2710 STATICCALL POP PUSH1 0x20 PUSH2 0x123 PUSH1 0xA CREATE POP PUSH1 0x0 DUP1 PUSH1 0x0 SWAP1 SLOAD SWAP1 PUSH2 0x100 EXP SWAP1 DIV PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 POP PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP1 PUSH32 0x697353616D654164647265737328616464726573732C61646472657373290000 DUP2 MSTORE POP PUSH1 0x1E ADD SWAP1 POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 KECCAK256 SWAP1 POP PUSH1 0x0 CALLER SWAP1 POP PUSH1 0x40 MLOAD DUP3 DUP2 MSTORE DUP2 PUSH1 0x4 DUP3 ADD MSTORE DUP2 PUSH1 0x24 DUP3 ADD MSTORE PUSH1 0x64 DUP2 ADD PUSH1 0x40 MSTORE PUSH1 0x20 DUP2 PUSH1 0x44 DUP4 PUSH1 0x0 DUP9 PUSH2 0x1388 CALL POP POP PUSH1 0x40 MLOAD DUP3 DUP2 MSTORE DUP2 PUSH1 0x4 DUP3 ADD MSTORE DUP2 PUSH1 0x24 DUP3 ADD MSTORE PUSH1 0x64 DUP2 ADD PUSH1 0x40 MSTORE PUSH1 0x20 DUP2 PUSH1 0x44 DUP4 PUSH1 0x0 DUP9 PUSH2 0x1388 CALLCODE POP POP PUSH1 0x40 MLOAD DUP3 DUP2 MSTORE DUP2 PUSH1 0x4 DUP3 ADD MSTORE DUP2 PUSH1 0x24 DUP3 ADD MSTORE PUSH1 0x64 DUP2 ADD PUSH1 0x40 MSTORE PUSH1 0x20 DUP2 PUSH1 0x44 DUP4 DUP8 PUSH2 0x1388 DELEGATECALL POP POP PUSH1 0x0 PUSH3 0x420042 SWAP1 POP PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG0 PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG2 DUP1 PUSH1 0x1 MUL CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG3 DUP1 PUSH1 0x1 MUL DUP2 PUSH1 0x1 MUL CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH32 0x50CB9FE53DAA9737B786AB3646F04D0150DC50EF4E75F59509D83667AD5ADB20 PUSH1 0x1 MUL PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG4 PUSH1 0x2 SELFDESTRUCT INVALID LOG1 PUSH6 0x627A7A723058 KECCAK256 0xe MLOAD 0xba LOG2 0xb4 SLOAD 0xb4 PUSH32 0xDF0EF596FA24AFF8ED3A3727B7481EBD25349182CE7152A30029608060405234 DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x13F DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x3B JUMPI PUSH1 0x0 CALLDATALOAD PUSH29 0x100000000000000000000000000000000000000000000000000000000 SWAP1 DIV DUP1 PUSH4 0x161E7150 EQ PUSH2 0x40 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x4C JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0xAF PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x40 DUP2 LT ISZERO PUSH2 0x63 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 DUP1 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0xC9 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 ISZERO ISZERO ISZERO ISZERO DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH1 0x0 DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ ISZERO PUSH2 0x108 JUMPI PUSH1 0x1 SWAP1 POP PUSH2 0x10D JUMP JUMPDEST PUSH1 0x0 SWAP1 POP JUMPDEST SWAP3 SWAP2 POP POP JUMP INVALID LOG1 PUSH6 0x627A7A723058 KECCAK256 CALLDATALOAD DUP16 PUSH8 0xA58C115EA636B0B8 0xe5 0xc4 0xca PUSH27 0x52B8192D0F3FA98A4434D6EA04596B5D0D00290000000000000000 ", + "sourceMap": "221:8828:0:-;;;263:110;8:9:-1;5:2;;;30:1;27;20:12;5:2;263:110:0;324:11;;:::i;:::-;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;324:11:0;316:5;;:19;;;;;;;;;;;;;;;;;;221:8828;;;;;;;;;;;;:::o;:::-;;;;;;;" +} diff --git a/tests/solidity/contracts/Migrations.sol b/tests/solidity/contracts/Migrations.sol new file mode 100644 index 000000000..c378ffb02 --- /dev/null +++ b/tests/solidity/contracts/Migrations.sol @@ -0,0 +1,23 @@ +pragma solidity >=0.4.21 <0.6.0; + +contract Migrations { + address public owner; + uint public last_completed_migration; + + constructor() public { + owner = msg.sender; + } + + modifier restricted() { + if (msg.sender == owner) _; + } + + function setCompleted(uint completed) public restricted { + last_completed_migration = completed; + } + + function upgrade(address new_address) public restricted { + Migrations upgraded = Migrations(new_address); + upgraded.setCompleted(last_completed_migration); + } +} diff --git a/tests/solidity/contracts/OpCodes.sol b/tests/solidity/contracts/OpCodes.sol new file mode 100644 index 000000000..9e3a0ebb0 --- /dev/null +++ b/tests/solidity/contracts/OpCodes.sol @@ -0,0 +1,322 @@ +pragma solidity >=0.4.21 <0.6.0; + +contract Test1 { + function isSameAddress(address a, address b) public returns(bool){ //Simply add the two arguments and return + if (a == b) return true; + return false; + } +} + +contract OpCodes { + + Test1 test1; + + constructor() public { //Constructor function + test1 = new Test1(); //Create new "Test1" function + } + + modifier onlyOwner(address _owner) { + require(msg.sender == _owner); + _; + } + // Add a todo to the list + function test() public { + + //simple_instructions + /*assembly { pop(sub(dup1, mul(dup1, dup1))) }*/ + + //keywords + assembly { pop(address) return(2, byte(2,1)) } + + //label_complex + /*assembly { 7 abc: 8 eq jump(abc) jumpi(eq(7, 8), abc) pop } + assembly { pop(jumpi(eq(7, 8), abc)) jump(abc) }*/ + + //functional + /*assembly { let x := 2 add(7, mul(6, x)) mul(7, 8) add =: x }*/ + + //for_statement + assembly { for { let i := 1 } lt(i, 5) { i := add(i, 1) } {} } + assembly { for { let i := 6 } gt(i, 5) { i := add(i, 1) } {} } + assembly { for { let i := 1 } slt(i, 5) { i := add(i, 1) } {} } + assembly { for { let i := 6 } sgt(i, 5) { i := add(i, 1) } {} } + + //no_opcodes_in_strict + assembly { pop(callvalue()) } + + //no_dup_swap_in_strict + /*assembly { swap1() }*/ + + //print_functional + assembly { let x := mul(sload(0x12), 7) } + + //print_if + assembly { if 2 { pop(mload(0)) }} + + //function_definitions_multiple_args + assembly { function f(a, d){ mstore(a, d) } function g(a, d) -> x, y {}} + + //sstore + assembly { function f(a, d){ sstore(a, d) } function g(a, d) -> x, y {}} + + //mstore8 + assembly { function f(a, d){ mstore8(a, d) } function g(a, d) -> x, y {}} + + //calldatacopy + assembly { + let a := mload(0x40) + let b := add(a, 32) + calldatacopy(a, 4, 32) + /*calldatacopy(b, add(4, 32), 32)*/ + /*result := add(mload(a), mload(b))*/ + } + + //codecopy + assembly { + let a := mload(0x40) + let b := add(a, 32) + codecopy(a, 4, 32) + } + + //codecopy + assembly { + let a := mload(0x40) + let b := add(a, 32) + extcodecopy(0, a, 4, 32) + } + + //for_statement + assembly { let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } } + + //keccak256 + assembly { pop(keccak256(0,0)) } + + //returndatasize + assembly { let r := returndatasize } + + //returndatacopy + assembly { returndatacopy(64, 32, 0) } + //byzantium vs const Constantinople + //staticcall + assembly { pop(staticcall(10000, 0x123, 64, 0x10, 128, 0x10)) } + + /*//create2 Constantinople + assembly { pop(create2(10, 0x123, 32, 64)) }*/ + + //create Constantinople + assembly { pop(create(10, 0x123, 32)) } + + //shift Constantinople + /*assembly { pop(shl(10, 32)) } + assembly { pop(shr(10, 32)) } + assembly { pop(sar(10, 32)) }*/ + + + //not + assembly { pop( not(0x1f)) } + + //exp + assembly { pop( exp(2, 226)) } + + //mod + assembly { pop( mod(3, 9)) } + + //smod + assembly { pop( smod(3, 9)) } + + //div + assembly { pop( div(4, 2)) } + + //sdiv + assembly { pop( sdiv(4, 2)) } + + //iszero + assembly { pop(iszero(1)) } + + //and + assembly { pop(and(2,3)) } + + //or + assembly { pop(or(3,3)) } + + //xor + assembly { pop(xor(3,3)) } + + //addmod + assembly { pop(addmod(3,3,6)) } + + //mulmod + assembly { pop(mulmod(3,3,3)) } + + //signextend + assembly { pop(signextend(1, 10)) } + + //sha3 + assembly { pop(calldataload(0)) } + + //blockhash + assembly { pop(blockhash(sub(number(), 1))) } + + //balance + assembly { pop(balance(0x0)) } + + //caller + assembly { pop(caller()) } + + //codesize + assembly { pop(codesize()) } + + //extcodesize + assembly { pop(extcodesize(0x1)) } + + //origin + assembly { pop(origin()) } + + //gas + assembly { pop(gas())} + + //msize + assembly { pop(msize())} + + //pc + assembly { pop(pc())} + + //gasprice + assembly { pop(gasprice())} + + //coinbase + assembly { pop(coinbase())} + + //timestamp + assembly { pop(timestamp())} + + //number + assembly { pop(number())} + + //difficulty + assembly { pop(difficulty())} + + //gaslimit + assembly { pop(gaslimit())} + + //call + address contractAddr = address(test1); + bytes4 sig = bytes4(keccak256("isSameAddress(address,address)")); //Function signature + address a = msg.sender; + + assembly { + let x := mload(0x40) //Find empty storage location using "free memory pointer" + mstore(x,sig) //Place signature at begining of empty storage + mstore(add(x,0x04),a) // first address parameter. just after signature + mstore(add(x,0x24),a) // 2nd address parameter - first padded. add 32 bytes (not 20 bytes) + mstore(0x40,add(x,0x64)) // this is missing in other examples. Set free pointer before function call. so it is used by called function. + // new free pointer position after the output values of the called function. + + let success := call( + 5000, //5k gas + contractAddr, //To addr + 0, //No wei passed + x, // Inputs are at location x + 0x44, //Inputs size two padded, so 68 bytes + x, //Store output over input + 0x20) //Output is 32 bytes long + } + + //callcode + assembly { + let x := mload(0x40) //Find empty storage location using "free memory pointer" + mstore(x,sig) //Place signature at begining of empty storage + mstore(add(x,0x04),a) // first address parameter. just after signature + mstore(add(x,0x24),a) // 2nd address parameter - first padded. add 32 bytes (not 20 bytes) + mstore(0x40,add(x,0x64)) // this is missing in other examples. Set free pointer before function call. so it is used by called function. + // new free pointer position after the output values of the called function. + + let success := callcode( + 5000, //5k gas + contractAddr, //To addr + 0, //No wei passed + x, // Inputs are at location x + 0x44, //Inputs size two padded, so 68 bytes + x, //Store output over input + 0x20) //Output is 32 bytes long + } + + //delegatecall + assembly { + let x := mload(0x40) //Find empty storage location using "free memory pointer" + mstore(x,sig) //Place signature at begining of empty storage + mstore(add(x,0x04),a) // first address parameter. just after signature + mstore(add(x,0x24),a) // 2nd address parameter - first padded. add 32 bytes (not 20 bytes) + mstore(0x40,add(x,0x64)) // this is missing in other examples. Set free pointer before function call. so it is used by called function. + // new free pointer position after the output values of the called function. + + let success := delegatecall( + 5000, //5k gas + contractAddr, //To addr + x, // Inputs are at location x + 0x44, //Inputs size two padded, so 68 bytes + x, //Store output over input + 0x20) //Output is 32 bytes long + } + + uint256 _id = 0x420042; + + //log0 + log0( + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20) + ); + + //log1 + log1( + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20) + ); + + //log2 + log2( + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(uint256(msg.sender)) + ); + + //log3 + log3( + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(uint256(msg.sender)), + bytes32(_id) + ); + + //log4 + log4( + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), + bytes32(uint256(msg.sender)), + bytes32(_id), + bytes32(_id) + + ); + + //selfdestruct + assembly { selfdestruct(0x02) } + } + + function test_revert() public { + + //revert + assembly{ revert(0, 0) } + } + + function test_invalid() public { + + //revert + assembly{ invalid() } + } + + function test_stop() public { + + //revert + assembly{ stop() } + } + +} diff --git a/tests/solidity/migrations/1_initial_migration.js b/tests/solidity/migrations/1_initial_migration.js new file mode 100644 index 000000000..ee2135d29 --- /dev/null +++ b/tests/solidity/migrations/1_initial_migration.js @@ -0,0 +1,5 @@ +const Migrations = artifacts.require("Migrations"); + +module.exports = function(deployer) { + deployer.deploy(Migrations); +}; diff --git a/tests/solidity/migrations/2_opCodes_migration.js b/tests/solidity/migrations/2_opCodes_migration.js new file mode 100644 index 000000000..65c6b6dc1 --- /dev/null +++ b/tests/solidity/migrations/2_opCodes_migration.js @@ -0,0 +1,5 @@ +var OpCodes = artifacts.require("./OpCodes.sol"); + +module.exports = function(deployer) { + deployer.deploy(OpCodes); +}; diff --git a/tests/solidity/test/opCodes.js b/tests/solidity/test/opCodes.js new file mode 100644 index 000000000..80abacef2 --- /dev/null +++ b/tests/solidity/test/opCodes.js @@ -0,0 +1,34 @@ +const TodoList = artifacts.require('./OpCodes.sol') +const assert = require('assert') +let contractInstance +const Web3 = require('web3'); +const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); +// const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:9545')); + +contract('OpCodes', (accounts) => { + beforeEach(async () => { + contractInstance = await TodoList.deployed() + }) + it('Should run without errors the majorit of opcodes', async () => { + await contractInstance.test() + await contractInstance.test_stop() + + }) + + it('Should throw invalid op code', async () => { + try{ + await contractInstance.test_invalid() + } + catch(error) { + console.error(error); + } + }) + + it('Should revert', async () => { + try{ + await contractInstance.test_revert() } + catch(error) { + console.error(error); + } + }) +}) diff --git a/tests/solidity/truffle-config.js b/tests/solidity/truffle-config.js new file mode 100644 index 000000000..c06d8316f --- /dev/null +++ b/tests/solidity/truffle-config.js @@ -0,0 +1,108 @@ +/** + * Use this file to configure your truffle project. It's seeded with some + * common settings for different networks and features like migrations, + * compilation and testing. Uncomment the ones you need or modify + * them to suit your project as necessary. + * + * More information about configuration can be found at: + * + * truffleframework.com/docs/advanced/configuration + * + * To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider) + * to sign your transactions before they're sent to a remote public node. Infura API + * keys are available for free at: infura.io/register + * + * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate + * public/private key pairs. If you're publishing your code to GitHub make sure you load this + * phrase from a file you've .gitignored so it doesn't accidentally become public. + * + */ + +// const HDWalletProvider = require('truffle-hdwallet-provider'); +// const infuraKey = "fj4jll3k....."; +// +// const fs = require('fs'); +// const mnemonic = fs.readFileSync(".secret").toString().trim(); + +// module.exports = { +// /** +// * Networks define how you connect to your ethereum client and let you set the +// * defaults web3 uses to send transactions. If you don't specify one truffle +// * will spin up a development blockchain for you on port 9545 when you +// * run `develop` or `test`. You can ask a truffle command to use a specific +// * network from the command line, e.g +// * +// * $ truffle test --network +// */ +// +// networks: { +// // Useful for testing. The `development` name is special - truffle uses it by default +// // if it's defined here and no other network is specified at the command line. +// // You should run a client (like ganache-cli, geth or parity) in a separate terminal +// // tab if you use this network and you must also set the `host`, `port` and `network_id` +// // options below to some value. +// // +// // development: { +// // host: "127.0.0.1", // Localhost (default: none) +// // port: 8545, // Standard Ethereum port (default: none) +// // network_id: "*", // Any network (default: none) +// // }, +// +// // Another network with more advanced options... +// // advanced: { +// // port: 8777, // Custom port +// // network_id: 1342, // Custom network +// // gas: 8500000, // Gas sent with each transaction (default: ~6700000) +// // gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei) +// // from:
, // Account to send txs from (default: accounts[0]) +// // websockets: true // Enable EventEmitter interface for web3 (default: false) +// // }, +// +// // Useful for deploying to a public network. +// // NB: It's important to wrap the provider as a function. +// // ropsten: { +// // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/${infuraKey}`), +// // network_id: 3, // Ropsten's id +// // gas: 5500000, // Ropsten has a lower block limit than mainnet +// // confirmations: 2, // # of confs to wait between deployments. (default: 0) +// // timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) +// // skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) +// // }, +// +// // Useful for private networks +// // private: { +// // provider: () => new HDWalletProvider(mnemonic, `https://network.io`), +// // network_id: 2111, // This network is yours, in the cloud. +// // production: true // Treats this network as if it was a public net. (default: false) +// // } +// }, +// +// // Set default mocha options here, use special reporters etc. +// mocha: { +// // timeout: 100000 +// }, +// +// // Configure your compilers +// compilers: { +// solc: { +// // version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version) +// // docker: true, // Use "0.5.1" you've installed locally with docker (default: false) +// // settings: { // See the solidity docs for advice about optimization and evmVersion +// // optimizer: { +// // enabled: false, +// // runs: 200 +// // }, +// // evmVersion: "byzantium" +// // } +// } +// } +// } +module.exports = { + networks: { + development: { + host: 'localhost', + port: 8545, + network_id: '*' + } + } +}