简体   繁体   English

solidity v0.8.15:ETH 主网上的需求和映射问题

[英]solidity v0.8.15 : require & mapping issues on ETH mainnet

I'm working on a NFT management contrat;我正在制定一份 NFT 管理合同; I can see everything works fine on rinkeby testnet, but when I'm calling the same functions on mainnet, I get errors many false errors with require.我可以看到在 rinkeby 测试网上一切正常,但是当我在主网上调用相同的函数时,我得到了许多错误的错误错误。 code was compiled on REMIX Ide;代码在 REMIX Ide 上编译;

Here is an example:这是一个例子:

mapping(address => mapping(uint => uint8) public handledNfts;

mapping(bytes32 => uint8) public usedHashes;

function create(address contractAddress, uint tokenId, bytes32 hash) external
{
    uint8 vCheck = usedHashes[hash];

    require(vCheck!=1, "Bad hash");    // sometimes it has false-positive

    usedHashes[ hash ] = 1;

    uint8 vCheck = handledNfts[contractAddress][tokenId];
    
    require(vCheck!=1, "Already created");    // False-positive sometimes also

    handledNfts[contractAddress][tokenId] = 1;



    //--- DO SOMETHING ....
}

So when I'm on rinkeby any call to create will work.因此,当我在 rinkeby 时,任何创建调用都会起作用。 However on mainnet, the create function returns a "Bad hash" or "Already closed" for no real reason, but sometimes in works like a charm.但是在主网上,创建 function 会无缘无故地返回“错误哈希”或“已关闭”,但有时会像魅力一样工作。

So I don't know what's the problem on mainnet for a code which works fine from testnet?所以我不知道在测试网中运行良好的代码在主网上有什么问题?

It's strange because the handledNfts[contractAddress][tokenId] should not be at ==1 when starting using the contrat.这很奇怪,因为在开始使用合同时,handledNfts[contractAddress][tokenId] 不应该是 ==1。 However solidity says the hash has already been used or the nft says to be already managed, when it's not true.然而,solidity 表示 hash 已被使用或 nft 表示已被管理,但事实并非如此。 Sometimes it works and sometimes it doesn't.有时它有效,有时则无效。 Most of the time it doesn't大多数时候它不会

The hash using in the create function is always unique for each call.在创建 function 中使用的 hash 对于每个调用始终是唯一的。

Can someone help me find a solution on that instability, please?有人可以帮我找到解决这种不稳定性的方法吗? It seems like mapping objects with a require don't work properly with me.似乎带有 require 的映射对象不适用于我。

I compile the code through remix directly, with solidity v0.8.15 https://remix.ethereum.org/#optimize=true&runs=200&evmVersion=null&version=soljson-v0.8.15+commit.e14f2714.js我通过 remix 直接编译代码,使用solidity v0.8.15 https://remix.ethereum.org/#optimize=true&runs=200&evmVersion=null&version=soljson-v0.8.15+commit.e14f2714.js

stangely also, I'm forced to use a variable to access a mapping object then use that variable;奇怪的是,我被迫使用变量来访问映射 object 然后使用该变量; so a code like this is buggy on me many time:所以像这样的代码对我来说是错误的:

require(usedHashes[hash]!=1, "Hash already used"); <-- buggy on mainnet

Any help please?请问有什么帮助吗?

I understand what happened.我明白发生了什么。 I've been front-runned by a MEV BOT.我被一个 MEV BOT 抢先一步。 It detected an ETH transaction was sent from my smartcontract, and sent a copy-cat of the transaction earlier than mine.它检测到我的智能合约发送了一笔 ETH 交易,并比我的更早发送了该交易的副本。

I've put counter-actions to avoid it.我已经采取了反制措施来避免它。 it's okay now.现在好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM