2020国赛预赛WP
智能合约看看这里
z3
1 | from z3 import * |
hyperthreading
1 | from z3 import * |
oplog
别的都没什么好说的,主要是这个合约部署和后面的Galios Field上面的Sage写法。
如果出题人给的是合约的ABI和字节码,如何部署?
用Remix的控制台,把部署语句压缩成一行直接部署:
1 | (new web3.eth.Contract(JSON.parse('[ { "inputs": [ { "internalType": "uint256", "name": "choose", "type": "uint256" }, { "internalType": "uint256", "name": "arg1", "type": "uint256" }, { "internalType": "uint256", "name": "arg2", "type": "uint256" }, { "internalType": "uint256", "name": "arg3", "type": "uint256" } ], "name": "calcx", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "key1", "type": "uint256" }, { "internalType": "uint256", "name": "key2", "type": "uint256" }, { "internalType": "uint256", "name": "key3", "type": "uint256" } ], "name": "feistel", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_flag", "type": "uint256" } ], "name": "setflag", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "p", "type": "uint256" } ], "name": "setr1", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "p", "type": "uint256" } ], "name": "setr2", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "p", "type": "uint256" } ], "name": "setr3", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "flag", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "r1", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "r2", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "r3", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "x1", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "x2", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "x3", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" } ]'), {data: '0x' + '608060405234801561001057600080fd5b506104f5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c80636ca5b5b01161008c5780638bf6e410116100665780638bf6e41014610236578063a3b7887314610254578063a7ba732e14610272578063c4ee5c77146102a0576100cf565b80636ca5b5b0146101cc5780637059c7e0146101ea578063890eba6814610218576100cf565b80630bcbbd21146100d4578063343943bd146100f25780634ff135711461011057806356b15fe31461012e5780635e031f4a146101705780636c3ce6761461019e575b600080fd5b6100dc6102ec565b6040518082815260200191505060405180910390f35b6100fa6102f2565b6040518082815260200191505060405180910390f35b6101186102f8565b6040518082815260200191505060405180910390f35b61016e6004803603606081101561014457600080fd5b810190808035906020019092919080359060200190929190803590602001909291905050506102fe565b005b61019c6004803603602081101561018657600080fd5b81019080803590602001909291905050506103f5565b005b6101ca600480360360208110156101b457600080fd5b810190808035906020019092919050505061040a565b005b6101d461041f565b6040518082815260200191505060405180910390f35b6102166004803603602081101561020057600080fd5b8101908080359060200190929190505050610425565b005b61022061043a565b6040518082815260200191505060405180910390f35b61023e610440565b6040518082815260200191505060405180910390f35b61025c610446565b6040518082815260200191505060405180910390f35b61029e6004803603602081101561028857600080fd5b810190808035906020019092919050505061044c565b005b6102ea600480360360808110156102b657600080fd5b8101908080359060200190929190803590602001909291908035906020019092919080359060200190929190505050610456565b005b60025481565b60045481565b60055481565b60007155555555555555555555555555555555555590506000712aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa905060008060008460045416925083600454169150829050819250878183181891508290508192508681831818915082905081925085818318189150818318600481905550846005541692508360055416915082905081925087818318189150829050819250868183181891508290508192508581831818915081831860058190555084600654169250836006541691508290508192508781831818915082905081925086818318189150829050819250858183181891508183186006819055505050505050505050565b806000548161040057fe5b0660028190555050565b806000548161041557fe5b0660038190555050565b60015481565b806000548161043057fe5b0660018190555050565b60005481565b60035481565b60065481565b8060008190555050565b600184141561047b5780600354028260025402846001540201016004819055506104b9565b60028414156104a05780600354028260025402846001540201016005819055506104b8565b80600354028260025402846001540201016006819055505b5b5050505056fea264697066735822122035d843a487b40ebb72b85fe1e1239e8fa66574935048ffc5425538b76ad05ac964736f6c63430006010033'})).deploy().send({ from: '0x2f442DA9db20809d245a7D40DE452cd361B2dc90', gas: 1500000, gasPrice: '30000000000000' }, function(error, transactionHash){ }) .on('receipt', function(receipt){ console.log(receipt.contractAddress); }) .then(function(newContractInstance){ console.log(newContractInstance.options.address); }) |
而且相关文档是真的烂的可怕,Infra的API只接受Raw的transaction,非常麻烦。
关于EVM反编译,
https://ethervm.io/decompile 的结果不如 https://ropsten.etherscan.io/bytecode-decompiler
还有就是Z3并不擅长涉及求余之类的数论相关运算,要尽量避免。这次就是通过舍去两个变量让r1
,r2
,r3
得到求解之后利用中国剩余定理的到flag再过滤.
1 | from z3 import * |
lfsr
1 | N = 100 |
电脑被黑
1 | from z3 import * |