合约验证小技巧

  • Ashton
  • 更新于 2021-12-13 21:56
  • 阅读 3594

本文给出了验证合约时快速填充构造函数参数的一个小技巧。

我们在做合约验证的时候,如果合约是带构造函数的,并且合约是被优化过的,几乎不可避免的会碰到下面的问题。 1.webp

因为事先浏览器并不知道我们的编译优化参数,无法准确填充所部署合约的构造函数参数。 2.webp

正规的解决这个问题的办法,是要比较合约编译出来的字节码和合约部署交易的输入,因为构造函数参数会被放到合约部署交易输入的最后,两者相比较多出来的那部分就是验证合约时要填充的构造函数参数。

这里还有个很简单的小技巧,可以让你快速解决这个问题。

只需要把第一个 00000000000 之前的部分去掉就好。

举例说明,把下面的这段

Note: Unable to determine contructor arguments, please check and replace with correct values (43457263323044656c656761746f723a3a5f736574496d706c656d656e746174696f6e3a2043616c6c6572206d7573742062652061646d696e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f0700a310cb14615a67eec1a8dad5791859f65f100000000000000000000000061a43f8f65ef35d28e63eadb0224b08944d75afb00000000000000000000000000000000000000000000000000470de4df82000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000001200000000000000000000000005ddc595fd33d7b2ab302143c420d0e7f21b622a000000000000000000000000c125cc8e28283afd02f908dd10f3ae415f3c5bb700000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000946696c646120424e420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000466424e420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000)

变成下面这样就好了:

000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f0700a310cb14615a67eec1a8dad5791859f65f100000000000000000000000061a43f8f65ef35d28e63eadb0224b08944d75afb00000000000000000000000000000000000000000000000000470de4df82000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000001200000000000000000000000005ddc595fd33d7b2ab302143c420d0e7f21b622a000000000000000000000000c125cc8e28283afd02f908dd10f3ae415f3c5bb700000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000946696c646120424e420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000466424e420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
点赞 4
收藏 3
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
Ashton
Ashton
0x53b3...c54F
专注于 EVM 和比特币生态的区块链开发者