DRIVE out of Porto Velho, the capital of the Amazonian state of Rondônia, and you see the trouble the world's largest forest is in. Lorry after lorry trundles by laden with logs; more logs lie by the road, to be collected by smugglers who dumped them on the rumour of a (rare) roadcheck. Charred tree-stumps show where ranchers burned what the loggers left behind; a few cattle roam sparsely through the scrubby fields. In places the acid subsoil shows through, sandy and bone-pale. Seen from above, the roads look like hatchet blows, with dirt tracks radiating outward like thinner wounds. The picture is reproduced across the Amazon's “arc of deforestation” (see map).

The Brazilian Amazon is now home to 24m people, many of them settlers who trekked those roads in the 1960s and 1970s, lured by a government promise that those who farmed “unproductive” land could keep it. Chaotic or corrupt land registries left some without secure title. Rubber-tappers, loggers, miners and charcoal-burners came too. The most recent arrivals are 20,000 construction workers building dams on the Madeira and Xingu rivers to provide electricity to Brazil's populous south. They have attracted some 80,000 camp-followers, many of whom squat on supposedly protected land.

The population of Jaci-Paraná, the nearest town to the Jirau dam being built on the Madeira, has risen from 3,500 to 21,000 in a decade—but it still has just four police. Prostitutes and drug-dealers do well. On payday, says Maria Pereira, a teacher, busloads of construction workers hit town to drink and fight. Knife-killings are common. When the dam is finished, many of the new residents will move on. Behind them, a bit more of the Amazon will be gone.

Brazil's government no longer encourages cutting down the forest. Nearly half of it now lies within indigenous reserves, or state and federal parks where most logging is banned. Private landowners must abide by the Forest Code, a law dating from 1965 that requires them to leave the forest standing on part of their farms (four-fifths in the Amazon, less elsewhere), and in particular around the sources and banks of rivers, and on hillsides.

But the code is routinely flouted. Less than 1% of the fines levied for failing to observe it are ever paid, because of uncertain ownership and poor enforcement. The Suruí, an Amerindian people, recently mapped its territory in Rondônia, on paper strictly protected. The tribe was shocked to find that 7% had been cleared.

In Brasília 2,000km (1,250 miles) and a world away, politicians are haggling over laws that will affect the fate of the forest. Some legislators are pushing a bill that would give Congress, rather than the president, the power to create new reserves. That would probably mean fewer new ones—a blow for the forest, says Ivaneide Bandeira of Kanindé, a non-profit group in Rondônia. “Indigenous people protect the forest better than anyone else,” she says.

The Senate is poised to vote on a new version of the Forest Code, already approved by the lower house. The president, Dilma Rousseff, wants a final version on her desk before Christmas. Everyone agrees that change is needed. The share of private land that must be set aside has risen since 1965 and farmers who were once in compliance but omitted to update their paperwork can end up lumped in with lawbreakers. Kátia Abreu, a senator who is the president of the main farm lobby, says farmers find such uncertainty “deeply worrying”. Environmentalists dislike it too, since it encourages loggers and land-grabbers by fuelling disrespect for the law.

But the consensus has gone no further. The farm lobby wanted all past land clearance regularised, arguing that if farmers had to replant trees, crop output would fall, food prices soar and poor Brazilians go hungry. Greens countered that an amnesty would fuel future deforestation. So far, at least, the farm lobby is winning. The current draft allows farmers to dodge fines for illegal logging and postpone their obligation to replant by simply declaring that their violations were committed before July 2008 and by enrolling in a vague and leisurely “environmental recovery programme”, to be run by individual states.

“This is an amnesty in all but name,” says Maria Cecília Brito, the head of WWF-Brazil, a conservation group. “Without safeguards, states will be able to postpone forever the requirement to act.” After several years in which the annual rate of deforestation fell, this year it has risen, possibly because landowners think the new code will let them get away with it. Law-abiding farmers are outraged. When Darci Ferrarin bought a large farm in Mato Grosso in 1998, he knew that its riverbanks had been illegally cleared. He paid to replant. “Those who deforested illegally should go to jail,” declares his son, Darci Junior.

The only promising aspect of the new code, thinks Roberto Smeraldi of Amazônia Brasileira, a green NGO, is that it offers benefits such as subsidised loans to landowners who have always stuck by the rules, or who are reforesting faster than the law demands. But he laments the missed opportunity for a grand bargain to align opposed interests. A cap-and-trade system like those used to limit industrial pollution in rivers could have helped farmers short of set-aside to comply with the law by paying neighbours with more than the legal minimum to maintain it. That would both have spared farmers from costly replanting and cut future deforestation by making standing forests financially valuable.

Ms Rousseff promises to veto any amnesty for illegal deforesters. But the figleaf of the “environmental recovery programme” may give her scope to temporise, and with a heavy legislative schedule she may be tempted to do so. If she does, the Amazon's best hope will lie with the enlightened farmers and indigenous tribes who care for their land better than the state is willing to.

For Mr Ferrarin, the way to halt deforestation is to use existing farmland better. Almost half his farm of 13,350 hectares (33,000 acres) is set aside as forest; the rest supports 3,000 cattle as well as soya and several other crops, farmed in rotation. Innovative no-till methods cut carbon emissions, fertiliser use and labour. The Ferrarins run workshops to teach other farmers about such “integrated farming” techniques. Mr Ferrarin's daughter, Valkiria, runs a cattle-breeding programme, with an on-site IVF clinic where embryos from prize animals are implanted in surrogates. A productive farm can support an extended family for several generations, he says.

Cassio Carvalho do Val's father settled in Redenção in Pará in 1959. It was then virgin rainforest: the last 150km of the journey was by donkey, carrying dried meat, rice and beans. Nine-tenths of the 300,000 hectares he was granted has since been sold, but the farm is still vast (the average farm in the United States comprises around 160 hectares), and unproductive, with just one cow per hectare of pasture. But his son has started to fatten his cows with grain and plans to try integrated farming. “It's the dream of every crop farmer to be a rancher,” he says with a laugh. “It's so much easier.” But he thinks he needs to keep up with the times.

The Suruí set an example

Some of Brazil's indigenous peoples are redoubling their efforts to protect the standing forest. The 1,300 Suruí have moved their 25 villages to the borders of their territory to get early warning of incursions. With help from Kanindé and others, since 2005 they have started to reforest where intruders have cleared. To the inexperienced eye, the new trees already look ancient (though to the Suruí the sparser cover is still obvious). Next year the tribe will host other indigenous peoples who want to repair deforestation on their own lands. They hope to start teaching non-indigenous folk, too.

The Suruí are the first Brazilian tribal people to set up a REDD project, an international aid scheme to prevent deforestation. Up to 10% of the income generated will go to local non-Indians, to show them that standing forest can create jobs and income. “We are not saying, don't use the forest,” explains the chief, Almir Narayamoga Suruí. “We are saying you should think about the medium and long term when you decide how to use it.” That will be easier if the politicians approve a Forest Code that looks to the future, not the past—and then provide the means to enforce it.