CheckinNewYear

先看一眼合约,并不复杂,就一签到题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SPDX-License-Identifier: shu shao de xiao mi di
pragma solidity ^0.8.9;
contract HappyNewYear{
string private NewYear;
constructor(string memory _newyear ) {
NewYear = _newyear;
}
function happyNewYear(string memory _newYear) public payable {
require(uint160(msg.sender) |
2**16 * 3**3 * 5 * 7 * 13 * 17 * 19 * 37 * 73 * 97 * 109 * 241 * 257 * 433 * 577 * 673 * 38737 * 487824887233 == 2**2 * 17 * 67 * 733 * 316139 * 18992431891 * 72887484710091183279372959, "Not this Year");
NewYear = _newYear;
}
function isSolved() public view returns (bool){
require(keccak256(abi.encodePacked(NewYear)) == keccak256(abi.encodePacked("Happy")),"not HappyNewYear");
return true;
}
}

唯一的要点可能就是钱包地址需要满足一定的要求,不过这要求也不算严格,问题不大:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from web3 import Account

while True:
account = Account.create()
address = account.address
address_int = int(address, 16)
private_key = account._private_key.hex()
if address_int | 1461501637330902918203684832716283019655932477440 == \
1461501637330902918203684832716283019655932485668:
break
print(f"{address=}", f"{private_key=}", sep="\n")

# address='0xf10DBbeAa1C8fE5971610fac5768E91DDe732024'
# private_key='0xf288cac72c6c753e2251b334a07ba40c054e072e4f20fdd763bf8e25f5fb9274'

拿着合约源代码生成个 ABI,然后操作合约就可以了。具体的代码在之前的区块链题解中有,咱也是复制过来改一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
with open("contract_abi.json", "r") as abi_file:
contract_abi = json.load(abi_file)
contract = w3.eth.contract(address=contract_address, abi=contract_abi)

def send_transaction(transaction, private_key):
signed_transaction = w3.eth.account.sign_transaction(
transaction, private_key)
transaction_hash = w3.eth.send_raw_transaction(
signed_transaction.rawTransaction)
w3.eth.wait_for_transaction_receipt(transaction_hash)
return transaction_hash

def happy_new_year(wallet_address: str, private_key: str):
transaction = contract.functions.happyNewYear("Happy").build_transaction({
"chainId": 39813,
"maxFeePerGas": w3.to_wei(1.000000014, 'gwei'),
"maxPriorityFeePerGas": w3.to_wei(1, 'gwei'),
"gas": 0x200000,
"value": w3.to_wei(0, 'ether'),
"nonce": w3.eth.get_transaction_count(wallet_address),
})
return send_transaction(transaction, private_key)