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

wasm 代理跨合约调用,被调用合约 platon_caller 获取的地址应该是调用合约的caller,不应该是调用合约的地址。 #1779

Closed
jatel opened this issue May 12, 2021 · 2 comments
Assignees
Labels
bug 🐛 Something isn't working Fixed

Comments

@jatel
Copy link
Contributor

jatel commented May 12, 2021

Hi there,

wasm 代理跨合约调用,被调用合约 platon_caller 获取的地址错误。

System information

PlatON version: platon version
OS & Version: Windows/Linux/OSX
Commit hash : (if develop)

Expected behaviour

应该是调用合约的 caller

Actual behaviour

不应该是 调用合约的地址

Steps to reproduce the behaviour

  1. 部署一个被调用 wasm 合约,在某一个合约方法里面通过 platon_caller函数获取被调用合约的 caller。
  2. 在调用合约里面通过代理跨合约调用被调用合约里面的方法。
// callee 合约
  ACTION bool Approve(const Address &spender, u128 value) override {
    Address sender = platon_caller();
    privacy_assert(value > 0, "PlatON ARC20: approve amount illegal");
    SetAllowance(sender, spender, value);
    PLATON_EMIT_EVENT2(ApprovalEvent, sender, spender, value);
    DEBUG("approve", "sender:", sender.toString(),
          "spender:", spender.toString(), "value:", value);
    return true;
  }
// caller 合约
 function Approve_delegatecall(address wasm, address spender, uint value) internal returns (bool){
  uint64 methord = RLPEncode.hash("Approve");
  bytes memory rlpMethord = RLPEncode.encodeUint(uint(methord));
  
  bytes memory rlpPara0 = RLPEncode.encodeAddress(spender);
  bytes memory rlpPara1 = RLPEncode.encodeUint(value);
  bytes[] memory allInput = new bytes[](3);
  allInput[0] = rlpMethord;
  allInput[1] = rlpPara0;
  allInput[2] = rlpPara1;
  bytes memory payload = RLPEncode.encodeList(allInput);
  (bool success, bytes memory data) = wasm.delegatecall(payload);
  if(!success){
	  revert();
  }
  
  RLPReader.RLPItem memory rlpItem = RLPReader.toRlpItem(data);
  bool result  = RLPReader.toBoolean(rlpItem);
  return result;
 }

Backtrace

[backtrace]
@TraceBundy
Copy link
Contributor

原因是caller调用时,获取地址错误。需要对此代码进行修复

_, err := proc.WriteAt(ctx.contract.caller.Address().Bytes(), int64(dst))

@benbaley
Copy link
Member

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working Fixed
Projects
None yet
Development

No branches or pull requests

3 participants