Closed geolffreym closed 1 week ago
hey @geolffreym is the screenshot where you say The returned in console:
from Traces
, that is by running script with -vvvv
?
Hey @grandizzy , thats right, i missed the param in the issue description..
forge script --chain polygon-amoy script/01_Create_SubscriptionAgreement.s.sol --rpc-url polygon-amoy --broadcast --verify --skip-simulation -vvvv
so there's the presimulation phase, that is before tx to be included hence different block.timestamp, given a contract like
contract Counter {
event CreatedAt(uint256 ts);
constructor(uint256 ts) {
emit CreatedAt(block.timestamp);
}
}
running forge script script/Counter.s.sol --rpc-url RPC_URL -vvvv --broadcast
you will see that's even before a simulation / timestamp different between these stages too
[⠒] Compiling...
No files changed, compilation skipped
Traces:
[97106] CounterScript::run()
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [56396] → new Counter@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
│ ├─ emit CreatedAt(ts: 1731601737 [1.731e9])
│ └─ ← [Return] 265 bytes of code
├─ [0] VM::stopBroadcast()
│ └─ ← [Return]
└─ ← [Stop]
Script ran successfully.
## Setting up 1 EVM.
==========================
Simulated On-chain Traces:
[56396] → new Counter@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
├─ emit CreatedAt(ts: 1731601741 [1.731e9])
└─ ← [Return] 265 bytes of code
==========================
Chain 10
Estimated gas price: 0.000101426 gwei
Estimated total gas used for script: 150618
Estimated amount required: 0.000000015276581268 ETH
==========================
therefore not possible to see in trace the exact value resulted within mined tx. Hope this makes sense
Ok! in my case i am skipping the simulation. Anyway i realized that the returned proof is inconsistent too?
uint256 proof = IRightsAccessAgreement(rightsAgreement).createAgreement(
10 * 1e18,
mmc,
rightsPolicyManager,
parties,
""
);
console.logUint(proof);
require(proof == expected); <- fail
presimulation always happens (even if skipping the simulation) take for example this run that won't broadcast tx because of using the default sender
forge script script/Counter.s.sol --rpc-url https://opt-mainnet.g.alchemy.com/v2/p5S0MgJrB48Y_RuVrOcVp3wLnV6Vzd8a -vvvv --broadcast --skip-simulation
[⠒] Compiling...
No files changed, compilation skipped
Traces:
[97106] CounterScript::run()
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [56396] → new Counter@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
│ ├─ emit CreatedAt(ts: 1731602227 [1.731e9])
│ └─ ← [Return] 265 bytes of code
├─ [0] VM::stopBroadcast()
│ └─ ← [Return]
└─ ← [Stop]
Script ran successfully.
SKIPPING ON CHAIN SIMULATION.
Transactions saved to: broadcast/Counter.s.sol/10/run-latest.json
Sensitive values saved to: cache/Counter.s.sol/10/run-latest.json
Error: You seem to be using Foundry's default sender. Be sure to set your own --sender.
The trace is not from the mined tx but from the local presimulation phase.
Ok, just to be sure i am following you @grandizzy :
contract OrchestrateRightsAuthorizer is Script {
function run() external {
uint256 admin = vm.envUint("PRIVATE_KEY");
address mmc = vm.envAddress("MMC");
address rightsPolicyManager = vm.envAddress("RIGHT_POLICY_MANAGER");
address rightsAgreement = vm.envAddress("RIGHT_ACCESS_AGREEMENT");
vm.startBroadcast(admin);
address[] memory parties = new address[](1);
parties[0] = 0x037f2b49721E34296fBD8F9E7e9cc6D5F9ecE7b4;
IERC20(mmc).approve(rightsAgreement, 10 * 1e18);
uint256 proof = IRightsAccessAgreement(rightsAgreement).createAgreement(
10 * 1e18,
mmc,
rightsPolicyManager,
parties,
""
);
console.logUint(proof); <- this proof is the result of the simulation?
vm.stopBroadcast();
}
}
that's my understanding, the proof is computed using the block.timestamp from presimulation phase, hence different in traces than what will be eventually included, but I could be wrong, @klkvr mind to chime in? thank you!
yep, this is probably same as https://github.com/foundry-rs/foundry/issues/8054
@geolffreym hope this clarifies why the difference, going to close this for now. Thank you
@geolffreym hope this clarifies why the difference, going to close this for now. Thank you
Yep! Thank you @grandizzy @klkvr
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
0.2.0
What command(s) is the bug in?
forge script
Operating System
Linux
Describe the bug
When executing a Foundry script that interacts with a smart contract on the Amoy network, an inconsistency in hash values has been observed. The script logs a specific hash value; however, querying the contract directly returns a different hash.
Observed Behavior:
The hash value logged by the Foundry script differs from the hash stored in the contract on Amoy.
Expected Behavior:
The hash values from both the script's log and the contract's storage should be identical, assuming consistent block.timestamp usage.
The returned in console: The registered in explorer:
I created a method to get the stored proof and is correctly retrieved and equal to explorer:
The proof is generated based on the struct and the following code:
The broadcast run show the same registered data as explorer too: